From 175df60eaeb0ade1baae81db06f23e22b9620165 Mon Sep 17 00:00:00 2001 From: Abay Bektursun Date: Thu, 22 Dec 2022 20:28:36 -0600 Subject: [PATCH 1/5] store det_idx --- yolox/tracker/byte_tracker.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/yolox/tracker/byte_tracker.py b/yolox/tracker/byte_tracker.py index 2d004599..29dac803 100644 --- a/yolox/tracker/byte_tracker.py +++ b/yolox/tracker/byte_tracker.py @@ -12,7 +12,7 @@ class STrack(BaseTrack): shared_kalman = KalmanFilter() - def __init__(self, tlwh, score): + def __init__(self, tlwh, score, det_idx=0): # wait activate self._tlwh = np.asarray(tlwh, dtype=np.float) @@ -23,6 +23,8 @@ def __init__(self, tlwh, score): self.score = score self.tracklet_len = 0 + self.det_idx = det_idx + def predict(self): mean_state = self.mean.copy() if self.state != TrackState.Tracked: @@ -156,7 +158,7 @@ def __init__(self, args, frame_rate=30): self.max_time_lost = self.buffer_size self.kalman_filter = KalmanFilter() - def update(self, output_results, img_info, img_size): + def update(self, output_results, img_info, img_size, det_idxs=None): self.frame_id += 1 activated_starcks = [] refind_stracks = [] @@ -166,6 +168,10 @@ def update(self, output_results, img_info, img_size): if output_results.shape[1] == 5: scores = output_results[:, 4] bboxes = output_results[:, :4] + elif output_results.shape[1] == 6: + scores = output_results[:, 4] + bboxes = output_results[:, :4] # x1y1x2y2 + det_idxs = output_results[:, 5] else: output_results = output_results.cpu().numpy() scores = output_results[:, 4] * output_results[:, 5] @@ -183,11 +189,14 @@ def update(self, output_results, img_info, img_size): dets = bboxes[remain_inds] scores_keep = scores[remain_inds] scores_second = scores[inds_second] + det_idxs = det_idxs[remain_inds] + det_idxs_second = det_idxs[inds_second] if len(dets) > 0: '''Detections''' - detections = [STrack(STrack.tlbr_to_tlwh(tlbr), s) for - (tlbr, s) in zip(dets, scores_keep)] + detections = [] + for (tlbr, s, di) in zip(dets, scores_keep, det_idxs): + detections.append(STrack(STrack.tlbr_to_tlwh(tlbr), s, di)) else: detections = [] @@ -223,8 +232,8 @@ def update(self, output_results, img_info, img_size): # association the untrack to the low score detections if len(dets_second) > 0: '''Detections''' - detections_second = [STrack(STrack.tlbr_to_tlwh(tlbr), s) for - (tlbr, s) in zip(dets_second, scores_second)] + detections_second = [STrack(STrack.tlbr_to_tlwh(tlbr), s, di) for + (tlbr, s, di) in zip(dets_second, scores_second, det_idxs_second)] else: detections_second = [] r_tracked_stracks = [strack_pool[i] for i in u_track if strack_pool[i].state == TrackState.Tracked] From 453a61d51fbd726c4041d9c0a33e8c8341ca2bcc Mon Sep 17 00:00:00 2001 From: Abay Bektursun Date: Fri, 23 Dec 2022 01:15:22 -0600 Subject: [PATCH 2/5] sync --- yolox/tracker/byte_tracker.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yolox/tracker/byte_tracker.py b/yolox/tracker/byte_tracker.py index 29dac803..50c138c3 100644 --- a/yolox/tracker/byte_tracker.py +++ b/yolox/tracker/byte_tracker.py @@ -158,7 +158,7 @@ def __init__(self, args, frame_rate=30): self.max_time_lost = self.buffer_size self.kalman_filter = KalmanFilter() - def update(self, output_results, img_info, img_size, det_idxs=None): + def update(self, output_results, img_info, img_size): self.frame_id += 1 activated_starcks = [] refind_stracks = [] @@ -171,7 +171,7 @@ def update(self, output_results, img_info, img_size, det_idxs=None): elif output_results.shape[1] == 6: scores = output_results[:, 4] bboxes = output_results[:, :4] # x1y1x2y2 - det_idxs = output_results[:, 5] + _det_idxs = output_results[:, 5] else: output_results = output_results.cpu().numpy() scores = output_results[:, 4] * output_results[:, 5] @@ -189,8 +189,8 @@ def update(self, output_results, img_info, img_size, det_idxs=None): dets = bboxes[remain_inds] scores_keep = scores[remain_inds] scores_second = scores[inds_second] - det_idxs = det_idxs[remain_inds] - det_idxs_second = det_idxs[inds_second] + det_idxs = _det_idxs[remain_inds] + det_idxs_second = _det_idxs[inds_second] if len(dets) > 0: '''Detections''' From ea5d4cf9ede5dfbd92022e365fedb091ab2754fc Mon Sep 17 00:00:00 2001 From: Abay Bektursun Date: Sat, 24 Dec 2022 16:48:55 -0600 Subject: [PATCH 3/5] bug fix --- yolox/tracker/byte_tracker.py | 47 +++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/yolox/tracker/byte_tracker.py b/yolox/tracker/byte_tracker.py index 50c138c3..5a15f91f 100644 --- a/yolox/tracker/byte_tracker.py +++ b/yolox/tracker/byte_tracker.py @@ -69,7 +69,9 @@ def re_activate(self, new_track, frame_id, new_id=False): if new_id: self.track_id = self.next_id() self.score = new_track.score - + # TODO: handle det_idx does not exist + self.det_idx = new_track.det_idx + def update(self, new_track, frame_id): """ Update a matched track @@ -89,6 +91,9 @@ def update(self, new_track, frame_id): self.score = new_track.score + # TODO: handle det_idx does not exist + self.det_idx = new_track.det_idx + @property # @jit(nopython=True) def tlwh(self): @@ -158,21 +163,25 @@ def __init__(self, args, frame_rate=30): self.max_time_lost = self.buffer_size self.kalman_filter = KalmanFilter() - def update(self, output_results, img_info, img_size): + def update(self, output_results, img_info, img_size, track_det_idx=False): self.frame_id += 1 activated_starcks = [] refind_stracks = [] lost_stracks = [] removed_stracks = [] + + if track_det_idx: + if output_results.shape[1] == 6: + scores = output_results[:, 4] + bboxes = output_results[:, :4] # x1y1x2y2 + _det_idxs = output_results[:, 5] + else: + raise ValueError('output_results shape error') if output_results.shape[1] == 5: scores = output_results[:, 4] bboxes = output_results[:, :4] - elif output_results.shape[1] == 6: - scores = output_results[:, 4] - bboxes = output_results[:, :4] # x1y1x2y2 - _det_idxs = output_results[:, 5] - else: + elif not track_det_idx: output_results = output_results.cpu().numpy() scores = output_results[:, 4] * output_results[:, 5] bboxes = output_results[:, :4] # x1y1x2y2 @@ -189,14 +198,19 @@ def update(self, output_results, img_info, img_size): dets = bboxes[remain_inds] scores_keep = scores[remain_inds] scores_second = scores[inds_second] - det_idxs = _det_idxs[remain_inds] - det_idxs_second = _det_idxs[inds_second] + if track_det_idx: + det_idxs = _det_idxs[remain_inds] + det_idxs_second = _det_idxs[inds_second] if len(dets) > 0: '''Detections''' detections = [] - for (tlbr, s, di) in zip(dets, scores_keep, det_idxs): - detections.append(STrack(STrack.tlbr_to_tlwh(tlbr), s, di)) + for i, (tlbr, s) in enumerate(zip(dets, scores_keep)): + di = det_idxs[i] + if track_det_idx: + detections.append(STrack(STrack.tlbr_to_tlwh(tlbr), s, di)) + else: + detections.append(STrack(STrack.tlbr_to_tlwh(tlbr), s)) else: detections = [] @@ -232,8 +246,15 @@ def update(self, output_results, img_info, img_size): # association the untrack to the low score detections if len(dets_second) > 0: '''Detections''' - detections_second = [STrack(STrack.tlbr_to_tlwh(tlbr), s, di) for - (tlbr, s, di) in zip(dets_second, scores_second, det_idxs_second)] + #detections_second = [STrack(STrack.tlbr_to_tlwh(tlbr), s, di) for + # (tlbr, s, di) in zip(dets_second, scores_second, det_idxs_second)] + detections_second = [] + for i, (tlbr, s) in enumerate(zip(dets_second, scores_second)): + if track_det_idx: + di = det_idxs_second[i] + detections_second.append(STrack(STrack.tlbr_to_tlwh(tlbr), s, di)) + else: + detections_second.append(STrack(STrack.tlbr_to_tlwh(tlbr), s)) else: detections_second = [] r_tracked_stracks = [strack_pool[i] for i in u_track if strack_pool[i].state == TrackState.Tracked] From fe0a3e2957aa5331006589d191f55a308e10c6a2 Mon Sep 17 00:00:00 2001 From: Abay Bektursun Date: Sat, 24 Dec 2022 16:59:45 -0600 Subject: [PATCH 4/5] doc --- yolox/tracker/byte_tracker.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/yolox/tracker/byte_tracker.py b/yolox/tracker/byte_tracker.py index 5a15f91f..fda1aef9 100644 --- a/yolox/tracker/byte_tracker.py +++ b/yolox/tracker/byte_tracker.py @@ -12,7 +12,14 @@ class STrack(BaseTrack): shared_kalman = KalmanFilter() - def __init__(self, tlwh, score, det_idx=0): + def __init__(self, tlwh, score, det_idx=None): + """ + Initialize a tracklet + Args: + tlwh: (np.ndarray) bbox in format x1,y1,x2,y2 + score: (float) bbox detection score + det_idx: (int) (Optional) corresponding index in object detection list + """ # wait activate self._tlwh = np.asarray(tlwh, dtype=np.float) @@ -69,7 +76,6 @@ def re_activate(self, new_track, frame_id, new_id=False): if new_id: self.track_id = self.next_id() self.score = new_track.score - # TODO: handle det_idx does not exist self.det_idx = new_track.det_idx def update(self, new_track, frame_id): @@ -91,7 +97,6 @@ def update(self, new_track, frame_id): self.score = new_track.score - # TODO: handle det_idx does not exist self.det_idx = new_track.det_idx @property @@ -164,6 +169,14 @@ def __init__(self, args, frame_rate=30): self.kalman_filter = KalmanFilter() def update(self, output_results, img_info, img_size, track_det_idx=False): + """ + Update tracker with detection results + Args: + output_results: detection results + Scores + det_idx (optional) + img_info: original image information + img_size: scaled image size + track_det_idx: whether to track det_idx (index corresponding to the detection results) + """ self.frame_id += 1 activated_starcks = [] refind_stracks = [] From a331008687b2aa372036d5da5156f8e8cd001ba0 Mon Sep 17 00:00:00 2001 From: Abay Bektursun Date: Sat, 24 Dec 2022 17:17:01 -0600 Subject: [PATCH 5/5] clearer name --- yolox/tracker/byte_tracker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yolox/tracker/byte_tracker.py b/yolox/tracker/byte_tracker.py index fda1aef9..8bac2846 100644 --- a/yolox/tracker/byte_tracker.py +++ b/yolox/tracker/byte_tracker.py @@ -174,7 +174,7 @@ def update(self, output_results, img_info, img_size, track_det_idx=False): Args: output_results: detection results + Scores + det_idx (optional) img_info: original image information - img_size: scaled image size + img_size: inference scaled image size track_det_idx: whether to track det_idx (index corresponding to the detection results) """ self.frame_id += 1