Skip to content

Commit

Permalink
Merge pull request #1854 from Fleyderer/master
Browse files Browse the repository at this point in the history
Added min confidence threshold to existing trackers
  • Loading branch information
mikel-brostrom authored Mar 11, 2025
2 parents 741202c + 4400881 commit 0c4aebe
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions boxmot/configs/bytetrack.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
min_thresh:
min_conf:
type: uniform
default: 0.2 # from the default parameters
default: 0.1 # from the default parameters
range: [0.1, 0.3]

track_thresh:
Expand Down
5 changes: 5 additions & 0 deletions boxmot/configs/ocsort.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
min_conf:
type: uniform
default: 0.1 # from the default parameters
range: [0.1, 0.3]

det_thresh:
type: uniform
default: 0.6 # from the default parameters
Expand Down
5 changes: 5 additions & 0 deletions boxmot/configs/strongsort.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
min_conf:
type: uniform
default: 0.6 # from the default parameters
range: [0.2, 0.8]

ema_alpha:
type: uniform
default: 0.9 # from the default parameters
Expand Down
8 changes: 4 additions & 4 deletions boxmot/trackers/bytetrack/bytetrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ByteTrack(BaseTracker):
BYTETracker: A tracking algorithm based on ByteTrack, which utilizes motion-based tracking.
Args:
min_thresh (float, optional): Threshold for detection confidence. Detections below this threshold are discarded.
min_conf (float, optional): Threshold for detection confidence. Detections below this threshold are discarded.
track_thresh (float, optional): Threshold for detection confidence. Detections above this threshold are considered for tracking in the first association round.
match_thresh (float, optional): Threshold for the matching step in data association. Controls the maximum distance allowed between tracklets and detections for a match.
track_buffer (int, optional): Number of frames to keep a track alive after it was last detected. A longer buffer allows for more robust tracking but may increase identity switches.
Expand All @@ -129,7 +129,7 @@ class ByteTrack(BaseTracker):
"""
def __init__(
self,
min_thresh: float = 0.1,
min_conf: float = 0.1,
track_thresh: float = 0.45,
match_thresh: float = 0.8,
track_buffer: int = 25,
Expand All @@ -145,7 +145,7 @@ def __init__(
self.track_buffer = track_buffer

self.per_class = per_class
self.min_thresh = min_thresh
self.min_conf = min_conf
self.track_thresh = track_thresh
self.match_thresh = match_thresh
self.det_thresh = track_thresh
Expand All @@ -169,7 +169,7 @@ def update(self, dets: np.ndarray, img: np.ndarray = None, embs: np.ndarray = No

remain_inds = confs > self.track_thresh

inds_low = confs > 0.1
inds_low = confs > self.min_conf
inds_high = confs < self.track_thresh
inds_second = np.logical_and(inds_low, inds_high)

Expand Down
2 changes: 1 addition & 1 deletion boxmot/trackers/deepocsort/deepocsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) ->
if self.embedding_off or dets.shape[0] == 0:
dets_embs = np.ones((dets.shape[0], 1))
elif embs is not None:
dets_embs = embs
dets_embs = embs[remain_inds]
else:
# (Ndets x X) [512, 1024, 2048]
dets_embs = self.model.get_features(dets[:, 0:4], img)
Expand Down
4 changes: 3 additions & 1 deletion boxmot/trackers/ocsort/ocsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class OcSort(BaseTracker):
def __init__(
self,
per_class: bool = False,
min_conf: float = 0.1,
det_thresh: float = 0.2,
max_age: int = 30,
min_hits: int = 3,
Expand All @@ -219,6 +220,7 @@ def __init__(
Sets key parameters for SORT
"""
self.per_class = per_class
self.min_conf = min_conf
self.max_age = max_age
self.min_hits = min_hits
self.asso_threshold = asso_threshold
Expand Down Expand Up @@ -251,7 +253,7 @@ def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) ->
dets = np.hstack([dets, np.arange(len(dets)).reshape(-1, 1)])
confs = dets[:, 4+self.is_obb]

inds_low = confs > 0.1
inds_low = confs > self.min_conf
inds_high = confs < self.det_thresh
inds_second = np.logical_and(
inds_low, inds_high
Expand Down
7 changes: 6 additions & 1 deletion boxmot/trackers/strongsort/strongsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(
device: device,
half: bool,
per_class: bool = False,
min_conf: float = 0.1,
max_cos_dist=0.2,
max_iou_dist=0.7,
max_age=30,
Expand All @@ -46,6 +47,7 @@ def __init__(
):

self.per_class = per_class
self.min_conf = min_conf
self.model = ReidAutoBackend(
weights=reid_weights, device=device, half=half
).model
Expand Down Expand Up @@ -76,6 +78,9 @@ def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) ->
), "Unsupported 'dets' 2nd dimension lenght, valid lenghts is 6"

dets = np.hstack([dets, np.arange(len(dets)).reshape(-1, 1)])
remain_inds = dets[:, 4] >= self.min_conf
dets = dets[remain_inds]

xyxy = dets[:, 0:4]
confs = dets[:, 4]
clss = dets[:, 5]
Expand All @@ -88,7 +93,7 @@ def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) ->

# extract appearance information for each detection
if embs is not None:
features = embs
features = embs[remain_inds]
else:
features = self.model.get_features(xyxy, img)

Expand Down

0 comments on commit 0c4aebe

Please sign in to comment.