| 18 | |
| 19 | |
| 20 | def write_results(filename, results, data_type): |
| 21 | if data_type == 'mot': |
| 22 | save_format = '{frame},{id},{x1},{y1},{w},{h},1,-1,-1,-1\n' |
| 23 | elif data_type == 'kitti': |
| 24 | save_format = '{frame} {id} pedestrian 0 0 -10 {x1} {y1} {x2} {y2} -10 -10 -10 -1000 -1000 -1000 -10\n' |
| 25 | else: |
| 26 | raise ValueError(data_type) |
| 27 | |
| 28 | with open(filename, 'w') as f: |
| 29 | for frame_id, tlwhs, track_ids in results: |
| 30 | if data_type == 'kitti': |
| 31 | frame_id -= 1 |
| 32 | for tlwh, track_id in zip(tlwhs, track_ids): |
| 33 | if track_id < 0: |
| 34 | continue |
| 35 | x1, y1, w, h = tlwh |
| 36 | x2, y2 = x1 + w, y1 + h |
| 37 | line = save_format.format(frame=frame_id, id=track_id, x1=x1, y1=y1, x2=x2, y2=y2, w=w, h=h) |
| 38 | f.write(line) |
| 39 | logger.info('save results to {}'.format(filename)) |
| 40 | |
| 41 | |
| 42 | def eval_seq(opt, dataloader, data_type, result_filename, save_dir=None, show_image=True, frame_rate=30): |