perf(ocsort): reuse the box returned by predict - #580
Open
JESUSROYETH wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes OC-SORT association by reusing bounding boxes returned during prediction instead of decoding unchanged states again.
Changes:
- Adds opt-in prediction collection to the shared helper.
- Reuses predictions by tracklet identity, with duplicate-timestamp fallback.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/trackers/core/base.py |
Optionally returns predictions keyed by tracklet identity. |
src/trackers/core/ocsort/tracker.py |
Reuses cached predictions during association. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| out_tracker_ids: list[int] = [] | ||
|
|
||
| self._predict_tracklets(self.tracks, timing) | ||
| predicted_boxes_by_tracklet = self._predict_tracklets(self.tracks, timing, return_predictions=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OC-SORT currently throws away the box returned by
predict(), then decodes the same unchanged state throughget_state_bbox()before association. This happens because the shared predict helper discards return values atbase.py:520-525, and OCSORT decodes again attracker.py:266-275.So the returned predictions end up optional in the shared helper. OCSORT asks for them and keeps an
id(tracklet)map, so pruning tracks before association cannot move the boxes to a different track. Duplicate timestamps still useget_state_bbox()because prediction is skipped there. The other tracker families use the default path and keep the old loop without building the map.Validation
I compared develop against itself first, then against this patch. Two 500-frame dynamic streams cover XCYCSR and XYXY, 10,547 detections per representation, duplicate timestamps every 37 frames, and a separate case where one track is pruned between prediction and association. Output boxes were paired by Hungarian IoU, the output IDs and complete per-frame state hashes are exact.
In both cases, the same check passes over 36,928 public MOT17 detections and 45,442 DanceTrack ground-truth boxes. It removes 50,563 redundant decodes on MOT17 and 48,874 on the DanceTrack sample.
pytest -m 'not integration'passes with 1,564 tests, the four evaluator integrations pass, andpre-commit run --all-filesis clean.Performance
CPU-only, Python 3.12.3 and NumPy 1.26.4. Inputs are loaded before timing, run order alternates and garbage collection runs before each sample.
I also checked the five callers that do not need returned predictions. A first version built the map unconditionally and made them 0.31-0.57% slower, so I dropped it. With opt-in collection their final MOT17 median deltas are between -0.17% and +0.09%, the ranges overlap, and paired wins are mixed at 4-7/10.
Dynamic prediction arrived in #446. #527 optimized the adjacent OCSORT association path, while #528 cached predicted boxes for BoT-SORT and CBIoU. OCSORT only has one primary predicted-box association stage, so its already returned value stayed unused.