Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mikel-brostrom/boxmot
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikel Broström committed Aug 13, 2024
2 parents 1cd7a77 + c23fe91 commit 2e0eb24
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 46 deletions.
14 changes: 14 additions & 0 deletions boxmot/trackers/basetracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) ->
"""
raise NotImplementedError("The update method needs to be implemented by the subclass.")

def check_inputs(self, dets, img):
assert isinstance(
dets, np.ndarray
), f"Unsupported 'dets' input format '{type(dets)}', valid format is np.ndarray"
assert isinstance(
img, np.ndarray
), f"Unsupported 'img_numpy' input format '{type(img)}', valid format is np.ndarray"
assert (
len(dets.shape) == 2
), "Unsupported 'dets' dimensions, valid number of dimensions is two"
assert (
dets.shape[1] == 6
), "Unsupported 'dets' 2nd dimension lenght, valid lenghts is 6"

def id_to_color(self, id: int, saturation: float = 0.75, value: float = 0.95) -> tuple:
"""
Generates a consistent unique BGR color for a given ID using hashing.
Expand Down
14 changes: 2 additions & 12 deletions boxmot/trackers/botsort/bot_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,8 @@ def __init__(

@PerClassDecorator
def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) -> np.ndarray:
assert isinstance(
dets, np.ndarray
), f"Unsupported 'dets' input format '{type(dets)}', valid format is np.ndarray"
assert isinstance(
img, np.ndarray
), f"Unsupported 'img_numpy' input format '{type(img)}', valid format is np.ndarray"
assert (
len(dets.shape) == 2
), "Unsupported 'dets' dimensions, valid number of dimensions is two"
assert (
dets.shape[1] == 6
), "Unsupported 'dets' 2nd dimension lenght, valid lenghts is 6"

self.check_inputs(dets, img)

self.frame_count += 1
activated_starcks = []
Expand Down
11 changes: 2 additions & 9 deletions boxmot/trackers/bytetrack/byte_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,8 @@ def __init__(

@PerClassDecorator
def update(self, dets: np.ndarray, img: np.ndarray = None, embs: np.ndarray = None) -> np.ndarray:
assert isinstance(
dets, np.ndarray
), f"Unsupported 'dets' input format '{type(dets)}', valid format is np.ndarray"
assert (
len(dets.shape) == 2
), "Unsupported 'dets' dimensions, valid number of dimensions is two"
assert (
dets.shape[1] == 6
), "Unsupported 'dets' 2nd dimension lenght, valid lenghts is 6"

self.check_inputs(dets, img)

dets = np.hstack([dets, np.arange(len(dets)).reshape(-1, 1)])
self.frame_count += 1
Expand Down
5 changes: 1 addition & 4 deletions boxmot/trackers/deepocsort/deep_ocsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,7 @@ def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) ->
"""
#dets, s, c = dets.data
#print(dets, s, c)
assert isinstance(dets, np.ndarray), f"Unsupported 'dets' input type '{type(dets)}', valid format is np.ndarray"
assert isinstance(img, np.ndarray), f"Unsupported 'img' input type '{type(img)}', valid format is np.ndarray"
assert len(dets.shape) == 2, "Unsupported 'dets' dimensions, valid number of dimensions is two"
assert dets.shape[1] == 6, "Unsupported 'dets' 2nd dimension lenght, valid lenghts is 6"
self.check_inputs(dets, img)

self.frame_count += 1
self.height, self.width = img.shape[:2]
Expand Down
3 changes: 3 additions & 0 deletions boxmot/trackers/hybridsort/hybridsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) ->
Returns the a similar array, where the last column is the object ID.
NOTE: The number of objects returned may differ from the number of detections provided.
"""

self.check_inputs(dets, img)

if dets is None:
return np.empty((0, 7))

Expand Down
13 changes: 1 addition & 12 deletions boxmot/trackers/imprassoc/impr_assoc_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,7 @@ def __init__(

@PerClassDecorator
def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) -> np.ndarray:
assert isinstance(
dets, np.ndarray
), f"Unsupported 'dets' input format '{type(dets)}', valid format is np.ndarray"
assert isinstance(
img, np.ndarray
), f"Unsupported 'img_numpy' input format '{type(img)}', valid format is np.ndarray"
assert (
len(dets.shape) == 2
), "Unsupported 'dets' dimensions, valid number of dimensions is two"
assert (
dets.shape[1] == 6
), "Unsupported 'dets' 2nd dimension lenght, valid lenghts is 6"
self.check_inputs(dets, img)

self.frame_count += 1
activated_starcks = []
Expand Down
10 changes: 1 addition & 9 deletions boxmot/trackers/ocsort/ocsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,7 @@ def update(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None) ->
NOTE: The number of objects returned may differ from the number of detections provided.
"""

assert isinstance(
dets, np.ndarray
), f"Unsupported 'dets' input format '{type(dets)}', valid format is np.ndarray"
assert (
len(dets.shape) == 2
), "Unsupported 'dets' dimensions, valid number of dimensions is two"
assert (
dets.shape[1] == 6
), "Unsupported 'dets' 2nd dimension lenght, valid lenghts is 6"
self.check_inputs(dets, img)

self.frame_count += 1
h, w = img.shape[0:2]
Expand Down

0 comments on commit 2e0eb24

Please sign in to comment.