Skip to content

Commit

Permalink
Merge pull request #1090 from mikel-brostrom/botsort-index-bug-fix
Browse files Browse the repository at this point in the history
fix #1083
  • Loading branch information
mikel-brostrom authored Aug 23, 2023
2 parents c5c73eb + 46d1e77 commit c34e4f7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion boxmot/configs/botsort.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ appearance_thresh: 0.4818211117541298
cmc_method: sparseOptFlow
conf_thres: 0.3501265956918775
frame_rate: 30
lambda_: 0.9896143462366406
match_thresh: 0.22734550911325851
new_track_thresh: 0.21144301345190655
proximity_thresh: 0.5945380911899254
track_buffer: 60
track_high_thresh: 0.33824964456239337
track_low_thresh: 0.1
2 changes: 1 addition & 1 deletion boxmot/tracker_zoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ def create_tracker(tracker_type, tracker_config, reid_weights, device, half, per
device,
half,
track_high_thresh=cfg.track_high_thresh,
track_low_thresh=cfg.track_low_thresh,
new_track_thresh=cfg.new_track_thresh,
track_buffer=cfg.track_buffer,
match_thresh=cfg.match_thresh,
proximity_thresh=cfg.proximity_thresh,
appearance_thresh=cfg.appearance_thresh,
cmc_method=cfg.cmc_method,
frame_rate=cfg.frame_rate,
lambda_=cfg.lambda_
)
return botsort
elif tracker_type == 'deepocsort':
Expand Down
36 changes: 17 additions & 19 deletions boxmot/trackers/botsort/bot_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ def __init__(
model_weights,
device,
fp16,
track_high_thresh: float = 0.45,
track_high_thresh: float = 0.5,
track_low_thresh: float = 0.1,
new_track_thresh: float = 0.6,
track_buffer: int = 30,
match_thresh: float = 0.8,
proximity_thresh: float = 0.5,
appearance_thresh: float = 0.25,
cmc_method: str = "sparseOptFlow",
frame_rate=30,
lambda_=0.985,
):
self.tracked_stracks = [] # type: list[STrack]
self.lost_stracks = [] # type: list[STrack]
Expand All @@ -204,9 +204,10 @@ def __init__(

self.frame_id = 0

self.lambda_ = lambda_
self.track_high_thresh = track_high_thresh
self.track_low_thresh = track_low_thresh
self.new_track_thresh = new_track_thresh
self.match_thresh = match_thresh

self.buffer_size = int(frame_rate / 30.0 * track_buffer)
self.max_time_lost = self.buffer_size
Expand All @@ -215,7 +216,6 @@ def __init__(
# ReID module
self.proximity_thresh = proximity_thresh
self.appearance_thresh = appearance_thresh
self.match_thresh = match_thresh

self.model = ReIDDetectMultiBackend(
weights=model_weights, device=device, fp16=fp16
Expand All @@ -237,33 +237,31 @@ def update(self, dets, img):
dets.shape[1] == 6
), "Unsupported 'dets' 2nd dimension lenght, valid lenghts is 6"

dets = np.hstack([dets, np.arange(len(dets)).reshape(-1, 1)])
self.frame_id += 1
activated_starcks = []
refind_stracks = []
lost_stracks = []
removed_stracks = []

xyxys = dets[:, 0:4]
confs = dets[:, 4]

remain_inds = confs > self.track_high_thresh
inds_low = confs > 0.1
inds_high = confs < self.track_high_thresh
dets = np.hstack([dets, np.arange(len(dets)).reshape(-1, 1)])

inds_second = np.logical_and(inds_low, inds_high)
# Remove bad detections
confs = dets[:, 4]

dets = dets[remain_inds]
dets_second = dets[inds_second]
# find second round association detections
second_mask = np.logical_or(confs > self.track_low_thresh, confs < self.track_high_thresh)
dets_second = dets[second_mask]

self.height, self.width = img.shape[:2]
# find first round association detections
first_mask = confs > self.track_high_thresh
dets_first = dets[first_mask]

"""Extract embeddings """
features_keep = self.model.get_features(xyxys[remain_inds], img)
features_high = self.model.get_features(dets_first[:, 0:4], img)

if len(dets) > 0:
"""Detections"""
detections = [STrack(det, f) for (det, f) in zip(dets, features_keep)]
detections = [STrack(det, f) for (det, f) in zip(dets_first, features_high)]
else:
detections = []

Expand All @@ -283,7 +281,7 @@ def update(self, dets, img):
STrack.multi_predict(strack_pool)

# Fix camera motion
warp = self.cmc.apply(img, dets)
warp = self.cmc.apply(img, dets_first)
STrack.multi_gmc(strack_pool, warp)
STrack.multi_gmc(unconfirmed, warp)

Expand Down Expand Up @@ -313,7 +311,7 @@ def update(self, dets, img):
""" Step 3: Second association, with low score detection boxes"""
if len(dets_second) > 0:
"""Detections"""
detections_second = [STrack(det_second) for det_second in dets_second]
detections_second = [STrack(dets_second) for dets_second in dets_second]
else:
detections_second = []

Expand Down

0 comments on commit c34e4f7

Please sign in to comment.