Unverified Commit 1bdda8cb authored by Santiago Castro's avatar Santiago Castro Committed by GitHub
Browse files

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



* Add a warning if a clip can't be get from a video in VideoClips

* Update torchvision/datasets/video_utils.py
Co-authored-by: default avatarPhilip Meier <github.pmeier@posteo.de>

* Add a test
Co-authored-by: default avatarPhilip Meier <github.pmeier@posteo.de>
parent 4521f6d1
...@@ -119,6 +119,16 @@ class Tester(unittest.TestCase): ...@@ -119,6 +119,16 @@ class Tester(unittest.TestCase):
self.assertTrue(clips.equal(idxs)) self.assertTrue(clips.equal(idxs))
self.assertTrue(idxs.flatten().equal(resampled_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__': if __name__ == '__main__':
unittest.main() unittest.main()
import bisect import bisect
import math import math
import warnings
from fractions import Fraction from fractions import Fraction
from typing import List from typing import List
...@@ -204,6 +205,9 @@ class VideoClips(object): ...@@ -204,6 +205,9 @@ class VideoClips(object):
) )
video_pts = video_pts[idxs] video_pts = video_pts[idxs]
clips = unfold(video_pts, num_frames, step) 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): if isinstance(idxs, slice):
idxs = [idxs] * len(clips) idxs = [idxs] * len(clips)
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment