modify pipeline.py
This commit is contained in:
@ -24,10 +24,15 @@ def init_eventdict(sourcePath, stype="data"):
|
||||
# bname = r"20241126-135911-bdf91cf9-3e9a-426d-94e8-ddf92238e175_6923555210479"
|
||||
|
||||
source_path = os.path.join(sourcePath, bname)
|
||||
if not os.path.isdir(source_path): continue
|
||||
|
||||
pickpath = os.path.join(eventDataPath, f"{bname}.pickle")
|
||||
if os.path.isfile(pickpath): continue
|
||||
if stype=="data":
|
||||
pickpath = os.path.join(eventDataPath, f"{bname}.pickle")
|
||||
if not os.path.isdir(source_path) or os.path.isfile(pickpath):
|
||||
continue
|
||||
if stype=="source":
|
||||
pickpath = os.path.join(eventDataPath, bname)
|
||||
if not os.path.isfile(source_path) or os.path.isfile(pickpath):
|
||||
continue
|
||||
|
||||
try:
|
||||
event = ShoppingEvent(source_path, stype)
|
||||
|
||||
@ -86,20 +91,28 @@ def simi_calc(event, o2nevt, typee=None):
|
||||
feat1 = event.back_feats
|
||||
feat2 = o2nevt.front_feats
|
||||
|
||||
'''自定义事件特征选择'''
|
||||
if typee==3:
|
||||
feat1 = event.feats_compose
|
||||
feat2 = o2nevt.feats_compose
|
||||
|
||||
|
||||
if len(feat1) and len(feat2):
|
||||
matrix = 1 - cdist(feat1[0], feat2[0], 'cosine')
|
||||
simi = np.mean(matrix)
|
||||
else:
|
||||
simi = None
|
||||
|
||||
|
||||
|
||||
return simi
|
||||
|
||||
|
||||
|
||||
|
||||
def one2n_pr(evtDicts):
|
||||
def one2n_pr(evtDicts, pattern=1):
|
||||
'''
|
||||
pattern:
|
||||
1: process.data 中记录的相似度
|
||||
2: 根据 process.data 中标记的 type 选择特征计算
|
||||
3: 以其它方式选择特征计算
|
||||
'''
|
||||
|
||||
tpevents, fnevents, fpevents, tnevents = [], [], [], []
|
||||
tpsimi, fnsimi, tnsimi, fpsimi = [], [], [], []
|
||||
errorFile_one2n = []
|
||||
@ -111,22 +124,30 @@ def one2n_pr(evtDicts):
|
||||
barcode = ndict["barcode"]
|
||||
similar = ndict["similar"]
|
||||
typee = ndict["type"].strip()
|
||||
|
||||
o2n_evt = [evt for name, evt in evtDicts.items() if name.find(nname[:15])==0]
|
||||
if len(o2n_evt)==1:
|
||||
o2nevt = o2n_evt[0]
|
||||
else:
|
||||
continue
|
||||
|
||||
simival = simi_calc(event, o2nevt, typee)
|
||||
if simival==None:
|
||||
continue
|
||||
|
||||
|
||||
evt_names.append(nname)
|
||||
evt_barcodes.append(barcode)
|
||||
evt_similars.append(simival)
|
||||
evt_types.append(typee)
|
||||
|
||||
|
||||
if pattern==1:
|
||||
evt_similars.append(similar)
|
||||
|
||||
if pattern==2 or pattern==3:
|
||||
o2n_evt = [evt for name, evt in evtDicts.items() if name.find(nname[:15])==0]
|
||||
if len(o2n_evt)==1:
|
||||
o2nevt = o2n_evt[0]
|
||||
else:
|
||||
continue
|
||||
|
||||
if pattern==2:
|
||||
simival = simi_calc(event, o2nevt, typee)
|
||||
|
||||
if pattern==3:
|
||||
simival = simi_calc(event, o2nevt, typee=pattern)
|
||||
|
||||
if simival==None:
|
||||
continue
|
||||
evt_similars.append(simival)
|
||||
|
||||
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:
|
||||
@ -205,30 +226,25 @@ def one2n_pr(evtDicts):
|
||||
def main():
|
||||
|
||||
'''1. 生成事件字典并保存至 eventDataPath, 只需运行一次 '''
|
||||
# init_eventdict(eventSourcePath)
|
||||
init_eventdict(eventSourcePath, stype="source")
|
||||
|
||||
'''2. 读取事件字典 '''
|
||||
evtDicts = read_eventdict(eventDataPath)
|
||||
|
||||
|
||||
'''3. 1:n 比对事件评估 '''
|
||||
fpevents = one2n_pr(evtDicts)
|
||||
fpevents = one2n_pr(evtDicts, pattern=3)
|
||||
|
||||
fpErrFile = str(Path(resultPath).joinpath("one2n_fp_Error.txt"))
|
||||
with open(fpErrFile, "w") as file:
|
||||
for item in fpevents:
|
||||
file.write(item + "\n")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\images"
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result"
|
||||
eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result\ShoppingDict_pkfile"
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result\contrast"
|
||||
|
||||
eventDataPath = os.path.join(resultPath, "evtobjs")
|
||||
similPath = os.path.join(resultPath, "simidata")
|
||||
|
Reference in New Issue
Block a user