modify pipeline.py
This commit is contained in:
Binary file not shown.
@ -171,16 +171,6 @@ def calc_simil(event, stdfeat):
|
||||
return Similar
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -345,20 +335,6 @@ def main():
|
||||
|
||||
simi_matrix()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -136,8 +136,8 @@ def stdfeat_infer(imgPath, featPath, bcdSet=None):
|
||||
continue
|
||||
|
||||
featpath = os.path.join(featPath, f"{bcd}.pickle")
|
||||
# if os.path.isfile(featpath):
|
||||
# continue
|
||||
if os.path.isfile(featpath):
|
||||
continue
|
||||
|
||||
stdbDict = {}
|
||||
t1 = time.time()
|
||||
|
@ -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")
|
||||
|
@ -194,6 +194,7 @@ def simi_calc(event, stdfeat):
|
||||
if len(evtfeat)==0 or len(stdfeat)==0:
|
||||
return None, None, None
|
||||
|
||||
|
||||
evtfeat /= np.linalg.norm(evtfeat, axis=1)[:, None]
|
||||
stdfeat /= np.linalg.norm(stdfeat, axis=1)[:, None]
|
||||
|
||||
@ -305,8 +306,8 @@ def one2SN_pr(evtList, evtDict, stdDict):
|
||||
barcodes, similars = [], []
|
||||
for stdbcd in bcd_selected:
|
||||
stdfeat = stdDict[stdbcd]
|
||||
# simi_mean, simi_max, simi_mfeat = simi_calc(event, stdfeat)
|
||||
simi_mean = calc_simil(event, stdfeat)
|
||||
simi_mean, simi_max, simi_mfeat = simi_calc(event, stdfeat)
|
||||
# simi_mean = calc_simil(event, stdfeat)
|
||||
|
||||
## 在event.front_feats和event.back_feats同时为空时,此处不需要保护
|
||||
# if simi_mean==None:
|
||||
@ -629,10 +630,8 @@ if __name__ == '__main__':
|
||||
stdBarcodePath = r"D:\全实时\source_data\bcdpath"
|
||||
stdFeaturePath = r"D:\全实时\source_data\stdfeats"
|
||||
|
||||
eventSourcePath = [r"D:\全实时\result\pipeline\pipeline"]
|
||||
resultPath = r"D:\全实时\result\pipeline"
|
||||
|
||||
|
||||
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")
|
||||
if not os.path.exists(eventDataPath):
|
||||
@ -640,7 +639,7 @@ if __name__ == '__main__':
|
||||
if not os.path.exists(similPath):
|
||||
os.makedirs(similPath)
|
||||
|
||||
test_one2one()
|
||||
# test_one2one()
|
||||
|
||||
test_one2SN()
|
||||
|
||||
|
Binary file not shown.
@ -76,7 +76,7 @@ def array2list(bboxes):
|
||||
|
||||
class ShoppingEvent:
|
||||
def __init__(self, eventpath, stype="data"):
|
||||
'''stype: str, 'source', 'data', '''
|
||||
'''stype: str, 'source', 'data', 'realtime', 共三种 '''
|
||||
|
||||
self.eventpath = eventpath
|
||||
self.evtname = str(Path(eventpath).stem)
|
||||
@ -167,20 +167,22 @@ class ShoppingEvent:
|
||||
|
||||
|
||||
def from_source_pkl(self, eventpath):
|
||||
|
||||
with open(eventpath, 'rb') as f:
|
||||
ShoppingDict = pickle.load(f)
|
||||
|
||||
|
||||
|
||||
self.eventpath = ShoppingDict["eventPath"]
|
||||
self.evtname = ShoppingDict["eventName"]
|
||||
self.barcode = ShoppingDict["barcode"]
|
||||
|
||||
|
||||
if len(ShoppingDict["one2n"]):
|
||||
self.one2n = ShoppingDict["one2n"]
|
||||
|
||||
'''=========== path of image and video =========== '''
|
||||
self.back_videopath = ShoppingDict["backCamera"]["videoPath"]
|
||||
self.front_videopath = ShoppingDict["frontCamera"]["videoPath"]
|
||||
self.back_imgpaths = ShoppingDict["backCamera"]["imagePaths"]
|
||||
self.front_imgpaths = ShoppingDict["frontCamera"]["imagePaths"]
|
||||
|
||||
|
||||
'''===========对应于 0/1_track.data ============================='''
|
||||
backdata, back_outdata = self.kerndata(ShoppingDict, "backCamera")
|
||||
|
Reference in New Issue
Block a user