Skip to content

Commit a8680a7

Browse files
committed
speed up 350x parsing file
1 parent 83f6277 commit a8680a7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

util.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@ def load_mot(detections):
2828
# assume it is an array
2929
assert isinstance(detections, np.ndarray), "only numpy arrays or *.csv paths are supported as detections."
3030
raw = detections.astype(np.float32)
31+
raw[:, 4:6] += raw[:, 2:4]
32+
sort_idx = np.argsort(raw[:, 0])
33+
raw = raw[sort_idx, :]
34+
frames = np.split(raw, np.where(np.diff(raw[:, 0]))[0]+1, axis=0)
3135

3236
end_frame = int(np.max(raw[:, 0]))
37+
ptr = 0
3338
for i in range(1, end_frame+1):
34-
idx = raw[:, 0] == i
35-
bbox = raw[idx, 2:6]
36-
bbox[:, 2:4] += bbox[:, 0:2] # x1, y1, w, h -> x1, y1, x2, y2
37-
scores = raw[idx, 6]
3839
dets = []
39-
for bb, s in zip(bbox, scores):
40-
dets.append({'bbox': (bb[0], bb[1], bb[2], bb[3]), 'score': s})
40+
if ptr < len(frames) and frames[ptr][0, 0] == i:
41+
bbox = frames[ptr][:, 2:6]
42+
scores = frames[ptr][:, 6]
43+
for bb, s in zip(bbox, scores):
44+
dets.append({'bbox': (bb[0], bb[1], bb[2], bb[3]), 'score': s})
45+
ptr += 1
4146
data.append(dets)
4247

4348
return data

0 commit comments

Comments
 (0)