update one2n.py
This commit is contained in:
Binary file not shown.
Binary file not shown.
@ -72,10 +72,11 @@ class FeatsInterface:
|
||||
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:
|
||||
patch = patch.to(device=self.device)
|
||||
patch = patch.to(device=self.device)
|
||||
# if str(self.device) != "cpu":
|
||||
# patch = patch.to(device=self.device).half()
|
||||
# else:
|
||||
# patch = patch.to(device=self.device)
|
||||
|
||||
patches.append(patch)
|
||||
if (i + 1) % self.batch_size == 0:
|
||||
|
@ -120,8 +120,7 @@ def stdfeat_infer(imgPath, featPath, bcdSet=None):
|
||||
|
||||
# imgPath = r"\\192.168.1.28\share\测试_202406\contrast\std_barcodes"
|
||||
# featPath = r"\\192.168.1.28\share\测试_202406\contrast\std_features"
|
||||
stdBarcodeDict = {}
|
||||
stdBarcodeDict_ft16 = {}
|
||||
|
||||
|
||||
Encoder = FeatsInterface(conf)
|
||||
|
||||
@ -167,23 +166,21 @@ def stdfeat_infer(imgPath, featPath, bcdSet=None):
|
||||
# uint8, 两种策略,1) 精度损失小, 2) 计算复杂度小
|
||||
# feature_uint8, _ = ft16_to_uint8(feature_ft16)
|
||||
feature_uint8 = (feature_ft16*128).astype(np.int8)
|
||||
|
||||
'''================ 保存单个barcode特征 ================'''
|
||||
##================== float32
|
||||
stdbDict["barcode"] = barcode
|
||||
stdbDict["imgpaths"] = imgpaths
|
||||
stdbDict["feats_ft32"] = feature_ft32
|
||||
stdbDict["feats_ft16"] = feature_ft16
|
||||
stdbDict["feats_uint8"] = feature_uint8
|
||||
|
||||
with open(featpath, 'wb') as f:
|
||||
pickle.dump(stdbDict, f)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error accured at: {filename}, with Exception is: {e}")
|
||||
|
||||
'''================ 保存单个barcode特征 ================'''
|
||||
##================== float32
|
||||
stdbDict["barcode"] = barcode
|
||||
stdbDict["imgpaths"] = imgpaths
|
||||
stdbDict["feats_ft32"] = feature_ft32
|
||||
stdbDict["feats_ft16"] = feature_ft16
|
||||
stdbDict["feats_uint8"] = feature_uint8
|
||||
|
||||
with open(featpath, 'wb') as f:
|
||||
pickle.dump(stdbDict, f)
|
||||
|
||||
stdBarcodeDict[barcode] = feature
|
||||
stdBarcodeDict_ft16[barcode] = feature_ft16
|
||||
|
||||
|
||||
t2 = time.time()
|
||||
print(f"Barcode: {barcode}, need time: {t2-t1:.1f} secs")
|
||||
|
@ -24,7 +24,7 @@ def init_eventdict(sourcePath, stype="data"):
|
||||
# bname = r"20241126-135911-bdf91cf9-3e9a-426d-94e8-ddf92238e175_6923555210479"
|
||||
|
||||
source_path = os.path.join(sourcePath, bname)
|
||||
if stype=="data":
|
||||
if stype=="data" or stype=="realtime":
|
||||
pickpath = os.path.join(eventDataPath, f"{bname}.pickle")
|
||||
if not os.path.isdir(source_path) or os.path.isfile(pickpath):
|
||||
continue
|
||||
@ -32,7 +32,12 @@ def init_eventdict(sourcePath, stype="data"):
|
||||
pickpath = os.path.join(eventDataPath, bname)
|
||||
if not os.path.isfile(source_path) or os.path.isfile(pickpath):
|
||||
continue
|
||||
|
||||
|
||||
evt = os.path.splitext(os.path.split(pickpath)[-1])[0].split('_')
|
||||
cont = len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10
|
||||
if not cont:
|
||||
continue
|
||||
|
||||
try:
|
||||
event = ShoppingEvent(source_path, stype)
|
||||
|
||||
@ -46,10 +51,10 @@ def init_eventdict(sourcePath, stype="data"):
|
||||
# if k==1:
|
||||
# break
|
||||
|
||||
errfile = os.path.join(resultPath, 'error_events.txt')
|
||||
with open(errfile, 'a', encoding='utf-8') as f:
|
||||
for line in errEvents:
|
||||
f.write(line + '\n')
|
||||
# errfile = os.path.join(resultPath, 'error_events.txt')
|
||||
# with open(errfile, 'a', encoding='utf-8') as f:
|
||||
# for line in errEvents:
|
||||
# f.write(line + '\n')
|
||||
|
||||
def read_eventdict(eventDataPath):
|
||||
evtDict = {}
|
||||
@ -236,14 +241,22 @@ def one2n_pr(evtDicts, pattern=1):
|
||||
def main():
|
||||
|
||||
'''1. 生成事件字典并保存至 eventDataPath, 只需运行一次 '''
|
||||
init_eventdict(eventSourcePath, stype="data")
|
||||
init_eventdict(eventSourcePath, stype="source") # 'source', 'data', 'realtime'
|
||||
|
||||
|
||||
# for pfile in os.listdir(eventDataPath):
|
||||
# evt = os.path.splitext(pfile)[0].split('_')
|
||||
# cont = len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10
|
||||
# if not cont:
|
||||
# continue
|
||||
|
||||
|
||||
'''2. 读取事件字典 '''
|
||||
evtDicts = read_eventdict(eventDataPath)
|
||||
|
||||
|
||||
'''3. 1:n 比对事件评估 '''
|
||||
fpevents = one2n_pr(evtDicts, pattern=1)
|
||||
fpevents = one2n_pr(evtDicts, pattern=2)
|
||||
|
||||
fpErrFile = str(Path(resultPath).joinpath("one2n_fp_Error.txt"))
|
||||
with open(fpErrFile, "w") as file:
|
||||
@ -253,10 +266,10 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对数据"
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing"
|
||||
eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\result_V12\ShoppingDict_pkfile"
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\testing"
|
||||
|
||||
eventDataPath = os.path.join(resultPath, "evtobjs")
|
||||
eventDataPath = os.path.join(resultPath, "evtobjs_data")
|
||||
if not os.path.exists(eventDataPath):
|
||||
os.makedirs(eventDataPath)
|
||||
|
||||
|
@ -418,8 +418,7 @@ def one2one_simi(evtList, evtDict, stdDict):
|
||||
|
||||
'''================ float32、16、int8 精度比较与存储 ============='''
|
||||
# data_precision_compare(stdfeat, evtfeat, mergePairs[i], save=True)
|
||||
|
||||
|
||||
|
||||
return rltdata
|
||||
|
||||
|
||||
@ -520,12 +519,12 @@ def gen_eventdict(sourcePath, saveimg=True):
|
||||
pickpath = os.path.join(eventDataPath, f"{bname}.pickle")
|
||||
if os.path.isfile(pickpath): continue
|
||||
|
||||
# event = ShoppingEvent(source_path, stype="data")
|
||||
# event = ShoppingEvent(source_path, stype=source_type)
|
||||
# with open(pickpath, 'wb') as f:
|
||||
# pickle.dump(event, f)
|
||||
|
||||
try:
|
||||
event = ShoppingEvent(source_path, stype="source")
|
||||
event = ShoppingEvent(source_path, stype=source_type)
|
||||
# save_data(event, resultPath)
|
||||
|
||||
with open(pickpath, 'wb') as f:
|
||||
@ -541,38 +540,35 @@ def gen_eventdict(sourcePath, saveimg=True):
|
||||
|
||||
|
||||
errfile = os.path.join(resultPath, 'error_events.txt')
|
||||
with open(errfile, 'w', encoding='utf-8') as f:
|
||||
for line in errEvents:
|
||||
f.write(line + '\n')
|
||||
# with open(errfile, 'w', encoding='utf-8') as f:
|
||||
# for line in errEvents:
|
||||
# f.write(line + '\n')
|
||||
|
||||
|
||||
def init_std_evt_dict():
|
||||
'''==== 0. 生成事件列表和对应的 Barcodes列表 ==========='''
|
||||
bcdList, event_spath = [], []
|
||||
for evtpath in eventSourcePath:
|
||||
for evtname in os.listdir(evtpath):
|
||||
bname, ext = os.path.splitext(evtname)
|
||||
|
||||
## 处理事件的两种情况:文件夹 和 Yolo-Resnet-Tracker 的输出
|
||||
fpath = os.path.join(evtpath, evtname)
|
||||
if os.path.isfile(fpath) and (ext==".pkl" or ext==".pickle"):
|
||||
evt = bname.split('_')
|
||||
elif os.path.isdir(fpath):
|
||||
evt = evtname.split('_')
|
||||
else:
|
||||
continue
|
||||
|
||||
|
||||
if len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10:
|
||||
bcdList.append(evt[-1])
|
||||
event_spath.append(os.path.join(evtpath, evtname))
|
||||
for evtname in os.listdir(eventSourcePath):
|
||||
bname, ext = os.path.splitext(evtname)
|
||||
|
||||
## 处理事件的两种情况:文件夹 和 Yolo-Resnet-Tracker 的输出
|
||||
fpath = os.path.join(eventSourcePath, evtname)
|
||||
if os.path.isfile(fpath) and (ext==".pkl" or ext==".pickle"):
|
||||
evt = bname.split('_')
|
||||
elif os.path.isdir(fpath):
|
||||
evt = evtname.split('_')
|
||||
else:
|
||||
continue
|
||||
|
||||
if len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10:
|
||||
bcdList.append(evt[-1])
|
||||
event_spath.append(fpath)
|
||||
|
||||
'''==== 1. 生成标准特征集, 只需运行一次, 在 genfeats.py 中实现 ==========='''
|
||||
bcdSet = set(bcdList)
|
||||
gen_bcd_features(stdSamplePath, stdBarcodePath, stdFeaturePath, bcdSet)
|
||||
print("stdFeats have generated and saved!")
|
||||
|
||||
|
||||
|
||||
'''==== 2. 生成事件字典, 只需运行一次 ==============='''
|
||||
gen_eventdict(event_spath)
|
||||
print("eventList have generated and saved!")
|
||||
@ -584,7 +580,7 @@ def test_one2one():
|
||||
'''1:1性能评估'''
|
||||
|
||||
# 1. 只需运行一次,生成事件字典和相应的标准特征库字典
|
||||
init_std_evt_dict()
|
||||
# init_std_evt_dict()
|
||||
|
||||
# 2. 基于事件barcode集和标准库barcode交集构造事件集合
|
||||
evtList, evtDict, stdDict = build_std_evt_dict()
|
||||
@ -598,7 +594,7 @@ def test_one2SN():
|
||||
'''1:SN性能评估'''
|
||||
|
||||
# 1. 只需运行一次,生成事件字典和相应的标准特征库字典
|
||||
init_std_evt_dict()
|
||||
# init_std_evt_dict()
|
||||
|
||||
# 2. 事件barcode集和标准库barcode求交集
|
||||
evtList, evtDict, stdDict = build_std_evt_dict()
|
||||
@ -612,7 +608,7 @@ if __name__ == '__main__':
|
||||
(1) stdSamplePath: 用于生成比对标准特征集的原始图像地址
|
||||
(2) stdBarcodePath: 比对标准特征集原始图像地址的pickle文件存储,{barcode: [imgpath1, imgpath1, ...]}
|
||||
(3) stdFeaturePath: 比对标准特征集特征存储地址
|
||||
(4) eventSourcePath: 事件地址
|
||||
(4) eventSourcePath: 事件地址, 包含data文件的文件夹或 Yolo-Resnet-Tracker输出的Pickle文件父文件夹
|
||||
(5) resultPath: 结果存储地址
|
||||
(6) eventDataPath: 用于1:1比对的购物事件存储地址,在resultPath下
|
||||
(7) similPath: 1:1比对结果存储地址(事件级),在resultPath下
|
||||
@ -622,19 +618,33 @@ if __name__ == '__main__':
|
||||
# stdBarcodePath = r"D:\exhibition\dataset\bcdpath"
|
||||
# stdFeaturePath = r"\\192.168.1.28\share\数据\已完成数据\比对数据\barcode\all_totalBarocde\features_json\v11_barcode_11592"
|
||||
|
||||
# eventSourcePath = [r'D:\exhibition\images\20241202']
|
||||
# eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\展厅测试\1129_展厅模型v801测试组测试"]
|
||||
# eventSourcePath = r'D:\exhibition\images\20241202'
|
||||
# eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\展厅测试\1129_展厅模型v801测试组测试"
|
||||
|
||||
# stdSamplePath = r"\\192.168.1.28\share\数据\已完成数据\展厅数据\v2.0_abroad\比对数据\all_base_二筛"
|
||||
# stdBarcodePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对测试数据20250121_testing\bcdpath"
|
||||
# stdFeaturePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对测试数据20250121_testing\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"
|
||||
stdSamplePath = r"\\192.168.1.28\share\数据\已完成数据\比对数据\barcode\all_totalBarocde\totalBarcode"
|
||||
stdBarcodePath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\testing\bcdpath"
|
||||
stdFeaturePath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\testing\stdfeats"
|
||||
|
||||
if not os.path.exists(stdBarcodePath):
|
||||
os.makedirs(stdBarcodePath)
|
||||
if not os.path.exists(stdFeaturePath):
|
||||
os.makedirs(stdFeaturePath)
|
||||
|
||||
eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对数据"]
|
||||
'''
|
||||
source_type:
|
||||
"source": eventSourcePath 为 Yolo-Resnet-Tracker 输出的 pickle 文件
|
||||
"data": eventSourcePath 为 包含 data 文件的文件夹
|
||||
'''
|
||||
source_type = 'realtime' # 'source', 'data', 'realtime'
|
||||
eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\V12\2025-2-21\比对\video"
|
||||
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing\evtobjs"
|
||||
eventDataPath = os.path.join(resultPath, "evtobjs")
|
||||
similPath = os.path.join(resultPath, "simidata")
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\testing"
|
||||
eventDataPath = os.path.join(resultPath, "evtobjs_data")
|
||||
similPath = os.path.join(resultPath, "simidata_data")
|
||||
if not os.path.exists(eventDataPath):
|
||||
os.makedirs(eventDataPath)
|
||||
if not os.path.exists(similPath):
|
||||
|
@ -1,8 +1,13 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Wed Sep 11 11:57:30 2024
|
||||
永辉现场试验输出数据的 1:1 性能评估
|
||||
适用于202410前数据保存版本的,需调用 OneToOneCompare.txt
|
||||
contrast_pr:
|
||||
直接利用测试数据中的 data 文件进行 1:1、1:SN、1:n 性能评估
|
||||
|
||||
test_compare:
|
||||
永辉现场试验输出数据的 1:1 性能评估
|
||||
适用于202410前数据保存版本的,需调用 OneToOneCompare.txt
|
||||
@author: ym
|
||||
"""
|
||||
import os
|
||||
@ -147,6 +152,7 @@ def contrast_pr(paths):
|
||||
|
||||
errorFile_one2one, errorFile_one2SN, errorFile_one2n = [], [], []
|
||||
|
||||
errorFile = []
|
||||
for path in evtpaths:
|
||||
barcode = path.stem.split('_')[-1]
|
||||
datapath = path.joinpath('process.data')
|
||||
@ -167,6 +173,10 @@ def contrast_pr(paths):
|
||||
one2SN = SimiDict['one2SN']
|
||||
one2n = SimiDict['one2n']
|
||||
|
||||
if len(one2one)+len(one2SN)+len(one2n) == 0:
|
||||
errorFile.append(path.stem)
|
||||
|
||||
|
||||
'''================== 0. 1:1 ==================='''
|
||||
barcodes, similars = [], []
|
||||
for dt in one2one:
|
||||
@ -176,6 +186,8 @@ def contrast_pr(paths):
|
||||
continue
|
||||
barcodes.append(dt['barcode'])
|
||||
similars.append(dt['similar'])
|
||||
|
||||
|
||||
if len(barcodes)==len(similars) and len(barcodes)!=0:
|
||||
## 扫A放A, 扫A放B场景
|
||||
simAA = [similars[i] for i in range(len(barcodes)) if barcodes[i]==barcode]
|
||||
@ -466,15 +478,15 @@ def contrast_pr(paths):
|
||||
plt.show()
|
||||
|
||||
|
||||
fpsnErrFile = str(paths.joinpath("one2SN_Error.txt"))
|
||||
with open(fpsnErrFile, "w") as file:
|
||||
for item in fp_events:
|
||||
file.write(item + "\n")
|
||||
# fpsnErrFile = str(paths.joinpath("one2SN_Error.txt"))
|
||||
# with open(fpsnErrFile, "w") as file:
|
||||
# for item in fp_events:
|
||||
# file.write(item + "\n")
|
||||
|
||||
fpErrFile = str(paths.joinpath("one2n_Error.txt"))
|
||||
with open(fpErrFile, "w") as file:
|
||||
for item in fpevents:
|
||||
file.write(item + "\n")
|
||||
# fpErrFile = str(paths.joinpath("one2n_Error.txt"))
|
||||
# with open(fpErrFile, "w") as file:
|
||||
# for item in fpevents:
|
||||
# file.write(item + "\n")
|
||||
|
||||
|
||||
|
||||
@ -495,7 +507,7 @@ def contrast_pr(paths):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
evtpaths = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\images"
|
||||
evtpaths = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\V12\2025-2-21\比对\video"
|
||||
contrast_pr(evtpaths)
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -17,6 +17,12 @@ from tracking.utils.drawtracks import drawTrack
|
||||
from tracking.utils.read_data import extract_data, read_tracking_output, read_similar
|
||||
from tracking.utils.read_data import extract_data_realtime, read_tracking_output_realtime
|
||||
|
||||
|
||||
# import platform
|
||||
# import pathlib
|
||||
# plt = platform.system()
|
||||
|
||||
|
||||
IMG_FORMAT = ['.bmp', '.jpg', '.jpeg', '.png']
|
||||
VID_FORMAT = ['.mp4', '.avi']
|
||||
|
||||
@ -166,7 +172,9 @@ class ShoppingEvent:
|
||||
return kdata, outdata
|
||||
|
||||
|
||||
def from_source_pkl(self, eventpath):
|
||||
def from_source_pkl(self, eventpath):
|
||||
# if plt == 'Windows':
|
||||
# pathlib.PosixPath = pathlib.WindowsPath
|
||||
with open(eventpath, 'rb') as f:
|
||||
ShoppingDict = pickle.load(f)
|
||||
|
||||
@ -202,10 +210,10 @@ class ShoppingEvent:
|
||||
self.front_trackingfeats = frontdata[5]
|
||||
|
||||
'''===========对应于 0/1_tracking_output.data ============================='''
|
||||
self.back_boxes = back_outdata
|
||||
self.back_feats = back_outdata
|
||||
self.front_boxes = front_outdata
|
||||
self.front_feats = front_outdata
|
||||
self.back_boxes = back_outdata[0]
|
||||
self.back_feats = back_outdata[1]
|
||||
self.front_boxes = front_outdata[0]
|
||||
self.front_feats = front_outdata[1]
|
||||
|
||||
|
||||
def from_datafile(self, eventpath):
|
||||
@ -296,13 +304,13 @@ class ShoppingEvent:
|
||||
self.front_feats = tracking_output_feats
|
||||
|
||||
def from_realtime_datafile(self, eventpath):
|
||||
# evtList = self.evtname.split('_')
|
||||
# if len(evtList)>=2 and len(evtList[-1])>=10 and evtList[-1].isdigit():
|
||||
# self.barcode = evtList[-1]
|
||||
# if len(evtList)==3 and evtList[-1]== evtList[-2]:
|
||||
# self.evtType = 'input'
|
||||
# else:
|
||||
# self.evtType = 'other'
|
||||
evtList = self.evtname.split('_')
|
||||
if len(evtList)>=2 and len(evtList[-1])>=10 and evtList[-1].isdigit():
|
||||
self.barcode = evtList[-1]
|
||||
if len(evtList)==3 and evtList[-1]== evtList[-2]:
|
||||
self.evtType = 'input'
|
||||
else:
|
||||
self.evtType = 'other'
|
||||
|
||||
'''================ path of video ============='''
|
||||
for vidname in os.listdir(eventpath):
|
||||
@ -330,7 +338,7 @@ class ShoppingEvent:
|
||||
if not os.path.isfile(datapath): continue
|
||||
CamerType = dataname.split('_')[0]
|
||||
'''========== 0/1_track.data =========='''
|
||||
if dataname.find("_track.data")>0:
|
||||
if dataname.find("_tracker.data")>0:
|
||||
trackerboxes, trackerfeats = extract_data_realtime(datapath)
|
||||
if CamerType == '0':
|
||||
self.back_trackerboxes = trackerboxes
|
||||
|
Reference in New Issue
Block a user