Skip to content

Commit 76bb885

Browse files
committed
update save_results
1 parent 40ce97a commit 76bb885

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ runs/*
1010
wandb/*
1111
track_result.txt
1212
.idea/
13+
tracker/results/*
1314

1415
# Byte-compiled / optimized / DLL files
1516
__pycache__/

tracker/track.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,15 @@ def post_process_v7(out, img_size, ori_img_size):
244244
return out
245245

246246

247-
def save_results(folder_name, seq_name, results, data_type='default'):
247+
def save_results(folder_name, seq_name, results, data_type='mot17'):
248248
"""
249249
write results to txt file
250250
251251
results: list row format: frame id, target id, box coordinate, class(optional)
252252
to_file: file path(optional)
253-
data_type: write data format
253+
data_type: write data format, default or mot17 format.
254254
"""
255255
assert len(results)
256-
if not data_type == 'default':
257-
raise NotImplementedError # TODO
258256

259257
if not os.path.exists(f'./tracker/results/{folder_name}'):
260258

@@ -263,11 +261,13 @@ def save_results(folder_name, seq_name, results, data_type='default'):
263261
with open(os.path.join('./tracker/results', folder_name, seq_name + '.txt'), 'w') as f:
264262
for frame_id, target_ids, tlwhs, clses in results:
265263
if data_type == 'default':
266-
267-
# f.write(f'{frame_id},{target_id},{tlwh[0]},{tlwh[1]},\
268-
# {tlwh[2]},{tlwh[3]},{cls}\n')
264+
269265
for id, tlwh, cls in zip(target_ids, tlwhs, clses):
270266
f.write(f'{frame_id},{id},{tlwh[0]:.2f},{tlwh[1]:.2f},{tlwh[2]:.2f},{tlwh[3]:.2f},{int(cls)}\n')
267+
268+
elif data_type == 'mot17':
269+
for id, tlwh, cls in zip(target_ids, tlwhs, clses):
270+
f.write(f'{frame_id},{id},{tlwh[0]:.2f},{tlwh[1]:.2f},{tlwh[2]:.2f},{tlwh[3]:.2f},1.0,-1,-1,-1\n')
271271
f.close()
272272

273273
return folder_name
@@ -359,7 +359,7 @@ def get_color(idx):
359359
parser.add_argument('--dhn_path', type=str, default='./weights/DHN.pth', help='path of DHN path for DeepMOT')
360360

361361
# threshs
362-
parser.add_argument('--conf_thresh', type=float, default=0.5, help='filter tracks')
362+
parser.add_argument('--conf_thresh', type=float, default=0.2, help='filter tracks')
363363
parser.add_argument('--nms_thresh', type=float, default=0.7, help='thresh for NMS')
364364
parser.add_argument('--iou_thresh', type=float, default=0.5, help='IOU thresh to filter tracks')
365365

tracker/track_yolov5.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,15 @@ def post_process_v5(out, img_size, ori_img_size):
230230

231231

232232

233-
def save_results(folder_name, seq_name, results, data_type='default'):
233+
def save_results(folder_name, seq_name, results, data_type='mot17'):
234234
"""
235235
write results to txt file
236236
237237
results: list row format: frame id, target id, box coordinate, class(optional)
238238
to_file: file path(optional)
239-
data_type: write data format
239+
data_type: write data format, default or mot17 format.
240240
"""
241241
assert len(results)
242-
if not data_type == 'default':
243-
raise NotImplementedError # TODO
244242

245243
if not os.path.exists(f'./tracker/results/{folder_name}'):
246244

@@ -249,11 +247,13 @@ def save_results(folder_name, seq_name, results, data_type='default'):
249247
with open(os.path.join('./tracker/results', folder_name, seq_name + '.txt'), 'w') as f:
250248
for frame_id, target_ids, tlwhs, clses in results:
251249
if data_type == 'default':
252-
253-
# f.write(f'{frame_id},{target_id},{tlwh[0]},{tlwh[1]},\
254-
# {tlwh[2]},{tlwh[3]},{cls}\n')
250+
255251
for id, tlwh, cls in zip(target_ids, tlwhs, clses):
256252
f.write(f'{frame_id},{id},{tlwh[0]:.2f},{tlwh[1]:.2f},{tlwh[2]:.2f},{tlwh[3]:.2f},{int(cls)}\n')
253+
254+
elif data_type == 'mot17':
255+
for id, tlwh, cls in zip(target_ids, tlwhs, clses):
256+
f.write(f'{frame_id},{id},{tlwh[0]:.2f},{tlwh[1]:.2f},{tlwh[2]:.2f},{tlwh[3]:.2f},1.0,-1,-1,-1\n')
257257
f.close()
258258

259259
return folder_name

tracker/track_yolov8.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,15 @@ def postprocess_v8(out):
238238
return out
239239

240240

241-
def save_results(folder_name, seq_name, results, data_type='default'):
241+
def save_results(folder_name, seq_name, results, data_type='mot17'):
242242
"""
243243
write results to txt file
244244
245245
results: list row format: frame id, target id, box coordinate, class(optional)
246246
to_file: file path(optional)
247-
data_type: write data format
247+
data_type: write data format, default or mot17 format.
248248
"""
249249
assert len(results)
250-
if not data_type == 'default':
251-
raise NotImplementedError # TODO
252250

253251
if not os.path.exists(f'./tracker/results/{folder_name}'):
254252

@@ -257,11 +255,13 @@ def save_results(folder_name, seq_name, results, data_type='default'):
257255
with open(os.path.join('./tracker/results', folder_name, seq_name + '.txt'), 'w') as f:
258256
for frame_id, target_ids, tlwhs, clses in results:
259257
if data_type == 'default':
260-
261-
# f.write(f'{frame_id},{target_id},{tlwh[0]},{tlwh[1]},\
262-
# {tlwh[2]},{tlwh[3]},{cls}\n')
258+
263259
for id, tlwh, cls in zip(target_ids, tlwhs, clses):
264260
f.write(f'{frame_id},{id},{tlwh[0]:.2f},{tlwh[1]:.2f},{tlwh[2]:.2f},{tlwh[3]:.2f},{int(cls)}\n')
261+
262+
elif data_type == 'mot17':
263+
for id, tlwh, cls in zip(target_ids, tlwhs, clses):
264+
f.write(f'{frame_id},{id},{tlwh[0]:.2f},{tlwh[1]:.2f},{tlwh[2]:.2f},{tlwh[3]:.2f},1.0,-1,-1,-1\n')
265265
f.close()
266266

267267
return folder_name

0 commit comments

Comments
 (0)