Add object detection, tracking, mobile notifications, and search to any security camera.
fix tracker test
roryclear80ca861fa3a3
diff --git a/test/test.py b/test/test.pyindex 6a8d547..2ad411d 100644--- a/test/test.py+++ b/test/test.py@@ -46,6 +46,7 @@ def test_yolo_infer():import picklefrom yolox.tracker.byte_tracker import BYTETracker+from yolox.tracker.byte_tracker2 import BYTETracker2def test_bytetracker():class Args:@@ -54,57 +55,29 @@ def test_bytetracker():self.mot20 = Falseself.match_thresh = 0.9tracker = BYTETracker(Args())+ tracker2 = BYTETracker2(Args())inputs = pickle.load(open("test/tracker_inputs.pkl", "rb"))- outputs = pickle.load(open("test/tracker_outputs.pkl", "rb"))total_time = 0total_time2 = 0for i in range(len(inputs)):st = time.perf_counter()output = tracker.update(inputs[i], [1280,1280], [1280,1280], threshold=0.5)+ output2 = tracker2.update(inputs[i], [1280,1280], [1280,1280], threshold=0.5)total_time += (time.perf_counter() - st)st = time.perf_counter()total_time2 += (time.perf_counter() - st)- assert len(outputs[i]) == len(output)+ assert len(output2) == len(output)for j in range(len(output)):- np.testing.assert_allclose(output[j]._tlwh, outputs[i][j]._tlwh)- np.testing.assert_allclose(output[j].score, outputs[i][j].score)- np.testing.assert_allclose(output[j].is_activated, outputs[i][j].is_activated)- np.testing.assert_allclose(output[j].mean, outputs[i][j].mean)- np.testing.assert_allclose(output[j].covariance, outputs[i][j].covariance)- np.testing.assert_allclose(output[j].class_id, outputs[i][j].class_id)+ np.testing.assert_allclose(output[j]._tlwh, output2[j]._tlwh)+ np.testing.assert_allclose(output[j].score, output2[j].score)+ np.testing.assert_allclose(output[j].is_activated, output2[j].is_activated)+ np.testing.assert_allclose(output[j].mean, output2[j].mean)+ np.testing.assert_allclose(output[j].covariance, output2[j].covariance)+ np.testing.assert_allclose(output[j].class_id, output2[j].class_id)assert total_time2 < (total_time * 1.1), "too slow"--def setup_test_bytetracker():- depth, width, ratio = get_variant_multiples("s")- yolo_infer = YOLOv8(w=width, r=ratio, d=depth, num_classes=80)- state_dict = safe_load(get_weights_location("s"))- load_state_dict(yolo_infer, state_dict)-- class Args:- def __init__(self):- self.track_buffer = 60- self.mot20 = False- self.match_thresh = 0.9-- inputs = []- outputs = []-- tracker = BYTETracker(Args())- cap = cv2.VideoCapture("test/MOT16-03.mp4")- for _ in range(1500):- _, frame = cap.read()- frame = Tensor(frame)- preds = do_inf(frame, yolo_infer).numpy()- inputs.append(preds)- preds = tracker.update(preds, [1280,1280], [1280,1280], threshold=0.5)- outputs.append(preds)- pickle.dump(inputs, open("test/tracker_inputs.pkl", "wb"))- pickle.dump(outputs, open("test/tracker_outputs.pkl", "wb"))--setup_test_bytetracker()test_bytetracker()#test_yolo_infer()#test_linear_sum_assigment()diff --git a/test/tracker_inputs.pkl b/test/tracker_inputs.pklindex 84f230f..0357dbb 100644Binary files a/test/tracker_inputs.pkl and b/test/tracker_inputs.pkl differdiff --git a/test/tracker_outputs.pkl b/test/tracker_outputs.pkldeleted file mode 100644index a0226f4..0000000Binary files a/test/tracker_outputs.pkl and /dev/null differdiff --git a/yolox/tracker/byte_tracker2.py b/yolox/tracker/byte_tracker2.pyindex d3912c5..93cef52 100644--- a/yolox/tracker/byte_tracker2.py+++ b/yolox/tracker/byte_tracker2.py@@ -173,19 +173,19 @@ class BYTETracker2(object):inds_second = np.logical_and(inds_low, inds_high)dets_second = bboxes[inds_second]- dets_keep = bboxes[remain_inds]+ dets = bboxes[remain_inds]scores_keep = scores[remain_inds]scores_second = scores[inds_second]classes_keep = classes[remain_inds]classes_second = classes[inds_second]- if len(dets_keep) > 0:+ if len(dets) > 0:'''Detections'''detections = [STrack(STrack.tlbr_to_tlwh(tlbr), s, c) for- (tlbr, s, c) in zip(dets_keep, scores_keep, classes_keep)]+ (tlbr, s, c) in zip(dets, scores_keep, classes_keep)]else:detections = []-+''' Add newly detected tracklets to tracked_stracks'''unconfirmed = []tracked_stracks = [] # type: list[STrack]@@ -200,7 +200,8 @@ class BYTETracker2(object):# Predict the current location with KFSTrack.multi_predict(strack_pool)dists = matching.iou_distance(strack_pool, detections)- dists = matching.fuse_score(dists, detections)+ if not self.args.mot20:+ dists = matching.fuse_score(dists, detections)matches, u_track, u_detection = matching.linear_assignment(dists, thresh=self.args.match_thresh)for itracked, idet in matches:@@ -243,7 +244,8 @@ class BYTETracker2(object):'''Deal with unconfirmed tracks, usually tracks with only one beginning frame'''detections = [detections[i] for i in u_detection]dists = matching.iou_distance(unconfirmed, detections)- dists = matching.fuse_score(dists, detections)+ if not self.args.mot20:+ dists = matching.fuse_score(dists, detections)matches, u_unconfirmed, u_detection = matching.linear_assignment(dists, thresh=0.7)for itracked, idet in matches:unconfirmed[itracked].update(detections[idet], self.frame_id)