Skip to content

Commit

Permalink
Merge pull request #1642 from roboflow/fix/tracker-regression-all-obj…
Browse files Browse the repository at this point in the history
…ects-connected

Fix regression where all uninitialized tracks are connected
  • Loading branch information
LinasKo authored Nov 1, 2024
2 parents 2704a24 + 4678dfc commit 589d4f9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions supervision/tracker/byte_tracker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@


class IdCounter:
def __init__(self):
def __init__(self, start_id: int = 0):
self.start_id = start_id
if self.start_id <= self.NO_ID:
raise ValueError("start_id must be greater than -1")
self.reset()

def reset(self) -> None:
self._id = self.NO_ID
self._id = self.start_id

def new_id(self) -> int:
returned_id = self._id
self._id += 1
return self._id
return returned_id

@property
def NO_ID(self) -> int:
return 0
return -1


class STrack(BaseTrack):
Expand Down Expand Up @@ -231,8 +235,10 @@ def __init__(
self.lost_tracks: List[STrack] = []
self.removed_tracks: List[STrack] = []

# Warning, possible bug: If you also set internal_id to start at 1,
# all traces will be connected across objects.
self.internal_id_counter = IdCounter()
self.external_id_counter = IdCounter()
self.external_id_counter = IdCounter(start_id=1)

def update_with_detections(self, detections: Detections) -> Detections:
"""
Expand Down

0 comments on commit 589d4f9

Please sign in to comment.