@@ -1240,6 +1240,10 @@ def test_kernel_video(self):
12401240 make_image_tensor ,
12411241 make_image_pil ,
12421242 make_image ,
1243+ pytest .param (
1244+ functools .partial (make_image_cvcuda , batch_dims = (1 ,)),
1245+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1246+ ),
12431247 make_bounding_boxes ,
12441248 make_segmentation_mask ,
12451249 make_video ,
@@ -1255,6 +1259,11 @@ def test_functional(self, make_input):
12551259 (F .horizontal_flip_image , torch .Tensor ),
12561260 (F ._geometry ._horizontal_flip_image_pil , PIL .Image .Image ),
12571261 (F .horizontal_flip_image , tv_tensors .Image ),
1262+ pytest .param (
1263+ F ._geometry ._horizontal_flip_image_cvcuda ,
1264+ cvcuda .Tensor ,
1265+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1266+ ),
12581267 (F .horizontal_flip_bounding_boxes , tv_tensors .BoundingBoxes ),
12591268 (F .horizontal_flip_mask , tv_tensors .Mask ),
12601269 (F .horizontal_flip_video , tv_tensors .Video ),
@@ -1270,6 +1279,10 @@ def test_functional_signature(self, kernel, input_type):
12701279 make_image_tensor ,
12711280 make_image_pil ,
12721281 make_image ,
1282+ pytest .param (
1283+ functools .partial (make_image_cvcuda , batch_dims = (1 ,)),
1284+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1285+ ),
12731286 make_bounding_boxes ,
12741287 make_segmentation_mask ,
12751288 make_video ,
@@ -1283,13 +1296,32 @@ def test_transform(self, make_input, device):
12831296 @pytest .mark .parametrize (
12841297 "fn" , [F .horizontal_flip , transform_cls_to_functional (transforms .RandomHorizontalFlip , p = 1 )]
12851298 )
1286- def test_image_correctness (self , fn ):
1287- image = make_image (dtype = torch .uint8 , device = "cpu" )
12881299
1289- actual = fn (image )
1290- expected = F .to_image (F .horizontal_flip (F .to_pil_image (image )))
1300+ @pytest .mark .parametrize (
1301+ "make_input" ,
1302+ [
1303+ make_image ,
1304+ pytest .param (
1305+ functools .partial (make_image_cvcuda , batch_dims = (1 ,)),
1306+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1307+ ),
1308+ ],
1309+ )
12911310
1292- torch .testing .assert_close (actual , expected )
1311+ def test_image_correctness (self , fn , make_input ):
1312+ image = make_input ()
1313+ actual = fn (image )
1314+ if isinstance (image , cvcuda .Tensor ):
1315+ # For CVCUDA input
1316+ expected = F .horizontal_flip (F .cvcuda_to_tensor (image ))
1317+ print ("actual is " , F .cvcuda_to_tensor (actual ))
1318+ print ("expected is " , expected )
1319+ assert_equal (F .cvcuda_to_tensor (actual ), expected )
1320+
1321+ else :
1322+ # For PIL/regular image input
1323+ expected = F .to_image (F .horizontal_flip (F .to_pil_image (image )))
1324+ assert_equal (actual , expected )
12931325
12941326 def _reference_horizontal_flip_bounding_boxes (self , bounding_boxes : tv_tensors .BoundingBoxes ):
12951327 affine_matrix = np .array (
@@ -1345,6 +1377,10 @@ def test_keypoints_correctness(self, fn):
13451377 make_image_tensor ,
13461378 make_image_pil ,
13471379 make_image ,
1380+ pytest .param (
1381+ functools .partial (make_image_cvcuda , batch_dims = (1 ,)),
1382+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1383+ ),
13481384 make_bounding_boxes ,
13491385 make_segmentation_mask ,
13501386 make_video ,
@@ -1354,12 +1390,13 @@ def test_keypoints_correctness(self, fn):
13541390 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
13551391 def test_transform_noop (self , make_input , device ):
13561392 input = make_input (device = device )
1357-
13581393 transform = transforms .RandomHorizontalFlip (p = 0 )
1359-
13601394 output = transform (input )
1395+ if isinstance (input , cvcuda .Tensor ):
1396+ assert_equal (F .cvcuda_to_tensor (output ), F .cvcuda_to_tensor (input ))
1397+ else :
1398+ assert_equal (output , input )
13611399
1362- assert_equal (output , input )
13631400
13641401
13651402class TestAffine :
@@ -1856,6 +1893,10 @@ def test_kernel_video(self):
18561893 make_image_tensor ,
18571894 make_image_pil ,
18581895 make_image ,
1896+ pytest .param (
1897+ functools .partial (make_image_cvcuda , batch_dims = (1 ,)),
1898+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1899+ ),
18591900 make_bounding_boxes ,
18601901 make_segmentation_mask ,
18611902 make_video ,
@@ -1871,6 +1912,11 @@ def test_functional(self, make_input):
18711912 (F .vertical_flip_image , torch .Tensor ),
18721913 (F ._geometry ._vertical_flip_image_pil , PIL .Image .Image ),
18731914 (F .vertical_flip_image , tv_tensors .Image ),
1915+ pytest .param (
1916+ F ._geometry ._vertical_flip_image_cvcuda ,
1917+ cvcuda .Tensor ,
1918+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1919+ ),
18741920 (F .vertical_flip_bounding_boxes , tv_tensors .BoundingBoxes ),
18751921 (F .vertical_flip_mask , tv_tensors .Mask ),
18761922 (F .vertical_flip_video , tv_tensors .Video ),
@@ -1886,6 +1932,10 @@ def test_functional_signature(self, kernel, input_type):
18861932 make_image_tensor ,
18871933 make_image_pil ,
18881934 make_image ,
1935+ pytest .param (
1936+ functools .partial (make_image_cvcuda , batch_dims = (1 ,)),
1937+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1938+ ),
18891939 make_bounding_boxes ,
18901940 make_segmentation_mask ,
18911941 make_video ,
@@ -1897,13 +1947,28 @@ def test_transform(self, make_input, device):
18971947 check_transform (transforms .RandomVerticalFlip (p = 1 ), make_input (device = device ))
18981948
18991949 @pytest .mark .parametrize ("fn" , [F .vertical_flip , transform_cls_to_functional (transforms .RandomVerticalFlip , p = 1 )])
1900- def test_image_correctness (self , fn ):
1901- image = make_image (dtype = torch .uint8 , device = "cpu" )
1950+ @pytest .mark .parametrize (
1951+ "make_input" ,
1952+ [
1953+ make_image ,
1954+ pytest .param (
1955+ functools .partial (make_image_cvcuda , batch_dims = (1 ,)),
1956+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1957+ ),
1958+ ],
1959+ )
19021960
1961+ def test_image_correctness (self , fn , make_input ):
1962+ image = make_input ()
19031963 actual = fn (image )
1904- expected = F .to_image (F .vertical_flip (F .to_pil_image (image )))
1905-
1906- torch .testing .assert_close (actual , expected )
1964+ if isinstance (image , cvcuda .Tensor ):
1965+ # For CVCUDA input
1966+ expected = F .vertical_flip (F .cvcuda_to_tensor (image ))
1967+ assert_equal (F .cvcuda_to_tensor (actual ), expected )
1968+ else :
1969+ # For PIL/regular image input
1970+ expected = F .to_image (F .vertical_flip (F .to_pil_image (image )))
1971+ assert_equal (actual , expected )
19071972
19081973 def _reference_vertical_flip_bounding_boxes (self , bounding_boxes : tv_tensors .BoundingBoxes ):
19091974 affine_matrix = np .array (
@@ -1955,6 +2020,10 @@ def test_keypoints_correctness(self, fn):
19552020 make_image_tensor ,
19562021 make_image_pil ,
19572022 make_image ,
2023+ pytest .param (
2024+ functools .partial (make_image_cvcuda , batch_dims = (1 ,)),
2025+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
2026+ ),
19582027 make_bounding_boxes ,
19592028 make_segmentation_mask ,
19602029 make_video ,
@@ -1964,12 +2033,12 @@ def test_keypoints_correctness(self, fn):
19642033 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
19652034 def test_transform_noop (self , make_input , device ):
19662035 input = make_input (device = device )
1967-
19682036 transform = transforms .RandomVerticalFlip (p = 0 )
1969-
19702037 output = transform (input )
1971-
1972- assert_equal (output , input )
2038+ if isinstance (input , cvcuda .Tensor ):
2039+ assert_equal (F .cvcuda_to_tensor (output ), F .cvcuda_to_tensor (input ))
2040+ else :
2041+ assert_equal (output , input )
19732042
19742043
19752044class TestRotate :
0 commit comments