-
Notifications
You must be signed in to change notification settings - Fork 0
/
yolov3_deepsort_eval.py
87 lines (72 loc) · 2.9 KB
/
yolov3_deepsort_eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
import os.path as osp
import logging
import argparse
from pathlib import Path
from utils.log import get_logger
from yolov3_deepsort import VideoTracker
from utils.parser import get_config
import motmetrics as mm
mm.lap.default_solver = 'lap'
from utils.evaluation import Evaluator
def mkdir_if_missing(dir):
os.makedirs(dir, exist_ok=True)
def main(data_root='', seqs=('',), args=""):
logger = get_logger()
logger.setLevel(logging.INFO)
data_type = 'mot'
result_root = os.path.join(Path(data_root), "mot_results")
mkdir_if_missing(result_root)
cfg = get_config()
cfg.merge_from_file(args.config_detection)
cfg.merge_from_file(args.config_deepsort)
# run tracking
accs = []
for seq in seqs:
logger.info('start seq: {}'.format(seq))
result_filename = os.path.join(result_root, '{}.txt'.format(seq))
video_path = data_root+"/"+seq+"/video/video.mp4"
with VideoTracker(cfg, args, video_path, result_filename) as vdo_trk:
vdo_trk.run()
# eval
logger.info('Evaluate seq: {}'.format(seq))
evaluator = Evaluator(data_root, seq, data_type)
accs.append(evaluator.eval_file(result_filename))
# get summary
metrics = mm.metrics.motchallenge_metrics
mh = mm.metrics.create()
summary = Evaluator.get_summary(accs, seqs, metrics)
strsummary = mm.io.render_summary(
summary,
formatters=mh.formatters,
namemap=mm.io.motchallenge_metric_names
)
print(strsummary)
Evaluator.save_summary(summary, os.path.join(result_root, 'summary_global.xlsx'))
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--config_detection", type=str, default="./configs/yolov3.yaml")
parser.add_argument("--config_deepsort", type=str, default="./configs/deep_sort.yaml")
parser.add_argument("--ignore_display", dest="display", action="store_false", default=False)
parser.add_argument("--frame_interval", type=int, default=1)
parser.add_argument("--display_width", type=int, default=800)
parser.add_argument("--display_height", type=int, default=600)
parser.add_argument("--save_path", type=str, default="./demo/demo.avi")
parser.add_argument("--cpu", dest="use_cuda", action="store_false", default=True)
parser.add_argument("--camera", action="store", dest="cam", type=int, default="-1")
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
seqs_str = '''MOT16-02
MOT16-04
MOT16-05
MOT16-09
MOT16-10
MOT16-11
MOT16-13
'''
data_root = 'data/dataset/MOT16/train/'
seqs = [seq.strip() for seq in seqs_str.split()]
main(data_root=data_root,
seqs=seqs,
args=args)