2525
2626from torchvision .transforms import v2
2727
28- from .utils import assert_frames_equal , NASA_VIDEO , needs_cuda , psnr
28+ from .utils import (
29+ assert_frames_equal ,
30+ assert_tensor_close_on_at_least ,
31+ NASA_VIDEO ,
32+ needs_cuda ,
33+ )
2934
3035torch ._dynamo .config .capture_dynamic_output_shape_ops = True
3136
@@ -202,8 +207,15 @@ def test_resize_torchvision(self, height_scaling_factor, width_scaling_factor):
202207 assert frame_resize .shape == expected_shape
203208 assert frame_tv .shape == expected_shape
204209
205- # Copied from PR #992; not sure if it's the best way to check
206- assert psnr (frame_resize , frame_tv ) > 35
210+ # The two tensors have been resized in different colorspaces:
211+ #
212+ # frame_resize: [format=input] -> [resize] -> [format=rgb24]
213+ # frame_tv [format=input] -> [format=rgb24] -> [resize]
214+ #
215+ # As a consequence, they are not going to be identical.
216+ assert_tensor_close_on_at_least (
217+ frame_resize , frame_tv , percentage = 85 , atol = 3
218+ )
207219
208220 def test_resize_ffmpeg (self ):
209221 height = 135
@@ -276,7 +288,7 @@ def test_crop_transform(self):
276288 add_video_stream (decoder_full )
277289
278290 for frame_index in [0 , 15 , 200 , 389 ]:
279- frame , * _ = get_frame_at_index (decoder_crop , frame_index = frame_index )
291+ frame_crop , * _ = get_frame_at_index (decoder_crop , frame_index = frame_index )
280292 frame_ref = NASA_VIDEO .get_frame_data_by_index (
281293 frame_index , filters = crop_filtergraph
282294 )
@@ -286,12 +298,19 @@ def test_crop_transform(self):
286298 frame_full , top = y , left = x , height = height , width = width
287299 )
288300
289- assert frame .shape == expected_shape
301+ assert frame_crop .shape == expected_shape
290302 assert frame_ref .shape == expected_shape
291303 assert frame_tv .shape == expected_shape
292304
293- assert psnr (frame , frame_tv ) > 35
294- assert_frames_equal (frame , frame_ref )
305+ # The two tensors have been cropped in different colorspaces:
306+ #
307+ # frame_crop: [format=input] -> [crop] -> [format=rgb24]
308+ # frame_tv [format=input] -> [format=rgb24] -> [crop]
309+ #
310+ # As a consequence, they are not going to be identical.
311+ assert_tensor_close_on_at_least (frame_crop , frame_tv , percentage = 85 , atol = 3 )
312+
313+ assert_frames_equal (frame_crop , frame_ref )
295314
296315 def test_crop_transform_fails (self ):
297316
0 commit comments