20250313
This commit is contained in:
@ -109,24 +109,31 @@ def test_compare():
|
||||
|
||||
plot_pr_curve(simiList)
|
||||
|
||||
def contrast_pr(paths):
|
||||
def contrast_pr(evtPaths):
|
||||
'''
|
||||
1:1
|
||||
'''
|
||||
paths = Path(paths)
|
||||
|
||||
'''
|
||||
evtpaths = []
|
||||
for p in paths.iterdir():
|
||||
# date_ = ['2025-3-4_1', '2025-3-5_1', '2025-3-5_2']
|
||||
# for dt in date_:
|
||||
# paths = Path(evtPaths) / dt
|
||||
abc = []
|
||||
for p in Path(evtPaths).iterdir():
|
||||
condt1 = p.is_dir()
|
||||
condt2 = len(p.name.split('_'))>=2
|
||||
condt3 = len(p.name.split('_')[-1])>8
|
||||
condt3 = len(p.name.split('_')[-1])>=8
|
||||
condt4 = p.name.split('_')[-1].isdigit()
|
||||
if condt1 and condt2 and condt3 and condt4:
|
||||
evtpaths.append(p)
|
||||
elif p.is_dir():
|
||||
abc.append(p.stem)
|
||||
|
||||
|
||||
# evtpaths = [p for p in paths.iterdir() if p.is_dir() and len(p.name.split('_'))>=2 and len(p.name.split('_')[-1])>8]
|
||||
# evtpaths = [p for p in paths.iterdir() if p.is_dir()]
|
||||
|
||||
alg_times = []
|
||||
|
||||
events, similars = [], []
|
||||
##===================================== 扫A放A, 扫A放B场景()
|
||||
one2oneAA, one2oneAB = [], []
|
||||
@ -157,7 +164,7 @@ def contrast_pr(paths):
|
||||
barcode = path.stem.split('_')[-1]
|
||||
datapath = path.joinpath('process.data')
|
||||
|
||||
if not barcode.isdigit() or len(barcode)<10: continue
|
||||
if not barcode.isdigit() or len(barcode)<8: continue
|
||||
if not datapath.is_file(): continue
|
||||
|
||||
bcdList.append(barcode)
|
||||
@ -175,10 +182,15 @@ def contrast_pr(paths):
|
||||
|
||||
if len(one2one)+len(one2SN)+len(one2n) == 0:
|
||||
errorFile.append(path.stem)
|
||||
|
||||
dtime = SimiDict["algroStartToEnd"]
|
||||
if dtime >= 0:
|
||||
alg_times.append((dtime, path.stem))
|
||||
|
||||
|
||||
'''================== 0. 1:1 ==================='''
|
||||
barcodes, similars = [], []
|
||||
barcodes_ = []
|
||||
for dt in one2one:
|
||||
one2onePath.append((path.stem))
|
||||
if dt['similar']==0:
|
||||
@ -186,6 +198,12 @@ def contrast_pr(paths):
|
||||
continue
|
||||
barcodes.append(dt['barcode'])
|
||||
similars.append(dt['similar'])
|
||||
|
||||
|
||||
barcodes_.append(path.stem)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if len(barcodes)==len(similars) and len(barcodes)!=0:
|
||||
@ -216,6 +234,8 @@ def contrast_pr(paths):
|
||||
_fp_events.append(path.stem)
|
||||
else:
|
||||
errorFile_one2one.append(path.stem)
|
||||
elif len(one2SN)+len(one2n) == 0:
|
||||
errorFile_one2one.append(path.stem)
|
||||
|
||||
|
||||
'''================== 2. 取出场景下的 1 : Small N ==================='''
|
||||
@ -223,6 +243,7 @@ def contrast_pr(paths):
|
||||
for dt in one2SN:
|
||||
barcodes.append(dt['barcode'])
|
||||
similars.append(dt['similar'])
|
||||
|
||||
|
||||
if len(barcodes)==len(similars) and len(barcodes)!=0:
|
||||
## 扫A放A, 扫A放B场景
|
||||
@ -231,11 +252,11 @@ def contrast_pr(paths):
|
||||
|
||||
one2SNAA.extend(simAA)
|
||||
one2SNAB.extend(simAB)
|
||||
|
||||
one2SNPath.append(path.stem)
|
||||
if len(simAA)==0:
|
||||
one2SNPath1.append(path.stem)
|
||||
|
||||
|
||||
errorFile_one2SN.append(path.stem)
|
||||
|
||||
## 相似度排序,barcode相等且排名第一为TP,适用于多的barcode相似度比较
|
||||
max_idx = similars.index(max(similars))
|
||||
max_sim = similars[max_idx]
|
||||
@ -256,6 +277,7 @@ def contrast_pr(paths):
|
||||
fp_events.append(path.stem)
|
||||
else:
|
||||
errorFile_one2SN.append(path.stem)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -266,10 +288,17 @@ def contrast_pr(paths):
|
||||
evt_barcodes.append(dt["barcode"])
|
||||
evt_similars.append(dt["similar"])
|
||||
evt_types.append(dt["type"])
|
||||
|
||||
if len(events)==len(evt_barcodes) and len(evt_barcodes)==len(evt_similars) \
|
||||
and len(evt_similars)==len(evt_types) and len(events)>0:
|
||||
|
||||
|
||||
|
||||
if len(events)==len(evt_barcodes)==len(evt_similars)==len(evt_types) and len(events)>0:
|
||||
if not barcode in evt_barcodes:
|
||||
errorFile_one2n.append(path.stem)
|
||||
continue
|
||||
|
||||
if len(barcodes_):
|
||||
print("do")
|
||||
|
||||
one2nPath.append(path.stem)
|
||||
maxsim = evt_similars[evt_similars.index(max(evt_similars))]
|
||||
for i in range(len(one2n)):
|
||||
@ -324,9 +353,9 @@ def contrast_pr(paths):
|
||||
_TN = sum(np.array(one2oneAB) < th)
|
||||
|
||||
_PPrecise.append(_TP/(_TP+_FP+1e-6))
|
||||
_PRecall.append(_TP/(len(one2oneAA)+1e-6))
|
||||
_PRecall.append(_TP/(_TP+_FN+1e-6))
|
||||
_NPrecise.append(_TN/(_TN+_FN+1e-6))
|
||||
_NRecall.append(_TN/(len(one2oneAB)+1e-6))
|
||||
_NRecall.append(_TN/(_TN+_FP+1e-6))
|
||||
|
||||
'''===================================== 1:SN 均值'''
|
||||
TP_ = sum(np.array(one2SNAA) >= th)
|
||||
@ -346,10 +375,10 @@ def contrast_pr(paths):
|
||||
FNX = sum(np.array(fn_simi) < th)
|
||||
TNX = sum(np.array(tn_simi) < th)
|
||||
PPreciseX.append(TPX/(TPX+FPX+1e-6))
|
||||
PRecallX.append(TPX/(len(tp_simi)+len(fn_simi)+1e-6))
|
||||
PRecallX.append(TPX/(TPX+FNX+1e-6))
|
||||
|
||||
NPreciseX.append(TNX/(TNX+FNX+1e-6))
|
||||
NRecallX.append(TNX/(len(tn_simi)+len(fp_simi)+1e-6))
|
||||
NRecallX.append(TNX/(TNX+FPX+1e-6))
|
||||
|
||||
|
||||
'''===================================== 1:n'''
|
||||
@ -359,13 +388,19 @@ def contrast_pr(paths):
|
||||
TN = sum(np.array(tnsimi) < th)
|
||||
|
||||
PPrecise.append(TP/(TP+FP+1e-6))
|
||||
PRecall.append(TP/(len(tpsimi)+len(fnsimi)+1e-6))
|
||||
PRecall.append(TP/(TP+FN+1e-6))
|
||||
NPrecise.append(TN/(TN+FN+1e-6))
|
||||
NRecall.append(TN/(len(tnsimi)+len(fpsimi)+1e-6))
|
||||
NRecall.append(TN/(TN+FP+1e-6))
|
||||
|
||||
algtime = []
|
||||
for tm, _ in alg_times:
|
||||
algtime.append(tm)
|
||||
fig, ax = plt.subplots()
|
||||
ax.hist(np.array(algtime), bins=100, edgecolor='black')
|
||||
ax.set_title('Algorthm Spend Time')
|
||||
ax.set_xlabel(f"Event Num: {len(alg_times)}")
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
'''1. ============================= 1:1 最大值方案 曲线'''
|
||||
fig, ax = plt.subplots()
|
||||
ax.plot(Thresh, _PPrecise, 'r', label='Precise_Pos: TP/TPFP')
|
||||
@ -374,7 +409,9 @@ def contrast_pr(paths):
|
||||
ax.plot(Thresh, _NRecall, 'c', label='Recall_Neg: TN/TNFN')
|
||||
ax.set_xlim([0, 1])
|
||||
ax.set_ylim([0, 1])
|
||||
ax.grid(True)
|
||||
ax.set_xticks(np.arange(0, 1, 0.1))
|
||||
ax.set_yticks(np.arange(0, 1, 0.1))
|
||||
ax.grid(True, linestyle='--')
|
||||
ax.set_title('1:1 Precise & Recall')
|
||||
ax.set_xlabel(f"Event Num: {len(one2oneAA)+len(one2oneAB)}")
|
||||
ax.legend()
|
||||
@ -393,30 +430,30 @@ def contrast_pr(paths):
|
||||
|
||||
|
||||
'''2. ============================= 1:1 均值方案 曲线'''
|
||||
fig, ax = plt.subplots()
|
||||
ax.plot(Thresh, PPrecise_, 'r', label='Precise_Pos: TP/TPFP')
|
||||
ax.plot(Thresh, PRecall_, 'b', label='Recall_Pos: TP/TPFN')
|
||||
ax.plot(Thresh, NPrecise_, 'g', label='Precise_Neg: TN/TNFP')
|
||||
ax.plot(Thresh, NRecall_, 'c', label='Recall_Neg: TN/TNFN')
|
||||
ax.set_xlim([0, 1])
|
||||
ax.set_ylim([0, 1])
|
||||
ax.grid(True)
|
||||
ax.set_title('1:1 Precise & Recall')
|
||||
ax.set_xlabel(f"Event Num: {len(one2SNAA)}")
|
||||
ax.legend()
|
||||
plt.show()
|
||||
## ============================= 1:1 均值方案 直方图'''
|
||||
fig, axes = plt.subplots(2, 1)
|
||||
axes[0].hist(np.array(one2SNAA), bins=60, edgecolor='black')
|
||||
axes[0].set_xlim([-0.2, 1])
|
||||
axes[0].set_title('AA')
|
||||
axes[0].set_xlabel(f"Event Num: {len(one2SNAA)}")
|
||||
# fig, ax = plt.subplots()
|
||||
# ax.plot(Thresh, PPrecise_, 'r', label='Precise_Pos: TP/TPFP')
|
||||
# ax.plot(Thresh, PRecall_, 'b', label='Recall_Pos: TP/TPFN')
|
||||
# ax.plot(Thresh, NPrecise_, 'g', label='Precise_Neg: TN/TNFP')
|
||||
# ax.plot(Thresh, NRecall_, 'c', label='Recall_Neg: TN/TNFN')
|
||||
# ax.set_xlim([0, 1])
|
||||
# ax.set_ylim([0, 1])
|
||||
# ax.grid(True)
|
||||
# ax.set_title('1:1 Precise & Recall')
|
||||
# ax.set_xlabel(f"Event Num: {len(one2SNAA)}")
|
||||
# ax.legend()
|
||||
# plt.show()
|
||||
# ## ============================= 1:1 均值方案 直方图'''
|
||||
# fig, axes = plt.subplots(2, 1)
|
||||
# axes[0].hist(np.array(one2SNAA), bins=60, edgecolor='black')
|
||||
# axes[0].set_xlim([-0.2, 1])
|
||||
# axes[0].set_title('AA')
|
||||
# axes[0].set_xlabel(f"Event Num: {len(one2SNAA)}")
|
||||
|
||||
axes[1].hist(np.array(one2SNAB), bins=60, edgecolor='black')
|
||||
axes[1].set_xlim([-0.2, 1])
|
||||
axes[1].set_title('BB')
|
||||
axes[1].set_xlabel(f"Event Num: {len(one2SNAB)}")
|
||||
plt.show()
|
||||
# axes[1].hist(np.array(one2SNAB), bins=60, edgecolor='black')
|
||||
# axes[1].set_xlim([-0.2, 1])
|
||||
# axes[1].set_title('BB')
|
||||
# axes[1].set_xlabel(f"Event Num: {len(one2SNAB)}")
|
||||
# plt.show()
|
||||
|
||||
''''3. ============================= 1:SN 曲线'''
|
||||
fig, ax = plt.subplots()
|
||||
@ -426,7 +463,9 @@ def contrast_pr(paths):
|
||||
ax.plot(Thresh, NRecallX, 'c', label='Recall_Neg: TN/TNFN')
|
||||
ax.set_xlim([0, 1])
|
||||
ax.set_ylim([0, 1])
|
||||
ax.grid(True)
|
||||
ax.set_xticks(np.arange(0, 1, 0.1))
|
||||
ax.set_yticks(np.arange(0, 1, 0.1))
|
||||
ax.grid(True, linestyle='--')
|
||||
ax.set_title('1:SN Precise & Recall')
|
||||
ax.set_xlabel(f"Event Num: {len(one2SNAA)}")
|
||||
ax.legend()
|
||||
@ -456,7 +495,9 @@ def contrast_pr(paths):
|
||||
ax.plot(Thresh, NRecall, 'c', label='Recall_Neg: TN/TNFN')
|
||||
ax.set_xlim([0, 1])
|
||||
ax.set_ylim([0, 1])
|
||||
ax.grid(True)
|
||||
ax.set_xticks(np.arange(0, 1, 0.1))
|
||||
ax.set_yticks(np.arange(0, 1, 0.1))
|
||||
ax.grid(True, linestyle='--')
|
||||
ax.set_title('1:n Precise & Recall')
|
||||
ax.set_xlabel(f"Event Num: {len(tpsimi)+len(fnsimi)}")
|
||||
ax.legend()
|
||||
@ -473,11 +514,11 @@ def contrast_pr(paths):
|
||||
axes[1, 0].set_xlim([-0.2, 1])
|
||||
axes[1, 0].set_title(f'TN({len(tnsimi)})')
|
||||
axes[1, 1].hist(fnsimi, bins=60, edgecolor='black')
|
||||
|
||||
axes[1, 1].set_xlim([-0.2, 1])
|
||||
axes[1, 1].set_title(f'FN({len(fnsimi)})')
|
||||
plt.show()
|
||||
|
||||
|
||||
# fpsnErrFile = str(paths.joinpath("one2SN_Error.txt"))
|
||||
# with open(fpsnErrFile, "w") as file:
|
||||
# for item in fp_events:
|
||||
@ -487,27 +528,24 @@ def contrast_pr(paths):
|
||||
# with open(fpErrFile, "w") as file:
|
||||
# for item in fpevents:
|
||||
# file.write(item + "\n")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# bcdSet = set(bcdList)
|
||||
# one2nErrFile = str(paths.joinpath("one_2_Small_n_Error.txt"))
|
||||
# with open(one2nErrFile, "w") as file:
|
||||
# for item in fnevents:
|
||||
# file.write(item + "\n")
|
||||
one2nErrFile = os.path.join(evtPaths, "one_2_Small_n_Error.txt")
|
||||
with open(one2nErrFile, "w") as file:
|
||||
for item in fnevents:
|
||||
file.write(item + "\n")
|
||||
|
||||
# one2NErrFile = str(paths.joinpath("one_2_Big_N_Error.txt"))
|
||||
# with open(one2NErrFile, "w") as file:
|
||||
# for item in fn_events:
|
||||
# file.write(item + "\n")
|
||||
one2NErrFile = os.path.join(evtPaths, "one_2_Big_N_Error.txt")
|
||||
with open(one2NErrFile, "w") as file:
|
||||
for item in fn_events:
|
||||
file.write(item + "\n")
|
||||
|
||||
print('Done!')
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
evtpaths = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\V12\2025-2-26_2"
|
||||
evtpaths = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\V12\2025-3-3"
|
||||
contrast_pr(evtpaths)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user