Skip to content

fix(cli): propagate the real source frame rate into the tracker - #569

Merged
Borda merged 2 commits into
roboflow:developfrom
JESUSROYETH:fix/tracker-frame-rate-propagation
Aug 14, 2026
Merged

Borda merged 2 commits into
roboflow:developfrom
JESUSROYETH:fix/tracker-frame-rate-propagation

Conversation

@JESUSROYETH

Copy link
Copy Markdown
Contributor

None of the three places that build a tracker from a real source pass it the source's actual frame rate. All of them fall back to the constructor default, frame_rate=30.0.

  • track_command() in src/trackers/cli/track.py calls _init_tracker() before source_info exists in that function's scope. source_info is what holds the real fps, via _classify_source(), so at that point there is nothing to pass yet. It's an ordering problem, not just a missing parameter.
  • _get_video_info() in demo/app.py already reads the fps with cv2.VideoCapture(...).get(cv2.CAP_PROP_FPS), but only uses it to compute the clip duration and throws it away. track() then builds ByteTrackTracker/SORTTracker with no frame_rate= at all.
  • run_sequence() in src/trackers/cli/benchmark/mcbyte.py passes DatasetConfig.frame_rate (one default shared by every sequence in a dataset) straight into create_tracker(). There is no mention of seqinfo.ini anywhere in the repo before this PR.

I checked how far off the shared default actually is against real data. The integration tests already cache real MOTChallenge-format sequences locally, and their seqinfo.ini files show frameRate=25 for all 45 cached SportsMOT-val sequences, and frameRate=20 for all 25 cached DanceTrack-val sequences. So this is not a couple of outlier sequences. The default is wrong for every sequence checked, in both datasets this benchmark supports.

Changes

  • src/trackers/cli/track.py: reordered track_command() to classify the source (metadata only, no frame decode) before building the tracker, and threaded that into _init_tracker() through a new detected_frame_rate: float | None = None argument.

It only fills kwargs["frame_rate"] when three things hold: the selected tracker accepts that argument, there is no explicit --tracker.frame_rate override already set, and the detected value is finite and > 0. That last check matters, a corrupt container can report inf/nan through cv2.CAP_PROP_FPS, and without the guard that would reach the tracker constructor and crash inside BaseTracker._compute_maximum_frames_without_update's math.isfinite check. An explicit override always wins.

For a pure --detection.mot_file replay there is no video to read a fps from. detected_frame_rate stays None and every tracker keeps its own default. That's correct, not a gap.

  • demo/app.py: _get_video_info() now also returns the fps it was already reading. It's guarded the same way, rejecting non-finite values and not just non-positive ones, because this value used to be display-only and is now forwarded live into the tracker constructor. track() forwards it as frame_rate= to ByteTrackTracker and SORTTracker.
  • src/trackers/cli/benchmark/mcbyte.py: added _read_sequence_frame_rate(image_dir, default, *, logger=None, sequence=""). It reads image_dir.parent / seqinfo.ini (the standard MOTChallenge layout) and parses [Sequence] frameRate with configparser, falling back to the dataset default when the file is missing, unparsable, or the value is not finite/positive.

A missing seqinfo.ini stays silent, and that's unremarkable. A present but broken one — unparsable content, or a non-finite/non-positive frameRate — now logs a warning naming the file, so a dataset shipping bad metadata doesn't silently pass for one with no metadata at all. run_sequence() now uses that per-sequence value instead of config.frame_rate directly, and logs once per sequence when the two differ.

  • docs/guides/track.md: updated the --tracker.frame_rate reference row. It used to say the default was just the tracker's own default; now it says a readable source FPS is used first, when the flag is left unset.

One sibling I did not touch: SequenceOptions.frame_rate in src/trackers/cli/inspect/mcbyte.py:109 has the same shape, a defaulted fps field. But that tool is a manual debugging entry point. The user already supplies image_dir, det_file, start_frame, end_frame, det_format by hand for every run, so there is no automatic source detection there for a real value to get discarded from. Left it out of scope on purpose, not something I missed.

A second one I also left alone, for a different reason. Tuner._build_tracker() in src/trackers/tune/tuner.py builds one tracker per trial with frame_rate on the same hardcoded 30.0, then reuses that single instance (tracker.reset() only) across every sequence in self._sequences.

frame_rate is not in any tracker's search_space, so nothing here ever sets it from real data either. images_dir — where a seqinfo.ini would live — is optional, and only required when enable_cmc=True.

Closing this one the same way needs an actual design decision. Either rebuild the tracker per sequence with its own detected fps, which changes what "one tracker instance per trial" means in _objective(), or accept one fps for a whole trial even when the sequences mix rates. That's not a call I want to make inside a plumbing PR, so I'm leaving it flagged instead of touching it or staying quiet about it.

This PR does not re-run the McByte benchmark or regenerate any of the golden results. That needs SAM/Cutie GPU compute, and it's outside what I wanted to take on here.

Worth flagging clearly though: running trackers benchmark mcbyte again after this fix could move the HOTA/MOTA numbers published in docs/evaluations/results.md for SportsMOT and DanceTrack. Only the lost-track buffer is affected, the Kalman process noise is not. BaseTracker._compute_maximum_frames_without_update scales lost_track_buffer by frame_rate / 30.0 once at tracker construction. So with McByte's default lost_track_buffer=30, the missed-frame budget goes from 30 frames (old hardcoded 30fps default) to 25 frames on SportsMOT-val (25fps), and 20 frames on DanceTrack-val (20fps).

The Kalman noise band in motion_models.py::build_Q only becomes fps-aware when a frame_rate reaches it through PredictTiming, the timestamped/dynamic-rate path. run_sequence() never passes a timestamp to update(), so it stays on the fixed frame-unit fallback regardless of this fix. I have not re-measured the buffer's downstream effect on HOTA/MOTA, I'm just leaving the mechanism and its exact magnitude as a known consequence for whoever runs the benchmark next.

Validation

  • Full non-integration suite: 1495 passed, 3 skipped, 14 deselected, consistent across repeated runs (baseline, before the adversarial-review fixes below; see caveat under those).
  • pre-commit run --all-files: all 18 hooks clean (license header, ruff check/format, docformatter, mdformat, codespell, mypy on src and tests).
  • Checked the benchmark regression test actually discriminates: reverted run_sequence()'s frame_rate=frame_rate back to frame_rate=config.frame_rate (the pre-fix behaviour) and reran the new tests. Exactly one failed (test_seqinfo_frame_rate_reaches_create_tracker, assert 30.0 == 25.0), the other 9 stayed green — expected, since the "no seqinfo" case is unaffected by the bug. Restored the fix, the full suite is green again.
  • New tests: tests/cli/test_track.py::TestInitTrackerDetectedFrameRate (6 tests, detected value reaches the tracker, explicit override wins, non-positive/non-finite/None values are ignored, every registered tracker currently accepts frame_rate), tests/cli/test_track.py::TestTrackCommandDetectsSourceFrameRate (2 tests, end to end with a real 24fps video written via cv2.VideoWriter and round-tripped through cv2.CAP_PROP_FPS, and the no-source case), tests/cli/test_benchmark_mcbyte.py::TestReadSequenceFrameRate (8 tests, parametrised over 0, -25, nan, inf, plus 3 covering the new seqinfo-present-but-broken warning), tests/cli/test_benchmark_mcbyte.py::TestRunSequenceUsesRealFrameRate (2 tests, create_tracker monkeypatched to a stub capturing the frame_rate kwarg, the real McByteTracker needs SAM/Cutie which is too heavy for a wiring check).
  • Adversarial review round (Codex) caught two real gaps and one prose overclaim, all fixed in this same patch:
    1. _init_tracker and demo/app.py::_get_video_info only rejected <= 0 fps, not non-finite fps. Since this PR is what makes that value reach the tracker constructor live (it used to be display-only), an inf/nan from a corrupt container crashed with an unhandled ValueError instead of falling back. Added the same math.isfinite guard benchmark/mcbyte.py already had.
    2. _read_sequence_frame_rate fell back identically, and silently, whether seqinfo.ini was simply absent or present-but-broken. Added an opt-in logger/sequence pair so run_sequence can warn on the latter case specifically.
    3. The PR body and a docstring overclaimed that this fix also changes McByte's Kalman process noise. It does not: run_sequence never passes a timestamp to update(), so the tracker stays in fixed-rate mode, only the lost-track buffer scaling is affected.

tests/cli/test_track.py -m "not integration" reverified after these fixes: 51 passed. tests/cli/test_benchmark_mcbyte.py's logger-warning behaviour was verified by direct module import (_read_sequence_frame_rate called standalone) rather than through pytest, because collecting that test file needs jsonargparse, which isn't installed in the environment available for this review round. That's a declared runtime dependency (pyproject.toml), not something this PR adds or removes, and none of benchmark/mcbyte.py's other tests were touched by the review-round changes.

@JESUSROYETH
JESUSROYETH requested a review from SkalskiP as a code owner August 13, 2026 21:37
@Borda
Borda requested a balanced review from Copilot August 14, 2026 06:35
@Borda Borda added the bug Something isn't working label Aug 14, 2026
Borda
Borda previously approved these changes Aug 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Propagates detected source frame rates into trackers so lost-track buffering reflects actual media timing.

Changes:

  • Detects and forwards video FPS in the CLI and demo.
  • Reads per-sequence benchmark FPS from seqinfo.ini.
  • Adds documentation and regression coverage.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/trackers/cli/track.py Seeds trackers with detected video FPS.
src/trackers/cli/benchmark/mcbyte.py Reads per-sequence benchmark FPS.
demo/app.py Passes uploaded-video FPS to trackers.
docs/guides/track.md Documents FPS fallback behavior.
tests/cli/test_track.py Tests CLI FPS propagation and validation.
tests/cli/test_benchmark_mcbyte.py Tests sequence metadata handling and propagation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/trackers/cli/benchmark/mcbyte.py Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@Borda
Borda merged commit e9bfccd into roboflow:develop Aug 14, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants