Clip samplers crash on iteration when no video clips are available
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 65/100
Research direction
Start with the UniformClipSampler and RandomClipSampler classes, where torch.cat is called on a possibly empty list of indices, and with VideoClips for how it skips short videos. Run the reproduction script in the issue to confirm the ValueError for each sampler. Done means all four sampler and empty-input combinations yield [] with no exception, and a regression test covers both the short-video and empty-video cases. The reporter says they plan to open a PR, so check for one before starting.
Written by the indexing model from the issue text.
Description
🐛 Describe the bug
UniformClipSampler reports length zero but raises an exception when every video is shorter than clip_length_in_frames. VideoClips warns that these videos will be skipped, so iterating the sampler should produce no indices.
Both UniformClipSampler and RandomClipSampler also fail when the video list is empty (for example, after VideoClips.subset([])). Both failures come from calling torch.cat(idxs) with an empty list.
Reproduction using precomputed timestamps, without video files or a decoder:
import torch
from torchvision.datasets.samplers import RandomClipSampler, UniformClipSampler
from torchvision.datasets.video_utils import VideoClips
for frame_counts in ([4], []):
paths = [f"video_{i}.mp4" for i in range(len(frame_counts))]
clips = VideoClips(
paths,
clip_length_in_frames=5,
frames_between_clips=5,
_precomputed_metadata={
"video_paths": paths,
"video_pts": [torch.arange(n) for n in frame_counts],
"video_fps": [30.0] * len(paths),
},
)
for sampler_cls in (UniformClipSampler, RandomClipSampler):
sampler = sampler_cls(clips, 3)
print(frame_counts, sampler_cls.__name__, "length:", len(sampler))
try:
print(list(sampler))
except ValueError as error:
print(type(error).__name__ + ": " + str(error))
Observed (in addition to the expected short-video warning):
[4] UniformClipSampler length: 0
ValueError: torch.cat(): expected a non-empty list of Tensors
[4] RandomClipSampler length: 0
[]
[] UniformClipSampler length: 0
ValueError: torch.cat(): expected a non-empty list of Tensors
[] RandomClipSampler length: 0
ValueError: torch.cat(): expected a non-empty list of Tensors
Expected: all four samplers yield [], consistent with their lengths. This also affects iteration through DistributedSampler wrapping these clip samplers.
I have a small fix and regression tests prepared and will submit a PR. Searches for both sampler names and empty-clip sampling did not find an existing report or competing fix.
Versions
- Torchvision source:
mainat134f6382956071833f05f072763c03f9858453f2(0.30.0a0+134f638), built locally with native ops. - PyTorch:
2.16.0.dev20261102 - Python:
3.13.3 - macOS 27.2, arm64; CPU reproduction.
- Dominant language
- Python
- Stars
- 18k
- Forks
- 7.3k
- Avg merge
- 1h
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pytorch/vision
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
[detection] Faster R-CNN accepts negative box_detections_per_img and applies Python slicingPossibly taken @hparik11 claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
pytorch/vision#9761 · 2 comments ·
Maintainers usually reply within 1 day
-
sigmoid_focal_loss gives NaN gradients for confident predictions when gamma < 1Possibly taken @yuvraj-del claimed this 21 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pytorch/vision#9743 · 2 comments ·
Maintainers usually reply within 1 day
-
vision_stable.cpp gets hipified into a duplicate copy under ROCm, causing "multiple definition of vision::cuda_version()"Possibly taken A pull request linked to this issue is open or already merged. Openmodule: rocm
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
complete_box_iou_loss / complete_box_iou: NaN gradients for zero-height boxes, NaN for point boxesPossibly taken @aounullah claimed this 21 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
pytorch/vision#9730 · 3 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 69/100
anderspitman/awesome-tunneling#330 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
521xueweihan/HelloGitHub#4676 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 18 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
pandas-dev/pandas-stubs#2155 ·
Maintainers usually reply within 1 day
-
essreduce
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
Maintainers usually reply within 1 day