Skip to content

Commit 2a22455

Browse files
committed
add lables to detections
1 parent fe53ac5 commit 2a22455

File tree

8 files changed

+94
-36
lines changed

8 files changed

+94
-36
lines changed

demo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def main(args):
1818
detections = load_mot(args.detection_path)
1919

2020
start = time()
21-
tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min)
21+
tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou,
22+
args.t_min)
2223
end = time()
2324

2425
num_frames = len(detections)
@@ -28,12 +29,12 @@ def main(args):
2829

2930

3031
if __name__ == '__main__':
31-
3232
parser = argparse.ArgumentParser(description="IOU Tracker demo script")
3333
parser.add_argument('-d', '--detection_path', type=str, required=True,
3434
help="full path to CSV file containing the detections")
3535
parser.add_argument('-o', '--output_path', type=str, required=True,
36-
help="output path to store the tracking results (MOT challenge devkit compatible format)")
36+
help="output path to store the tracking results "
37+
"(MOT challenge devkit compatible format)")
3738
parser.add_argument('-sl', '--sigma_l', type=float, default=0,
3839
help="low detection threshold")
3940
parser.add_argument('-sh', '--sigma_h', type=float, default=0.5,

iou_tracker.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
def track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min):
1414
"""
1515
Simple IOU based tracker.
16-
See "High-Speed Tracking-by-Detection Without Using Image Information by E. Bochinski, V. Eiselein, T. Sikora" for
16+
See "High-Speed Tracking-by-Detection Without Using Image Information
17+
by E. Bochinski, V. Eiselein, T. Sikora" for
1718
more information.
1819
1920
Args:
20-
detections (list): list of detections per frame, usually generated by util.load_mot
21+
detections (list): list of detections per frame, usually generated by
22+
util.load_mot
2123
sigma_l (float): low detection threshold.
2224
sigma_h (float): high detection threshold.
2325
sigma_iou (float): IOU threshold.
@@ -38,10 +40,12 @@ def track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min):
3840
for track in tracks_active:
3941
if len(dets) > 0:
4042
# get det with highest iou
41-
best_match = max(dets, key=lambda x: iou(track['bboxes'][-1], x['bbox']))
43+
best_match = max(dets, key=lambda x: iou(track['bboxes'][-1],
44+
x['bbox']))
4245
if iou(track['bboxes'][-1], best_match['bbox']) >= sigma_iou:
4346
track['bboxes'].append(best_match['bbox'])
44-
track['max_score'] = max(track['max_score'], best_match['score'])
47+
track['max_score'] = max(track['max_score'],
48+
best_match['score'])
4549

4650
updated_tracks.append(track)
4751

@@ -51,16 +55,19 @@ def track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min):
5155
# if track was not updated
5256
if len(updated_tracks) == 0 or track is not updated_tracks[-1]:
5357
# finish track when the conditions are met
54-
if track['max_score'] >= sigma_h and len(track['bboxes']) >= t_min:
58+
if track['max_score'] >= sigma_h and len(
59+
track['bboxes']) >= t_min:
5560
tracks_finished.append(track)
5661

5762
# create new tracks
58-
new_tracks = [{'bboxes': [det['bbox']], 'max_score': det['score'], 'start_frame': frame_num} for det in dets]
63+
new_tracks = [{'bboxes': [det['bbox']], 'max_score': det['score'],
64+
'start_frame': frame_num} for det in dets]
5965
tracks_active = updated_tracks + new_tracks
6066

6167
# finish all remaining active tracks
6268
tracks_finished += [track for track in tracks_active
63-
if track['max_score'] >= sigma_h and len(track['bboxes']) >= t_min]
69+
if track['max_score'] >= sigma_h and len(
70+
track['bboxes']) >= t_min]
6471

6572
return tracks_finished
6673

@@ -91,7 +98,8 @@ def track_iou_matlab_wrapper(detections, sigma_l, sigma_h, sigma_iou, t_min):
9198
out = []
9299
for track in tracks:
93100
for i, bbox in enumerate(track['bboxes']):
94-
out += [float(bbox[0]), float(bbox[1]), float(bbox[2] - bbox[0]), float(bbox[3] - bbox[1]),
101+
out += [float(bbox[0]), float(bbox[1]), float(bbox[2] - bbox[0]),
102+
float(bbox[3] - bbox[1]),
95103
float(track['start_frame'] + i), float(id_)]
96104
id_ += 1
97105

mot16.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,29 @@ def main(args):
2828
detections = load_mot(det_path)
2929

3030
start = time()
31-
tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min)
31+
tracks = track_iou(detections, args.sigma_l, args.sigma_h,
32+
args.sigma_iou, args.t_min)
3233
end = time()
3334

3435
num_frames = len(detections)
35-
print("finished " + seq + " at " + str(int(num_frames / (end - start))) + " fps!")
36+
print("finished " + seq + " at " + str(
37+
int(num_frames / (end - start))) + " fps!")
3638

3739
save_to_csv(out_path, tracks)
3840

3941

4042
if __name__ == '__main__':
41-
42-
parser = argparse.ArgumentParser(description="IOU Tracker MOT demo script. Default parameters are set to reproduce "
43-
"the results using the SDP detections.")
44-
parser.add_argument('-m', '--seqmap', type=str, required=True,
43+
parser = argparse.ArgumentParser(
44+
description="IOU Tracker MOT demo script. Default parameters are set to "
45+
"reproduce the results using the SDP detections.")
46+
parser.add_argument('-m', '--seqmap', type=str,
47+
default="../motchallenge/seqmaps/c5-train.txt",
4548
help="full path to the seqmap file to evaluate")
46-
parser.add_argument('-o', '--res_dir', type=str, required=True,
49+
parser.add_argument('-o', '--res_dir', type=str,
50+
default="../motchallenge/res/MOT16/iou-tracker",
4751
help="path to the results directory")
48-
parser.add_argument('-b', '--benchmark_dir', type=str, required=True,
52+
parser.add_argument('-b', '--benchmark_dir', type=str,
53+
default="../motchallenge/MOT16/train",
4954
help="path to the sequence directory")
5055
parser.add_argument('-sl', '--sigma_l', type=float, default=0.3,
5156
help="low detection threshold")

mot17.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ def main(args):
3838
sigma_iou = 0.2
3939
t_min = 2
4040
else:
41-
print("No detector name found, this could happen with the wrong seqmap seqmap file. "
42-
"Please use c10-train.txt, c10-test.txt or c10-all.txt")
41+
print(
42+
"No detector name found, this could happen with the "
43+
"wrong seqmap seqmap file. "
44+
"Please use c10-train.txt, c10-test.txt or c10-all.txt")
4345
exit()
4446

47+
# Take the pre-computed detections.
4548
det_path = args.benchmark_dir + "/" + seq + "/det/det.txt"
4649
out_path = args.res_dir + "/" + seq + ".txt"
4750

@@ -52,19 +55,24 @@ def main(args):
5255
end = time()
5356

5457
num_frames = len(detections)
55-
print("finished " + seq + " at " + str(int(num_frames / (end - start))) + " fps!")
58+
print("finished " + seq + " at " + str(
59+
int(num_frames / (end - start))) + " fps!")
5660

5761
save_to_csv(out_path, tracks)
5862

59-
if __name__ == '__main__':
6063

61-
parser = argparse.ArgumentParser(description="IOU Tracker MOT17 demo script. The best parameters for each detector "
62-
"are hardcoded.")
63-
parser.add_argument('-m', '--seqmap', type=str, required=True,
64+
if __name__ == '__main__':
65+
parser = argparse.ArgumentParser(
66+
description="IOU Tracker MOT17 demo script. The best parameters for "
67+
"each detector are hardcoded.")
68+
parser.add_argument('-m', '--seqmap', type=str,
69+
default="../motchallenge/seqmaps/c10-train-sample.txt",
6470
help="full path to the seqmap file to evaluate")
65-
parser.add_argument('-o', '--res_dir', type=str, required=True,
71+
parser.add_argument('-o', '--res_dir', type=str,
72+
default="../motchallenge/res/MOT17/iou-tracker",
6673
help="path to the results directory")
67-
parser.add_argument('-b', '--benchmark_dir', type=str, required=True,
74+
parser.add_argument('-b', '--benchmark_dir', type=str,
75+
default="../motchallenge/",
6876
help="path to the sequence directory")
6977

7078
args = parser.parse_args()

seqmaps/mot16-dpm-all.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name
2+
MOT16-01
3+
MOT16-02
4+
MOT16-03
5+
MOT16-04
6+
MOT16-05
7+
MOT16-06
8+
MOT16-07
9+
MOT16-08
10+
MOT16-09
11+
MOT16-10
12+
MOT16-11
13+
MOT16-12
14+
MOT16-13
15+
MOT16-14

seqmaps/mot16-dpm-test.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name
2+
MOT16-01
3+
MOT16-03
4+
MOT16-06
5+
MOT16-07
6+
MOT16-08
7+
MOT16-12
8+
MOT16-14

seqmaps/mot16-dpm-train.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name
2+
MOT16-02
3+
MOT16-04
4+
MOT16-05
5+
MOT16-09
6+
MOT16-10
7+
MOT16-11
8+
MOT16-13

util.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
def load_mot(detections):
1313
"""
14-
Loads detections stored in a mot-challenge like formatted CSV or numpy array (fieldNames = ['frame', 'id', 'x', 'y',
15-
'w', 'h', 'score']).
14+
Loads detections stored in a mot-challenge like formatted CSV or numpy array
15+
(fieldNames = ['frame', 'id', 'x', 'y', 'w', 'h', 'score', 'class',
16+
'visibility_ratio']).
1617
1718
Args:
1819
detections
@@ -26,18 +27,21 @@ def load_mot(detections):
2627
raw = np.genfromtxt(detections, delimiter=',', dtype=np.float32)
2728
else:
2829
# assume it is an array
29-
assert isinstance(detections, np.ndarray), "only numpy arrays or *.csv paths are supported as detections."
30+
assert isinstance(detections,
31+
np.ndarray), "only numpy arrays or *.csv paths are supported as detections."
3032
raw = detections.astype(np.float32)
3133

3234
end_frame = int(np.max(raw[:, 0]))
33-
for i in range(1, end_frame+1):
35+
for i in range(1, end_frame + 1):
3436
idx = raw[:, 0] == i
3537
bbox = raw[idx, 2:6]
3638
bbox[:, 2:4] += bbox[:, 0:2] # x1, y1, w, h -> x1, y1, x2, y2
3739
scores = raw[idx, 6]
40+
labels = raw[idx, 7] # extract column 7 for the indexes (idx) from raw
3841
dets = []
39-
for bb, s in zip(bbox, scores):
40-
dets.append({'bbox': (bb[0], bb[1], bb[2], bb[3]), 'score': s})
42+
for bb, s, label in zip(bbox, scores, labels):
43+
dets.append({'bbox': (bb[0], bb[1], bb[2], bb[3]), 'score': s,
44+
'label': label})
4145
data.append(dets)
4246

4347
return data
@@ -52,8 +56,9 @@ def save_to_csv(out_path, tracks):
5256
tracks (list): list of tracks to store.
5357
"""
5458

55-
with open(out_path, "w") as ofile:
56-
field_names = ['frame', 'id', 'x', 'y', 'w', 'h', 'score', 'wx', 'wy', 'wz']
59+
with open(out_path, "w", newline="") as ofile:
60+
field_names = ['frame', 'id', 'x', 'y', 'w', 'h', 'score', 'wx', 'wy',
61+
'wz']
5762

5863
odict = csv.DictWriter(ofile, field_names)
5964
id_ = 1

0 commit comments

Comments
 (0)