Skip to content

fix: Isolate BYTETracker IDs per instance and bound removed tracks - #170

Merged
yakhyo merged 5 commits into
yakhyo:mainfrom
M-Colley:fix/bytetrack-isolation-and-leak
Nov 28, 2026
Merged

yakhyo merged 5 commits into
yakhyo:mainfrom
M-Colley:fix/bytetrack-isolation-and-leak

Conversation

@M-Colley

Copy link
Copy Markdown
Contributor

Summary

Fixes multi-tracker ID collisions, unbounded memory/CPU growth, and CLI tracking bugs in ByteTrack:

  • Per-instance BYTETracker IDs (uniface/tracking/bytetrack/tracker.py): Track IDs are now allocated per BYTETracker instance (self._next_id) rather than resetting global BaseTrack._count inside reset(). Previously, calling reset() on one BYTETracker caused concurrent trackers to reuse active IDs and silently drop new face tracks during _joint_stracks deduplication. (BaseTrack.next_id() remains intact for standalone STrack callers.)
  • Instance-scoped BaseTrack containers (uniface/tracking/bytetrack/basetrack.py): Move history and features from shared mutable class attributes into BaseTrack.__init__.
  • Bounded removed_stracks (uniface/tracking/bytetrack/tracker.py): Subtract only the current frame's removed_stracks from self.lost_stracks and cap self.removed_stracks to 1,000 entries, fixing unbounded memory growth and O(total_historical_tracks) per-frame overhead on long streams.
  • Vectorized KalmanFilter.multi_predict (uniface/tracking/bytetrack/kalman.py): Replace the per-track np.diag Python loop with vectorized diagonal indexing and batched matrix multiplication.
  • CLI tracking (tools/track.py): Forward low-confidence detections (> tracker.low_thresh) so ByteTrack's second-stage association runs as intended, and match tracks 1-to-1 to detected Face objects by IoU so occluded tracks cannot overwrite another face's track_id.

Testing

  • Added tests/test_tracking.py covering two-stage association, multi-instance reset isolation, instance-scoped containers, bounded removed_stracks, Kalman batch parity, and 1-to-1 CLI track assignment.

@yakhyo

yakhyo commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Hi @M-Colley! Thanks for the fix! I pushed a few small changes to keep it closer to the original ByteTrack code and dropped the parts outside the two fixes.

@yakhyo
yakhyo merged commit 0cf5fe6 into yakhyo:main Nov 28, 2026
8 checks passed
@yakhyo

yakhyo commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants