Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a warning if any clip can't be obtained from a video in VideoClips. #2513

Merged
merged 3 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/test_datasets_video_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ def test_compute_clips_for_video(self):
self.assertTrue(clips.equal(idxs))
self.assertTrue(idxs.flatten().equal(resampled_idxs))

# case 3: frames aren't enough for a clip
num_frames = 32
orig_fps = 30
new_fps = 13
with self.assertWarns(UserWarning):
clips, idxs = VideoClips.compute_clips_for_video(video_pts, num_frames, num_frames,
orig_fps, new_fps)
self.assertEqual(len(clips), 0)
self.assertEqual(len(idxs), 0)


if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions torchvision/datasets/video_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import bisect
import math
import warnings
from fractions import Fraction
from typing import List

Expand Down Expand Up @@ -204,6 +205,9 @@ def compute_clips_for_video(video_pts, num_frames, step, fps, frame_rate):
)
video_pts = video_pts[idxs]
clips = unfold(video_pts, num_frames, step)
if not clips.numel():
warnings.warn("There aren't enough frames in the current video to get a clip for the given clip length and "
"frames between clips. The video (and potentially others) will be skipped.")
if isinstance(idxs, slice):
idxs = [idxs] * len(clips)
else:
Expand Down