Skip to content

Commit

Permalink
Merge pull request #1682 from mikel-brostrom/handle-none-empty-input
Browse files Browse the repository at this point in the history
handle None and empty np inputs
  • Loading branch information
mikel-brostrom authored Sep 30, 2024
2 parents 20d8957 + d8cb9ee commit dc3ff39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions boxmot/trackers/basetracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def per_class_decorator(update_method):
Decorator for the update method to handle per-class processing.
"""
def wrapper(self, dets: np.ndarray, img: np.ndarray, embs: np.ndarray = None):

#handle different types of inputs
if dets is None or len(dets) == 0:
dets = np.empty((0, 6))

if self.per_class:
# Initialize an array to store the tracks for each class
per_class_tracks = []
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,22 @@ def test_per_class_tracker_active_tracks(tracker_type):
assert tracker.per_class_active_tracks[0], "No active tracks for class 0"
assert tracker.per_class_active_tracks[65], "No active tracks for class 65"


@pytest.mark.parametrize("tracker_type", ALL_TRACKERS)
@pytest.mark.parametrize("dets", [None, np.array([])])
def test_tracker_with_no_detections(tracker_type, dets):
tracker_conf = get_tracker_config(tracker_type)
tracker = create_tracker(
tracker_type=tracker_type,
tracker_config=tracker_conf,
reid_weights=WEIGHTS / 'mobilenetv2_x1_4_dukemtmcreid.pt',
device='cpu',
half=False,
per_class=False
)

rgb = np.random.randint(255, size=(640, 640, 3), dtype=np.uint8)
embs = np.random.random(size=(2, 512))

output = tracker.update(dets, rgb, embs)
assert output.size == 0, "Output should be empty when no detections are provided"

0 comments on commit dc3ff39

Please sign in to comment.