Clip samplers crash on iteration when no video clips are available

オープン 初心者向け
#9,733 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@raunakpandey1 がすでに取り組んでいます。

2026年11月2日 から。

  • #9734 @raunakpandey1 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
data

調査の方向性

UniformClipSampler と RandomClipSampler クラスから始めてください。ここでは、空の可能性があるインデックスのリストに対して torch.cat が呼び出されています。短い動画をどのようにスキップするかについては VideoClips を確認してください。issue の再現スクリプトを実行し、各サンプラーで ValueError が発生することを確認してください。完了の条件は、4つのサンプラーと空入力の組み合わせがすべて例外なく [] を返すことと、短い動画と空の動画の両方をリグレッションテストで網羅することです。報告者は PR を作成する予定だと述べているため、作業を始める前に既存の PR がないか確認してください。

索引モデルが issue の本文から書いたものです。

説明

🐛 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: main at 134f6382956071833f05f072763c03f9858453f2 (0.30.0a0+134f638), built locally with native ops.
  • PyTorch: 2.16.0.dev20261102
  • Python: 3.13.3
  • macOS 27.2, arm64; CPU reproduction.
主要言語
Python
スター
18k
フォーク
7.3k
平均マージ
1時間
マージ済み PR(30日)
3

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pytorch/vision のほかの issue

pytorch/vision の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。