@@ -1241,6 +1241,10 @@ def test_kernel_video(self):
12411241 make_image_tensor ,
12421242 make_image_pil ,
12431243 make_image ,
1244+ pytest .param (
1245+ make_image_cvcuda ,
1246+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1247+ ),
12441248 make_bounding_boxes ,
12451249 make_segmentation_mask ,
12461250 make_video ,
@@ -1256,13 +1260,20 @@ def test_functional(self, make_input):
12561260 (F .horizontal_flip_image , torch .Tensor ),
12571261 (F ._geometry ._horizontal_flip_image_pil , PIL .Image .Image ),
12581262 (F .horizontal_flip_image , tv_tensors .Image ),
1263+ pytest .param (
1264+ F ._geometry ._horizontal_flip_image_cvcuda ,
1265+ None ,
1266+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1267+ ),
12591268 (F .horizontal_flip_bounding_boxes , tv_tensors .BoundingBoxes ),
12601269 (F .horizontal_flip_mask , tv_tensors .Mask ),
12611270 (F .horizontal_flip_video , tv_tensors .Video ),
12621271 (F .horizontal_flip_keypoints , tv_tensors .KeyPoints ),
12631272 ],
12641273 )
12651274 def test_functional_signature (self , kernel , input_type ):
1275+ if kernel is F ._geometry ._horizontal_flip_image_cvcuda :
1276+ input_type = _import_cvcuda ().Tensor
12661277 check_functional_kernel_signature_match (F .horizontal_flip , kernel = kernel , input_type = input_type )
12671278
12681279 @pytest .mark .parametrize (
@@ -1271,6 +1282,10 @@ def test_functional_signature(self, kernel, input_type):
12711282 make_image_tensor ,
12721283 make_image_pil ,
12731284 make_image ,
1285+ pytest .param (
1286+ make_image_cvcuda ,
1287+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1288+ ),
12741289 make_bounding_boxes ,
12751290 make_segmentation_mask ,
12761291 make_video ,
@@ -1284,13 +1299,23 @@ def test_transform(self, make_input, device):
12841299 @pytest .mark .parametrize (
12851300 "fn" , [F .horizontal_flip , transform_cls_to_functional (transforms .RandomHorizontalFlip , p = 1 )]
12861301 )
1287- def test_image_correctness (self , fn ):
1288- image = make_image (dtype = torch .uint8 , device = "cpu" )
1289-
1302+ @pytest .mark .parametrize (
1303+ "make_input" ,
1304+ [
1305+ make_image ,
1306+ pytest .param (
1307+ make_image_cvcuda ,
1308+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1309+ ),
1310+ ],
1311+ )
1312+ def test_image_correctness (self , fn , make_input ):
1313+ image = make_input ()
12901314 actual = fn (image )
1291- expected = F .to_image (F .horizontal_flip (F .to_pil_image (image )))
1292-
1293- torch .testing .assert_close (actual , expected )
1315+ if make_input is make_image_cvcuda :
1316+ image = F .cvcuda_to_tensor (image )[0 ].cpu ()
1317+ expected = F .horizontal_flip (F .to_pil_image (image ))
1318+ assert_equal (actual , expected )
12941319
12951320 def _reference_horizontal_flip_bounding_boxes (self , bounding_boxes : tv_tensors .BoundingBoxes ):
12961321 affine_matrix = np .array (
@@ -1346,6 +1371,10 @@ def test_keypoints_correctness(self, fn):
13461371 make_image_tensor ,
13471372 make_image_pil ,
13481373 make_image ,
1374+ pytest .param (
1375+ make_image_cvcuda ,
1376+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1377+ ),
13491378 make_bounding_boxes ,
13501379 make_segmentation_mask ,
13511380 make_video ,
@@ -1355,11 +1384,8 @@ def test_keypoints_correctness(self, fn):
13551384 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
13561385 def test_transform_noop (self , make_input , device ):
13571386 input = make_input (device = device )
1358-
13591387 transform = transforms .RandomHorizontalFlip (p = 0 )
1360-
13611388 output = transform (input )
1362-
13631389 assert_equal (output , input )
13641390
13651391
@@ -1857,6 +1883,10 @@ def test_kernel_video(self):
18571883 make_image_tensor ,
18581884 make_image_pil ,
18591885 make_image ,
1886+ pytest .param (
1887+ make_image_cvcuda ,
1888+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1889+ ),
18601890 make_bounding_boxes ,
18611891 make_segmentation_mask ,
18621892 make_video ,
@@ -1872,13 +1902,20 @@ def test_functional(self, make_input):
18721902 (F .vertical_flip_image , torch .Tensor ),
18731903 (F ._geometry ._vertical_flip_image_pil , PIL .Image .Image ),
18741904 (F .vertical_flip_image , tv_tensors .Image ),
1905+ pytest .param (
1906+ F ._geometry ._vertical_flip_image_cvcuda ,
1907+ None ,
1908+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1909+ ),
18751910 (F .vertical_flip_bounding_boxes , tv_tensors .BoundingBoxes ),
18761911 (F .vertical_flip_mask , tv_tensors .Mask ),
18771912 (F .vertical_flip_video , tv_tensors .Video ),
18781913 (F .vertical_flip_keypoints , tv_tensors .KeyPoints ),
18791914 ],
18801915 )
18811916 def test_functional_signature (self , kernel , input_type ):
1917+ if kernel is F ._geometry ._vertical_flip_image_cvcuda :
1918+ input_type = _import_cvcuda ().Tensor
18821919 check_functional_kernel_signature_match (F .vertical_flip , kernel = kernel , input_type = input_type )
18831920
18841921 @pytest .mark .parametrize (
@@ -1887,6 +1924,10 @@ def test_functional_signature(self, kernel, input_type):
18871924 make_image_tensor ,
18881925 make_image_pil ,
18891926 make_image ,
1927+ pytest .param (
1928+ make_image_cvcuda ,
1929+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1930+ ),
18901931 make_bounding_boxes ,
18911932 make_segmentation_mask ,
18921933 make_video ,
@@ -1898,13 +1939,23 @@ def test_transform(self, make_input, device):
18981939 check_transform (transforms .RandomVerticalFlip (p = 1 ), make_input (device = device ))
18991940
19001941 @pytest .mark .parametrize ("fn" , [F .vertical_flip , transform_cls_to_functional (transforms .RandomVerticalFlip , p = 1 )])
1901- def test_image_correctness (self , fn ):
1902- image = make_image (dtype = torch .uint8 , device = "cpu" )
1903-
1942+ @pytest .mark .parametrize (
1943+ "make_input" ,
1944+ [
1945+ make_image ,
1946+ pytest .param (
1947+ make_image_cvcuda ,
1948+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
1949+ ),
1950+ ],
1951+ )
1952+ def test_image_correctness (self , fn , make_input ):
1953+ image = make_input ()
19041954 actual = fn (image )
1905- expected = F .to_image (F .vertical_flip (F .to_pil_image (image )))
1906-
1907- torch .testing .assert_close (actual , expected )
1955+ if make_input is make_image_cvcuda :
1956+ image = F .cvcuda_to_tensor (image )[0 ].cpu ()
1957+ expected = F .vertical_flip (F .to_pil_image (image ))
1958+ assert_equal (actual , expected )
19081959
19091960 def _reference_vertical_flip_bounding_boxes (self , bounding_boxes : tv_tensors .BoundingBoxes ):
19101961 affine_matrix = np .array (
@@ -1956,6 +2007,10 @@ def test_keypoints_correctness(self, fn):
19562007 make_image_tensor ,
19572008 make_image_pil ,
19582009 make_image ,
2010+ pytest .param (
2011+ make_image_cvcuda ,
2012+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ),
2013+ ),
19592014 make_bounding_boxes ,
19602015 make_segmentation_mask ,
19612016 make_video ,
@@ -1965,11 +2020,8 @@ def test_keypoints_correctness(self, fn):
19652020 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
19662021 def test_transform_noop (self , make_input , device ):
19672022 input = make_input (device = device )
1968-
19692023 transform = transforms .RandomVerticalFlip (p = 0 )
1970-
19712024 output = transform (input )
1972-
19732025 assert_equal (output , input )
19742026
19752027
@@ -6826,7 +6878,7 @@ def test_functional_and_transform(self, dtype, device, color_space, batch_dims,
68266878 assert F .get_size (output ) == F .get_size (input_tensor )
68276879
68286880 def test_functional_error (self ):
6829- with pytest .raises (TypeError , match = "cvcuda_img should be `cvcuda.Tensor`" ):
6881+ with pytest .raises (TypeError , match = r "cvcuda_img should be `` cvcuda\ .Tensor``\. Got .+\. " ):
68306882 F .cvcuda_to_tensor (object ())
68316883
68326884
0 commit comments