pipeline.py 等更新
This commit is contained in:
Binary file not shown.
@ -169,9 +169,6 @@ def calc_simil(event, stdfeat):
|
||||
Similar = None # 在event.front_feats和event.back_feats同时为空时
|
||||
|
||||
return Similar
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def simi_matrix():
|
||||
|
Binary file not shown.
Binary file not shown.
@ -61,8 +61,9 @@ class Config:
|
||||
test_val = "D:/比对/cl"
|
||||
# test_val = "./data/test_data_100"
|
||||
|
||||
test_model = "checkpoints/best_resnet18_v12.pth"
|
||||
# test_model = "checkpoints/best_resnet18_v12.pth"
|
||||
# test_model = "checkpoints/zhanting_res_801.pth"
|
||||
test_model = "checkpoints/zhanting_res_abroad_8021.pth"
|
||||
|
||||
|
||||
|
||||
|
@ -61,8 +61,17 @@ class FeatsInterface:
|
||||
batch_patches = []
|
||||
patches = []
|
||||
for i, img in enumerate(images):
|
||||
img = img.copy()
|
||||
patch = self.transform(img)
|
||||
img = img.copy()
|
||||
|
||||
## 对 img 进行补黑边,生成新的图像new_img
|
||||
width, height = img.size
|
||||
new_size = max(width, height)
|
||||
new_img = Image.new("RGB", (new_size, new_size), (0, 0, 0))
|
||||
paste_x = (new_size - width) // 2
|
||||
paste_y = (new_size - height) // 2
|
||||
new_img.paste(img, (paste_x, paste_y))
|
||||
|
||||
patch = self.transform(new_img)
|
||||
if str(self.device) != "cpu":
|
||||
patch = patch.to(device=self.device).half()
|
||||
else:
|
||||
@ -107,10 +116,12 @@ class FeatsInterface:
|
||||
patch = self.transform(img1)
|
||||
|
||||
# patch = patch.to(device=self.device).half()
|
||||
if str(self.device) != "cpu":
|
||||
patch = patch.to(device=self.device).half()
|
||||
else:
|
||||
patch = patch.to(device=self.device)
|
||||
# if str(self.device) != "cpu":
|
||||
# patch = patch.to(device=self.device).half()
|
||||
# patch = patch.to(device=self.device)
|
||||
# else:
|
||||
# patch = patch.to(device=self.device)
|
||||
patch = patch.to(device=self.device)
|
||||
|
||||
patches.append(patch)
|
||||
if (d + 1) % self.batch_size == 0:
|
||||
|
@ -158,6 +158,8 @@ def stdfeat_infer(imgPath, featPath, bcdSet=None):
|
||||
|
||||
feature /= np.linalg.norm(feature, axis=1)[:, None]
|
||||
|
||||
feature_ft32 = feature.astype(np.float32)
|
||||
|
||||
# float16
|
||||
feature_ft16 = feature.astype(np.float16)
|
||||
feature_ft16 /= np.linalg.norm(feature_ft16, axis=1)[:, None]
|
||||
@ -173,7 +175,7 @@ def stdfeat_infer(imgPath, featPath, bcdSet=None):
|
||||
##================== float32
|
||||
stdbDict["barcode"] = barcode
|
||||
stdbDict["imgpaths"] = imgpaths
|
||||
stdbDict["feats_ft32"] = feature
|
||||
stdbDict["feats_ft32"] = feature_ft32
|
||||
stdbDict["feats_ft16"] = feature_ft16
|
||||
stdbDict["feats_uint8"] = feature_uint8
|
||||
|
||||
@ -202,9 +204,13 @@ def gen_bcd_features(imgpath, bcdpath, featpath, bcdSet=None):
|
||||
stdfeat_infer(bcdpath, featpath, bcdSet)
|
||||
|
||||
def main():
|
||||
imgpath = r"\\192.168.1.28\share\数据\已完成数据\展厅数据\v1.0\比对数据\整理\zhantingBase"
|
||||
bcdpath = r"D:\exhibition\dataset\bcdpath"
|
||||
featpath = r"D:\exhibition\dataset\feats"
|
||||
imgpath = r"\\192.168.1.28\share\数据\已完成数据\展厅数据\v2.0_abroad\比对数据\all_base_二筛"
|
||||
bcdpath = r"D:\exhibition\dataset\bcdpath_abroad"
|
||||
featpath = r"D:\exhibition\dataset\feats_abroad"
|
||||
if not os.path.exists(bcdpath):
|
||||
os.makedirs(bcdpath)
|
||||
if not os.path.exists(featpath):
|
||||
os.makedirs(featpath)
|
||||
|
||||
|
||||
gen_bcd_features(imgpath, bcdpath, featpath)
|
||||
|
@ -92,9 +92,9 @@ def simi_calc(event, o2nevt, typee=None):
|
||||
feat2 = o2nevt.front_feats
|
||||
|
||||
'''自定义事件特征选择'''
|
||||
if typee==3:
|
||||
feat1 = event.feats_compose
|
||||
feat2 = o2nevt.feats_compose
|
||||
if typee==3 and len(event.feats_compose) and len(o2nevt.feats_compose):
|
||||
feat1 = [event.feats_compose]
|
||||
feat2 = [o2nevt.feats_compose]
|
||||
|
||||
|
||||
if len(feat1) and len(feat2):
|
||||
@ -109,15 +109,18 @@ def one2n_pr(evtDicts, pattern=1):
|
||||
'''
|
||||
pattern:
|
||||
1: process.data 中记录的相似度
|
||||
2: 根据 process.data 中标记的 type 选择特征计算
|
||||
3: 以其它方式选择特征计算
|
||||
2: 根据 process.data 中标记的 type 选择特征计算相似度
|
||||
3: 以其它方式选择特征计算相似度
|
||||
'''
|
||||
|
||||
tpevents, fnevents, fpevents, tnevents = [], [], [], []
|
||||
tpsimi, fnsimi, tnsimi, fpsimi = [], [], [], []
|
||||
errorFile_one2n = []
|
||||
one2nFile, errorFile_one2n = [], []
|
||||
for evtname, event in evtDicts.items():
|
||||
evt_names, evt_barcodes, evt_similars, evt_types = [], [], [], []
|
||||
|
||||
if len(event.barcode)==0:
|
||||
continue
|
||||
|
||||
for ndict in event.one2n:
|
||||
nname = ndict["event"]
|
||||
@ -149,6 +152,13 @@ def one2n_pr(evtDicts, pattern=1):
|
||||
continue
|
||||
evt_similars.append(simival)
|
||||
|
||||
## process.data的oneTon的各项中,均不包括当前事件的barcode
|
||||
if event.barcode not in evt_barcodes:
|
||||
errorFile_one2n.append(evtname)
|
||||
continue
|
||||
else:
|
||||
one2nFile.append(evtname)
|
||||
|
||||
if len(evt_names)==len(evt_barcodes) and len(evt_barcodes)==len(evt_similars) \
|
||||
and len(evt_similars)==len(evt_types) and len(evt_names)>0:
|
||||
|
||||
@ -166,7 +176,7 @@ def one2n_pr(evtDicts, pattern=1):
|
||||
elif bcd!=event.barcode and simi!=maxsim:
|
||||
tnsimi.append(simi)
|
||||
tnevents.append(evtname)
|
||||
elif bcd!=event.barcode and simi==maxsim and event.barcode in evt_barcodes:
|
||||
elif bcd!=event.barcode and simi==maxsim:
|
||||
fpsimi.append(simi)
|
||||
fpevents.append(evtname)
|
||||
else:
|
||||
@ -187,7 +197,7 @@ def one2n_pr(evtDicts, pattern=1):
|
||||
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/(len(one2nFile)+1e-6))
|
||||
NPrecise.append(TN/(TN+FN+1e-6))
|
||||
NRecall.append(TN/(len(tnsimi)+len(fpsimi)+1e-6))
|
||||
|
||||
@ -202,23 +212,23 @@ def one2n_pr(evtDicts, pattern=1):
|
||||
ax.set_ylim([0, 1])
|
||||
ax.grid(True)
|
||||
ax.set_title('1:n Precise & Recall')
|
||||
ax.set_xlabel(f"Event Num: {len(tpsimi)+len(fnsimi)}")
|
||||
ax.set_xlabel(f"Event Num: {len(one2nFile)}")
|
||||
ax.legend()
|
||||
plt.show()
|
||||
## ============================= 1:n 直方图'''
|
||||
fig, axes = plt.subplots(2, 2)
|
||||
axes[0, 0].hist(tpsimi, bins=60, range=(-0.2, 1), edgecolor='black')
|
||||
axes[0, 0].set_xlim([-0.2, 1])
|
||||
axes[0, 0].set_title('TP')
|
||||
axes[0, 0].set_title(f'TP: {len(tpsimi)}')
|
||||
axes[0, 1].hist(fpsimi, bins=60, range=(-0.2, 1), edgecolor='black')
|
||||
axes[0, 1].set_xlim([-0.2, 1])
|
||||
axes[0, 1].set_title('FP')
|
||||
axes[0, 1].set_title(f'FP: {len(fpsimi)}')
|
||||
axes[1, 0].hist(tnsimi, bins=60, range=(-0.2, 1), edgecolor='black')
|
||||
axes[1, 0].set_xlim([-0.2, 1])
|
||||
axes[1, 0].set_title('TN')
|
||||
axes[1, 0].set_title(f'TN: {len(tnsimi)}')
|
||||
axes[1, 1].hist(fnsimi, bins=60, range=(-0.2, 1), edgecolor='black')
|
||||
axes[1, 1].set_xlim([-0.2, 1])
|
||||
axes[1, 1].set_title('FN')
|
||||
axes[1, 1].set_title(f'FN: {len(fnsimi)}')
|
||||
plt.show()
|
||||
|
||||
return fpevents
|
||||
@ -226,14 +236,14 @@ def one2n_pr(evtDicts, pattern=1):
|
||||
def main():
|
||||
|
||||
'''1. 生成事件字典并保存至 eventDataPath, 只需运行一次 '''
|
||||
init_eventdict(eventSourcePath, stype="source")
|
||||
init_eventdict(eventSourcePath, stype="data")
|
||||
|
||||
'''2. 读取事件字典 '''
|
||||
evtDicts = read_eventdict(eventDataPath)
|
||||
|
||||
|
||||
'''3. 1:n 比对事件评估 '''
|
||||
fpevents = one2n_pr(evtDicts, pattern=3)
|
||||
fpevents = one2n_pr(evtDicts, pattern=1)
|
||||
|
||||
fpErrFile = str(Path(resultPath).joinpath("one2n_fp_Error.txt"))
|
||||
with open(fpErrFile, "w") as file:
|
||||
@ -243,15 +253,16 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result\ShoppingDict_pkfile"
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result\contrast"
|
||||
eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对数据"
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing"
|
||||
|
||||
eventDataPath = os.path.join(resultPath, "evtobjs")
|
||||
similPath = os.path.join(resultPath, "simidata")
|
||||
if not os.path.exists(eventDataPath):
|
||||
os.makedirs(eventDataPath)
|
||||
if not os.path.exists(similPath):
|
||||
os.makedirs(similPath)
|
||||
|
||||
# similPath = os.path.join(resultPath, "simidata")
|
||||
# if not os.path.exists(similPath):
|
||||
# os.makedirs(similPath)
|
||||
|
||||
main()
|
||||
|
||||
|
@ -626,12 +626,13 @@ if __name__ == '__main__':
|
||||
# eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\展厅测试\1129_展厅模型v801测试组测试"]
|
||||
|
||||
|
||||
stdSamplePath = r"\\192.168.1.28\share\数据\已完成数据\比对数据\barcode\all_totalBarocde\totalBarcode"
|
||||
stdBarcodePath = r"D:\全实时\source_data\bcdpath"
|
||||
stdFeaturePath = r"D:\全实时\source_data\stdfeats"
|
||||
stdSamplePath = r"\\192.168.1.28\share\数据\已完成数据\展厅数据\v2.0_abroad\比对数据\all_base_二筛"
|
||||
stdBarcodePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing\bcdpath"
|
||||
stdFeaturePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing\stdfeats"
|
||||
|
||||
eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result\ShoppingDict_pkfile"]
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result\contrast"
|
||||
eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对数据"]
|
||||
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing\evtobjs"
|
||||
eventDataPath = os.path.join(resultPath, "evtobjs")
|
||||
similPath = os.path.join(resultPath, "simidata")
|
||||
if not os.path.exists(eventDataPath):
|
||||
@ -639,7 +640,7 @@ if __name__ == '__main__':
|
||||
if not os.path.exists(similPath):
|
||||
os.makedirs(similPath)
|
||||
|
||||
# test_one2one()
|
||||
test_one2one()
|
||||
|
||||
test_one2SN()
|
||||
|
||||
|
@ -495,7 +495,7 @@ def contrast_pr(paths):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
evtpaths = r"D:\全实时\source_data\2024122416"
|
||||
evtpaths = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\images"
|
||||
contrast_pr(evtpaths)
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -202,10 +202,10 @@ class ShoppingEvent:
|
||||
self.front_trackingfeats = frontdata[5]
|
||||
|
||||
'''===========对应于 0/1_tracking_output.data ============================='''
|
||||
self.back_boxes = back_outdata[0]
|
||||
self.back_feats = back_outdata[1]
|
||||
self.front_boxes = front_outdata[0]
|
||||
self.front_feats = front_outdata[1]
|
||||
self.back_boxes = back_outdata
|
||||
self.back_feats = back_outdata
|
||||
self.front_boxes = front_outdata
|
||||
self.front_feats = front_outdata
|
||||
|
||||
|
||||
def from_datafile(self, eventpath):
|
||||
|
Reference in New Issue
Block a user