Skip to content

fix(gui): omit --frames for entire-video inference (#2808)#2809

Open
tom21100227 wants to merge 1 commit into
developfrom
triage/2807-frames
Open

fix(gui): omit --frames for entire-video inference (#2808)#2809
tom21100227 wants to merge 1 commit into
developfrom
triage/2807-frames

Conversation

@tom21100227

Copy link
Copy Markdown
Collaborator

Problem

Running inference from the GUI with the frame range set to "Entire video" builds a command containing --frames 0,-N (e.g. --frames 0,-10245). This was reported in discussion #2807, where it crashes with IndexError: Failed to read frame index N.

Two things are wrong with the 0,-N encoding:

  1. It's fragile. MainWindow._get_frames_for_prediction encodes "Entire video" as the half-open range [0, len(video))[0, -len(video)], and VideoItemForInference.cli_args serializes that to --frames 0,-N. That string only decodes back into a range because sleap-nn's frame_list happens to do min_max[0].rstrip(","). It reads like the two-frame list [0, -N] (exactly how the reporter interpreted it).
  2. It pins the endpoint to the GUI's frame count. If that count is one greater than the number of frames the inference reader actually decodes — the 1-indexed/0-indexed discrepancy in GUI frames are 1-indexed, while cli commands are 0-indexed #2790, or a video whose metadata over-reports its length — inference iterates to a nonexistent frame and raises IndexError: Failed to read frame index N.

Fix

Add VideoItemForInference.is_entire_video and, when it's true, omit --frames so the inference CLI predicts on all frames using its own frame count (the documented default when --frames is not passed). This drops the fragile encoding and decouples the run from the GUI's count.

Selection Before After
Entire video --frames 0,-N (omitted → all frames)
Clip [a, b) --frames a,-(b-1) unchanged
Explicit frames --frames 0,1,2,… unchanged
Current frame --frames k unchanged

Testing

  • tests/gui/learning/test_cli_construction.py::TestVideoItemForInferenceCLI — added 3 tests (entire-video omits --frames; a shorter clip still emits --frames; explicit lists are never treated as entire-video). All 9 tests in the class pass.
  • Existing frame-range / CLI-construction tests unchanged and green.

One unrelated test (TestWritePipelineFiles::test_train_script_does_not_contain_zmq) fails locally with ModuleNotFoundError: No module named 'sleap_nn' — pre-existing in this environment (confirmed on a clean branch), not touched by this change.

Notes

If the crash still reproduces for a specific video after this change, the video's own metadata over-reports its decodable frame count (a corrupted / variable-frame-rate file). That is a separate reader-robustness concern in sleap-nn / sleap-io, and the plan is to confirm with the reporter and request the video if needed.

Fixes #2808. Reported in #2807.

github-actions Bot pushed a commit that referenced this pull request Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Docs Preview

Preview URL https://docs.sleap.ai/pr/2809/
Commit 9a5f1d00e6b93b85a7afcacd775911239b3b535f

API changes detected - View API Reference

This preview will be removed when the PR is closed.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.70%. Comparing base (2649d80) to head (9a5f1d0).

Files with missing lines Patch % Lines
sleap/gui/learning/runners.py 83.33% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2809   +/-   ##
========================================
  Coverage    70.69%   70.70%           
========================================
  Files          103      103           
  Lines        23359    23374   +15     
========================================
+ Hits         16514    16526   +12     
- Misses        6845     6848    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The "Entire video" inference option encoded its selection as the range
[0, len(video)) and serialized it to a fragile `--frames 0,-N` argument.
That form only decodes as a range via a legacy `rstrip(",")` quirk in
sleap-nn's `frame_list`, and it pins the endpoint to the GUI's frame
count. When that count exceeds the number of frames the inference video
reader can decode (off-by-one indexing, or a video whose metadata
over-reports its length), inference requests a nonexistent frame and
crashes with `IndexError: Failed to read frame index N`.

Add `VideoItemForInference.is_entire_video` and omit `--frames` for that
case so the inference CLI predicts on all frames using its own frame
count (its documented default). Clip and explicit-frame selections are
unchanged.

Fixes #2808. Reported in #2807.

With the help of Claude.
@tom21100227
tom21100227 force-pushed the triage/2807-frames branch from 7ab4981 to 9a5f1d0 Compare July 1, 2026 22:20
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.

GUI "Entire video" inference emits fragile --frames 0,-N and can request an out-of-range frame

1 participant