|
31 | 31 | H265_VIDEO, |
32 | 32 | NASA_VIDEO, |
33 | 33 | needs_cuda, |
| 34 | + TEST_SRC_2_720P, |
34 | 35 | ) |
35 | 36 |
|
36 | 37 | torch._dynamo.config.capture_dynamic_output_shape_ops = True |
37 | 38 |
|
38 | 39 |
|
39 | 40 | class TestCoreVideoDecoderTransformOps: |
40 | | - @pytest.mark.parametrize("video", [NASA_VIDEO, H265_VIDEO, AV1_VIDEO]) |
41 | | - def test_color_conversion_library(self, video): |
| 41 | + def get_num_frames_core_ops(self, video): |
42 | 42 | decoder = create_from_file(str(video.path)) |
43 | 43 | add_video_stream(decoder) |
44 | 44 | metadata = get_json_metadata(decoder) |
45 | 45 | metadata_dict = json.loads(metadata) |
46 | 46 | num_frames = metadata_dict["numFramesFromHeader"] |
| 47 | + assert num_frames is not None |
| 48 | + return num_frames |
| 49 | + |
| 50 | + @pytest.mark.parametrize("video", [NASA_VIDEO, H265_VIDEO, AV1_VIDEO]) |
| 51 | + def test_color_conversion_library(self, video): |
| 52 | + num_frames = self.get_num_frames_core_ops(video) |
47 | 53 |
|
48 | 54 | filtergraph_decoder = create_from_file(str(video.path)) |
49 | 55 | _add_video_stream( |
@@ -170,32 +176,63 @@ def test_transform_fails(self): |
170 | 176 | "height_scaling_factor, width_scaling_factor", |
171 | 177 | ((1.5, 1.31), (0.5, 0.71), (0.7, 1.31), (1.5, 0.71), (1.0, 1.0), (2.0, 2.0)), |
172 | 178 | ) |
173 | | - def test_resize_torchvision(self, height_scaling_factor, width_scaling_factor): |
174 | | - height = int(NASA_VIDEO.get_height() * height_scaling_factor) |
175 | | - width = int(NASA_VIDEO.get_width() * width_scaling_factor) |
| 179 | + @pytest.mark.parametrize("video", [NASA_VIDEO, TEST_SRC_2_720P]) |
| 180 | + def test_resize_torchvision( |
| 181 | + self, video, height_scaling_factor, width_scaling_factor |
| 182 | + ): |
| 183 | + num_frames = self.get_num_frames_core_ops(video) |
| 184 | + |
| 185 | + height = int(video.get_height() * height_scaling_factor) |
| 186 | + width = int(video.get_width() * width_scaling_factor) |
176 | 187 | resize_spec = f"resize, {height}, {width}" |
177 | 188 |
|
178 | | - decoder_resize = create_from_file(str(NASA_VIDEO.path)) |
| 189 | + decoder_resize = create_from_file(str(video.path)) |
179 | 190 | add_video_stream(decoder_resize, transform_specs=resize_spec) |
180 | 191 |
|
181 | | - decoder_full = create_from_file(str(NASA_VIDEO.path)) |
| 192 | + decoder_full = create_from_file(str(video.path)) |
182 | 193 | add_video_stream(decoder_full) |
183 | 194 |
|
184 | | - for frame_index in [0, 10, 17, 100, 230, 389]: |
185 | | - expected_shape = (NASA_VIDEO.get_num_color_channels(), height, width) |
| 195 | + for frame_index in [ |
| 196 | + 0, |
| 197 | + int(num_frames * 0.1), |
| 198 | + int(num_frames * 0.2), |
| 199 | + int(num_frames * 0.3), |
| 200 | + int(num_frames * 0.4), |
| 201 | + int(num_frames * 0.5), |
| 202 | + int(num_frames * 0.75), |
| 203 | + int(num_frames * 0.90), |
| 204 | + num_frames - 1, |
| 205 | + ]: |
| 206 | + expected_shape = (video.get_num_color_channels(), height, width) |
186 | 207 | frame_resize, *_ = get_frame_at_index( |
187 | 208 | decoder_resize, frame_index=frame_index |
188 | 209 | ) |
189 | 210 |
|
190 | 211 | frame_full, *_ = get_frame_at_index(decoder_full, frame_index=frame_index) |
191 | 212 | frame_tv = v2.functional.resize(frame_full, size=(height, width)) |
| 213 | + frame_tv_no_antialias = v2.functional.resize( |
| 214 | + frame_full, size=(height, width), antialias=False |
| 215 | + ) |
192 | 216 |
|
193 | 217 | assert frame_resize.shape == expected_shape |
194 | 218 | assert frame_tv.shape == expected_shape |
| 219 | + assert frame_tv_no_antialias.shape == expected_shape |
195 | 220 |
|
196 | 221 | assert_tensor_close_on_at_least( |
197 | | - frame_resize, frame_tv, percentage=99, atol=1 |
| 222 | + frame_resize, frame_tv, percentage=99.9, atol=1 |
198 | 223 | ) |
| 224 | + torch.testing.assert_close(frame_resize, frame_tv, rtol=0, atol=6) |
| 225 | + |
| 226 | + if height_scaling_factor < 1 or width_scaling_factor < 1: |
| 227 | + # Antialias only relevant when down-scaling! |
| 228 | + with pytest.raises(AssertionError, match="Expected at least"): |
| 229 | + assert_tensor_close_on_at_least( |
| 230 | + frame_resize, frame_tv_no_antialias, percentage=99, atol=1 |
| 231 | + ) |
| 232 | + with pytest.raises(AssertionError, match="Tensor-likes are not close"): |
| 233 | + torch.testing.assert_close( |
| 234 | + frame_resize, frame_tv_no_antialias, rtol=0, atol=6 |
| 235 | + ) |
199 | 236 |
|
200 | 237 | def test_resize_ffmpeg(self): |
201 | 238 | height = 135 |
|
0 commit comments