Skip to content

Commit

Permalink
[fbsync] test output_format in video datasets (#7879)
Browse files Browse the repository at this point in the history
Summary: (Note: this ignores all push blocking failures!)

Reviewed By: matteobettini

Differential Revision: D48900404

fbshipit-source-id: 015ca49dd030e3734ad7a9d088ea454ffc2bf018
  • Loading branch information
NicolasHug authored and facebook-github-bot committed Sep 6, 2023
1 parent 4cb076c commit dfdfd88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
22 changes: 17 additions & 5 deletions test/datasets_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,27 +662,39 @@ class VideoDatasetTestCase(DatasetTestCase):
FEATURE_TYPES = (torch.Tensor, torch.Tensor, int)
REQUIRED_PACKAGES = ("av",)

DEFAULT_FRAMES_PER_CLIP = 1
FRAMES_PER_CLIP = 1

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.dataset_args = self._set_default_frames_per_clip(self.dataset_args)

def _set_default_frames_per_clip(self, inject_fake_data):
def _set_default_frames_per_clip(self, dataset_args):
argspec = inspect.getfullargspec(self.DATASET_CLASS.__init__)
args_without_default = argspec.args[1 : (-len(argspec.defaults) if argspec.defaults else None)]
frames_per_clip_last = args_without_default[-1] == "frames_per_clip"

@functools.wraps(inject_fake_data)
@functools.wraps(dataset_args)
def wrapper(tmpdir, config):
args = inject_fake_data(tmpdir, config)
args = dataset_args(tmpdir, config)
if frames_per_clip_last and len(args) == len(args_without_default) - 1:
args = (*args, self.DEFAULT_FRAMES_PER_CLIP)
args = (*args, self.FRAMES_PER_CLIP)

return args

return wrapper

def test_output_format(self):
for output_format in ["TCHW", "THWC"]:
with self.create_dataset(output_format=output_format) as (dataset, _):
for video, *_ in dataset:
if output_format == "TCHW":
num_frames, num_channels, *_ = video.shape
else: # output_format == "THWC":
num_frames, *_, num_channels = video.shape

assert num_frames == self.FRAMES_PER_CLIP
assert num_channels == 3

@test_all_configs
def test_transforms_v2_wrapper(self, config):
# `output_format == "THWC"` is not supported by the wrapper. Thus, we skip the `config` if it is set explicitly
Expand Down
6 changes: 3 additions & 3 deletions torchvision/datasets/video_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ def subset(self, indices: List[int]) -> "VideoClips":
}
return type(self)(
video_paths,
self.num_frames,
self.step,
self.frame_rate,
clip_length_in_frames=self.num_frames,
frames_between_clips=self.step,
frame_rate=self.frame_rate,
_precomputed_metadata=metadata,
num_workers=self.num_workers,
_video_width=self._video_width,
Expand Down

0 comments on commit dfdfd88

Please sign in to comment.