modify 1:1 比对方式
This commit is contained in:
@ -106,7 +106,9 @@ def test_compare():
|
||||
|
||||
def one2one_pr(paths):
|
||||
paths = Path(paths)
|
||||
evtpaths = [p for p in paths.iterdir() if p.is_dir() and len(p.name.split('_'))>=2]
|
||||
|
||||
# evtpaths = [p for p in paths.iterdir() if p.is_dir() and len(p.name.split('_'))>=2]
|
||||
evtpaths = [p for p in paths.iterdir() if p.is_dir()]
|
||||
|
||||
events, similars = [], []
|
||||
|
||||
@ -120,14 +122,19 @@ def one2one_pr(paths):
|
||||
##===================================== 应用于1:n
|
||||
tpevents, fnevents, fpevents, tnevents = [], [], [], []
|
||||
tpsimi, fnsimi, tnsimi, fpsimi = [], [], [], []
|
||||
|
||||
other_event, other_simi = [], []
|
||||
|
||||
##===================================== barcodes总数、比对错误事件
|
||||
bcdList, one2onePath = [], []
|
||||
for path in evtpaths:
|
||||
barcode = path.stem.split('_')[-1]
|
||||
datapath = path.joinpath('process.data')
|
||||
|
||||
if not barcode.isdigit() or len(barcode)<10: continue
|
||||
if not datapath.is_file(): continue
|
||||
|
||||
|
||||
bcdList.append(barcode)
|
||||
|
||||
try:
|
||||
SimiDict = read_similar(datapath)
|
||||
except Exception as e:
|
||||
@ -150,13 +157,17 @@ def one2one_pr(paths):
|
||||
|
||||
one2oneAA.extend(simAA)
|
||||
one2oneAB.extend(simAB)
|
||||
|
||||
one2onePath.append(path.stem)
|
||||
|
||||
##===================================== 以下应用适用于展厅 1:N
|
||||
max_idx = similars.index(max(similars))
|
||||
max_sim = similars[max_idx]
|
||||
# max_bcd = barcodes[max_idx]
|
||||
|
||||
if path.stem.find('100321')>0:
|
||||
print("hhh")
|
||||
|
||||
|
||||
for i in range(len(one2one)):
|
||||
bcd, simi = barcodes[i], similars[i]
|
||||
if bcd==barcode and simi==max_sim:
|
||||
@ -172,7 +183,7 @@ def one2one_pr(paths):
|
||||
fp_simi.append(simi)
|
||||
fp_events.append(path.stem)
|
||||
|
||||
|
||||
|
||||
##===================================== 以下应用适用1:n
|
||||
events, evt_barcodes, evt_similars, evt_types = [], [], [], []
|
||||
for dt in one2n:
|
||||
@ -197,9 +208,13 @@ def one2one_pr(paths):
|
||||
elif bcd!=barcode and simi!=maxsim:
|
||||
tnsimi.append(simi)
|
||||
tnevents.append(path.stem)
|
||||
else:
|
||||
elif bcd!=barcode and simi==maxsim:
|
||||
fpsimi.append(simi)
|
||||
fpevents.append(path.stem)
|
||||
else:
|
||||
other_simi.append(simi)
|
||||
other_event.append(path.stem)
|
||||
|
||||
|
||||
'''命名规则:
|
||||
1:1 1:n 1:N
|
||||
@ -228,9 +243,12 @@ def one2one_pr(paths):
|
||||
FN_ = sum(np.array(one2oneAA) < th)
|
||||
TN_ = sum(np.array(one2oneAB) < th)
|
||||
PPrecise_.append(TP_/(TP_+FP_+1e-6))
|
||||
PRecall_.append(TP_/(TP_+FN_+1e-6))
|
||||
# PRecall_.append(TP_/(TP_+FN_+1e-6))
|
||||
PRecall_.append(TP_/(len(one2oneAA)+1e-6))
|
||||
|
||||
NPrecise_.append(TN_/(TN_+FN_+1e-6))
|
||||
NRecall_.append(TN_/(TN_+FP_+1e-6))
|
||||
# NRecall_.append(TN_/(TN_+FP_+1e-6))
|
||||
NRecall_.append(TN_/(len(one2oneAB)+1e-6))
|
||||
|
||||
'''============================= 1:n'''
|
||||
TP = sum(np.array(tpsimi) >= th)
|
||||
@ -238,9 +256,12 @@ def one2one_pr(paths):
|
||||
FN = sum(np.array(fnsimi) < th)
|
||||
TN = sum(np.array(tnsimi) < th)
|
||||
PPrecise.append(TP/(TP+FP+1e-6))
|
||||
PRecall.append(TP/(TP+FN+1e-6))
|
||||
# PRecall.append(TP/(TP+FN+1e-6))
|
||||
PRecall.append(TP/(len(tpsimi)+len(fnsimi)+1e-6))
|
||||
|
||||
NPrecise.append(TN/(TN+FN+1e-6))
|
||||
NRecall.append(TN/(TN+FP+1e-6))
|
||||
# NRecall.append(TN/(TN+FP+1e-6))
|
||||
NRecall.append(TN/(len(tnsimi)+len(fpsimi)+1e-6))
|
||||
|
||||
|
||||
'''============================= 1:N 展厅'''
|
||||
@ -249,9 +270,12 @@ def one2one_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/(TPX+FNX+1e-6))
|
||||
# PRecallX.append(TPX/(TPX+FNX+1e-6))
|
||||
PRecallX.append(TPX/(len(tp_simi)+len(fn_simi)+1e-6))
|
||||
|
||||
NPreciseX.append(TNX/(TNX+FNX+1e-6))
|
||||
NRecallX.append(TNX/(TNX+FPX+1e-6))
|
||||
# NRecallX.append(TNX/(TNX+FPX+1e-6))
|
||||
NRecallX.append(TNX/(len(tn_simi)+len(fp_simi)+1e-6))
|
||||
|
||||
'''============================= 1:1 曲线'''
|
||||
fig, ax = plt.subplots()
|
||||
@ -262,8 +286,8 @@ def one2one_pr(paths):
|
||||
ax.set_xlim([0, 1])
|
||||
ax.set_ylim([0, 1])
|
||||
ax.grid(True)
|
||||
ax.set_title('Precise & Recall')
|
||||
ax.set_xlabel(f"Num: {len(evtpaths)}")
|
||||
ax.set_title('1:1 Precise & Recall')
|
||||
ax.set_xlabel(f"Event Num: {len(one2oneAA)}")
|
||||
ax.legend()
|
||||
plt.show()
|
||||
|
||||
@ -286,8 +310,8 @@ def one2one_pr(paths):
|
||||
ax.set_xlim([0, 1])
|
||||
ax.set_ylim([0, 1])
|
||||
ax.grid(True)
|
||||
ax.set_title('Precise & Recall')
|
||||
ax.set_xlabel(f"Num: {len(evtpaths)}")
|
||||
ax.set_title('1:n Precise & Recall')
|
||||
ax.set_xlabel(f"Event Num: {len(one2oneAA)}")
|
||||
ax.legend()
|
||||
plt.show()
|
||||
|
||||
@ -317,8 +341,8 @@ def one2one_pr(paths):
|
||||
ax.set_xlim([0, 1])
|
||||
ax.set_ylim([0, 1])
|
||||
ax.grid(True)
|
||||
ax.set_title('Precise & Recall')
|
||||
ax.set_xlabel(f"Num: {len(evtpaths)}")
|
||||
ax.set_title('1:N Precise & Recall')
|
||||
ax.set_xlabel(f"Event Num: {len(one2oneAA)}")
|
||||
ax.legend()
|
||||
plt.show()
|
||||
|
||||
@ -338,16 +362,23 @@ def one2one_pr(paths):
|
||||
axes[1, 1].set_title('FN')
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
# 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 = str(paths.joinpath("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\测试视频数据以及日志\各模块测试记录\展厅测试\1120_展厅模型v801测试\扫A放A"
|
||||
evtpaths = r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\展厅测试\1129_展厅模型v801测试组测试"
|
||||
one2one_pr(evtpaths)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user