modify at output data format
This commit is contained in:
Binary file not shown.
@ -34,10 +34,12 @@ def find_samebox_in_array(arr, target):
|
||||
return -1
|
||||
|
||||
|
||||
|
||||
def extract_data(datapath):
|
||||
'''
|
||||
0/1_track.data 数据读取
|
||||
对于特征,需要构造两个对象:
|
||||
(1) tracking输出 boxes,依据 (fid, bid) 找到对应的 feats, tracker_feat_dict 实现较为方便
|
||||
(2) frameDictList 中元素为 frameDict,输出同一接口
|
||||
'''
|
||||
bboxes, ffeats = [], []
|
||||
|
||||
@ -45,9 +47,7 @@ def extract_data(datapath):
|
||||
trackerfeats = np.empty((0, 256), dtype=np.float64)
|
||||
|
||||
boxes, feats, tboxes, tfeats = [], [], [], []
|
||||
|
||||
timestamps, frameIds = [], []
|
||||
|
||||
with open(datapath, 'r', encoding='utf-8') as lines:
|
||||
for line in lines:
|
||||
line = line.strip() # 去除行尾的换行符和可能的空白字符
|
||||
@ -102,16 +102,17 @@ def extract_data(datapath):
|
||||
assert(len(bboxes)==len(ffeats)), "Error at Yolo output!"
|
||||
assert(len(trackerboxes)==len(trackerfeats)), "Error at tracker output!"
|
||||
|
||||
tracker_feat_dict = {}
|
||||
tracker_feat_dict["timestamps"] = timestamps
|
||||
tracker_feat_dict["frameIds"] = frameIds
|
||||
|
||||
for i in range(len(trackerboxes)):
|
||||
tid, fid, bid = int(trackerboxes[i, 4]), int(trackerboxes[i, 7]), int(trackerboxes[i, 8])
|
||||
if f"frame_{fid}" not in tracker_feat_dict:
|
||||
tracker_feat_dict[f"frame_{fid}"]= {"feats": {}}
|
||||
tracker_feat_dict[f"frame_{fid}"]["feats"].update({bid: trackerfeats[i, :]})
|
||||
|
||||
## 生成帧为单位的特征列表
|
||||
tracker_feats = {}
|
||||
frmIDs = np.sort(np.unique(trackerboxes[:, 7].astype(int)))
|
||||
for fid in frmIDs:
|
||||
idx = np.where(trackerboxes[:, 7] == fid)[0]
|
||||
boxes = trackerboxes[idx, :]
|
||||
feats = trackerfeats[idx, :]
|
||||
|
||||
for i in range(len(boxes)):
|
||||
f, b = int(boxes[i, 7]), int(boxes[i, 8])
|
||||
tracker_feats.update({f"{f}_{b}": feats[i, :]})
|
||||
|
||||
boxes, trackingboxes= [], []
|
||||
tracking_flag = False
|
||||
@ -137,18 +138,41 @@ def extract_data(datapath):
|
||||
if len(boxes):
|
||||
trackingboxes.append(np.array(boxes))
|
||||
|
||||
tracking_feat_dict = {}
|
||||
# tracking_feat_dict = {}
|
||||
# try:
|
||||
# for i, boxes in enumerate(trackingboxes):
|
||||
# for box in boxes:
|
||||
# tid, fid, bid = int(box[4]), int(box[7]), int(box[8])
|
||||
# if f"track_{tid}" not in tracking_feat_dict:
|
||||
# tracking_feat_dict[f"track_{tid}"]= {"feats": {}}
|
||||
# tracking_feat_dict[f"track_{tid}"]["feats"].update({f"{fid}_{bid}": tracker_feat_dict[f"frame_{fid}"]["feats"][bid]})
|
||||
# except Exception as e:
|
||||
# print(f'Path: {datapath}, tracking_feat_dict can not be structured correcttly, Error: {e}')
|
||||
|
||||
# tracker_feat_dict = {}
|
||||
# tracker_feat_dict["timestamps"] = timestamps
|
||||
# tracker_feat_dict["frameIds"] = frameIds
|
||||
|
||||
# for i in range(len(trackerboxes)):
|
||||
# fid, bid = int(trackerboxes[i, 7]), int(trackerboxes[i, 8])
|
||||
# if f"frame_{fid}" not in tracker_feat_dict:
|
||||
# tracker_feat_dict[f"frame_{fid}"]= {"feats": {}}
|
||||
# tracker_feat_dict[f"frame_{fid}"]["feats"].update({bid: trackerfeats[i, :]})
|
||||
|
||||
trackingfeats = []
|
||||
try:
|
||||
for i, boxes in enumerate(trackingboxes):
|
||||
feats = []
|
||||
for box in boxes:
|
||||
tid, fid, bid = int(box[4]), int(box[7]), int(box[8])
|
||||
if f"track_{tid}" not in tracking_feat_dict:
|
||||
tracking_feat_dict[f"track_{tid}"]= {"feats": {}}
|
||||
tracking_feat_dict[f"track_{tid}"]["feats"].update({f"{fid}_{bid}": tracker_feat_dict[f"frame_{fid}"]["feats"][bid]})
|
||||
fid, bid = int(box[7]), int(box[8])
|
||||
feat = tracker_feats[f"{fid}_{bid}"]
|
||||
feats.append(feat)
|
||||
trackingfeats.append(np.array(feats))
|
||||
except Exception as e:
|
||||
print(f'Path: {datapath}, tracking_feat_dict can not be structured correcttly, Error: {e}')
|
||||
print(f'Path: {datapath}, trackingfeats can not be structured correcttly, Error: {e}')
|
||||
|
||||
return bboxes, ffeats, trackerboxes, tracker_feat_dict, trackingboxes, tracking_feat_dict
|
||||
# return bboxes, ffeats, trackerboxes, tracker_feat_dict, trackingboxes, trackingfeats
|
||||
return bboxes, ffeats, trackerboxes, tracker_feats, trackingboxes, trackingfeats
|
||||
|
||||
def read_tracking_output(filepath):
|
||||
'''
|
||||
@ -236,8 +260,6 @@ def read_returnGoods_file(filePath):
|
||||
lines = f.readlines()
|
||||
clean_lines = [line.strip().replace("'", '').replace('"', '') for line in lines]
|
||||
|
||||
|
||||
|
||||
all_list = []
|
||||
split_flag, dict = False, {}
|
||||
barcode_list, similarity_list = [], []
|
||||
@ -318,14 +340,15 @@ def read_seneor(filepath):
|
||||
def read_similar(filePath):
|
||||
SimiDict = {}
|
||||
SimiDict['one2one'] = []
|
||||
SimiDict['one2SN'] = []
|
||||
SimiDict['one2n'] = []
|
||||
|
||||
with open(filePath, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
clean_lines = [line.strip().replace("'", '').replace('"', '') for line in lines]
|
||||
one2one_list, one2n_list = [], []
|
||||
one2one_list, one2SN_list, one2n_list = [], [], []
|
||||
|
||||
Flag_1to1, Flag_1ton = False, False
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, False, False
|
||||
for i, line in enumerate(clean_lines):
|
||||
line = line.strip()
|
||||
if line.endswith(','):
|
||||
@ -334,18 +357,26 @@ def read_similar(filePath):
|
||||
|
||||
if not line:
|
||||
if len(one2one_list): SimiDict['one2one'] = one2one_list
|
||||
if len(one2SN_list): SimiDict['one2SN'] = one2SN_list
|
||||
if len(one2n_list): SimiDict['one2n'] = one2n_list
|
||||
one2one_list, one2n_list = [], []
|
||||
Flag_1to1, Flag_1ton = False, False
|
||||
|
||||
|
||||
one2one_list, one2SN_list, one2n_list = [], [], []
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, False, False
|
||||
continue
|
||||
|
||||
if line.find('oneToOne')>=0:
|
||||
Flag_1to1, Flag_1ton = True, False
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = True, False,False
|
||||
continue
|
||||
if line.find('oneToSN')>=0:
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, True, False
|
||||
continue
|
||||
if line.find('oneTon')>=0:
|
||||
Flag_1to1, Flag_1ton = False, True
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, False, True
|
||||
continue
|
||||
|
||||
|
||||
|
||||
if Flag_1to1:
|
||||
barcode = line.split(',')[0].strip()
|
||||
value = line.split(',')[1].split(':')[1].strip()
|
||||
@ -353,6 +384,14 @@ def read_similar(filePath):
|
||||
Dict['similar'] = float(value)
|
||||
one2one_list.append(Dict)
|
||||
continue
|
||||
|
||||
if Flag_1toSN:
|
||||
barcode = line.split(',')[0].strip()
|
||||
value = line.split(',')[1].split(':')[1].strip()
|
||||
Dict['barcode'] = barcode
|
||||
Dict['similar'] = float(value)
|
||||
one2SN_list.append(Dict)
|
||||
continue
|
||||
|
||||
if Flag_1ton:
|
||||
label = line.split(':')[0].strip()
|
||||
|
Reference in New Issue
Block a user