-
Notifications
You must be signed in to change notification settings - Fork 249
Fix: Prevent in-place mutation of Detections input in ByteTrack #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a side-effect bug in ByteTrackTracker.update() where the input sv.Detections object was being modified in-place, causing data loss for downstream code that reuses the detections object. The fix ensures the input remains immutable by using deepcopy() for all return paths.
Changes:
- Removed redundant in-place mutation of input detections (
detections.tracker_id = -np.ones(len(detections))) - Fixed edge case handling to return a deep copy instead of mutating the input when both tracks and detections are empty
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @Aaryan2304 👋🏻 Thanks a lot for your interes in trackers and for submitting this PR. We are planning |
Thanks @SkalskiP ! Appreciate you including this in the next release. |
|
Hi @Aaryan2304 👋🏻 It looks like the same bug is also partially present in SORT. trackers/core/sort/tracker.py lines 133-135 if len(self.trackers) == 0 and len(detections) == 0:
detections.tracker_id = np.array([], dtype=int)
return detectionstrackers/core/bytetrack/tracker.py lines 112-114 if len(self.tracks) == 0 and len(detections) == 0:
detections.tracker_id = np.array([], dtype=int)
return detections |
|
@SkalskiP ran soccernet benchmark over this branch and gives same result + from my overview seems like an adequate change |
|
@Aaryan2304 I'm merging the PR. Thanks a lot for your contribution! We may need similar PR for SORT. |
Ok, I'll make the necessary changes and raise a PR accordingly. |
Summary
This PR fixes a side-effect in
ByteTrackTracker.update()where the inputsv.Detectionsobject was modified in-place, overwriting existingtracker_idvalues with-1. This behavior caused data loss for pipelines that reuse thedetectionsobject after the tracking step.Changes
detections.tracker_id = -np.ones(len(detections))(line 111)deepcopy()calls in_update_detections(), the unmatched loop, and_spawn_new_trackers().deepcopy()instead of mutating and returning the input directly.Verification
detectionsobject retains its original values after callingupdate()CLA Signing
I have read the CLA Document and I sign the CLA.