@@ -6357,7 +6357,17 @@ class TestRgbToGrayscale:
63576357 def test_kernel_image (self , dtype , device ):
63586358 check_kernel (F .rgb_to_grayscale_image , make_image (dtype = dtype , device = device ))
63596359
6360- @pytest .mark .parametrize ("make_input" , [make_image_tensor , make_image_pil , make_image ])
6360+ @pytest .mark .parametrize (
6361+ "make_input" ,
6362+ [
6363+ make_image_tensor ,
6364+ make_image_pil ,
6365+ make_image ,
6366+ pytest .param (
6367+ make_image_cvcuda , marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA not available" )
6368+ ),
6369+ ],
6370+ )
63616371 def test_functional (self , make_input ):
63626372 check_functional (F .rgb_to_grayscale , make_input ())
63636373
@@ -6367,23 +6377,62 @@ def test_functional(self, make_input):
63676377 (F .rgb_to_grayscale_image , torch .Tensor ),
63686378 (F ._color ._rgb_to_grayscale_image_pil , PIL .Image .Image ),
63696379 (F .rgb_to_grayscale_image , tv_tensors .Image ),
6380+ pytest .param (
6381+ F ._color ._rgb_to_grayscale_cvcuda ,
6382+ "cvcuda.Tensor" ,
6383+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA not available" ),
6384+ ),
63706385 ],
63716386 )
63726387 def test_functional_signature (self , kernel , input_type ):
6388+ if input_type == "cvcuda.Tensor" :
6389+ input_type = _import_cvcuda ().Tensor
63736390 check_functional_kernel_signature_match (F .rgb_to_grayscale , kernel = kernel , input_type = input_type )
63746391
63756392 @pytest .mark .parametrize ("transform" , [transforms .Grayscale (), transforms .RandomGrayscale (p = 1 )])
6376- @pytest .mark .parametrize ("make_input" , [make_image_tensor , make_image_pil , make_image ])
6393+ @pytest .mark .parametrize (
6394+ "make_input" ,
6395+ [
6396+ make_image_tensor ,
6397+ make_image_pil ,
6398+ make_image ,
6399+ pytest .param (
6400+ make_image_cvcuda , marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA not available" )
6401+ ),
6402+ ],
6403+ )
63776404 def test_transform (self , transform , make_input ):
6405+ if make_input is make_image_cvcuda and isinstance (transform , transforms .RandomGrayscale ):
6406+ pytest .skip ("CV-CUDA does not support RandomGrayscale, will have num_output_channels == 3" )
63786407 check_transform (transform , make_input ())
63796408
63806409 @pytest .mark .parametrize ("num_output_channels" , [1 , 3 ])
63816410 @pytest .mark .parametrize ("color_space" , ["RGB" , "GRAY" ])
6411+ @pytest .mark .parametrize (
6412+ "make_input" ,
6413+ [
6414+ make_image ,
6415+ pytest .param (
6416+ make_image_cvcuda , marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA not available" )
6417+ ),
6418+ ],
6419+ )
63826420 @pytest .mark .parametrize ("fn" , [F .rgb_to_grayscale , transform_cls_to_functional (transforms .Grayscale )])
6383- def test_image_correctness (self , num_output_channels , color_space , fn ):
6384- image = make_image (dtype = torch .uint8 , device = "cpu" , color_space = color_space )
6421+ def test_image_correctness (self , num_output_channels , color_space , make_input , fn ):
6422+ if make_input is make_image_cvcuda and num_output_channels == 3 :
6423+ pytest .skip ("CV-CUDA does not support num_output_channels == 3" )
6424+
6425+ image = make_input (dtype = torch .uint8 , device = "cpu" , color_space = color_space )
63856426
63866427 actual = fn (image , num_output_channels = num_output_channels )
6428+
6429+ if make_input is make_image_cvcuda :
6430+ actual = F .cvcuda_to_tensor (actual ).to (device = "cpu" )
6431+ actual = actual .squeeze (0 )
6432+ # drop the batch dimension
6433+ image = F .cvcuda_to_tensor (image ).to (device = "cpu" )
6434+ image = image .squeeze (0 )
6435+
63876436 expected = F .to_image (F .rgb_to_grayscale (F .to_pil_image (image ), num_output_channels = num_output_channels ))
63886437
63896438 assert_equal (actual , expected , rtol = 0 , atol = 1 )
@@ -6421,7 +6470,17 @@ class TestGrayscaleToRgb:
64216470 def test_kernel_image (self , dtype , device ):
64226471 check_kernel (F .grayscale_to_rgb_image , make_image (dtype = dtype , device = device ))
64236472
6424- @pytest .mark .parametrize ("make_input" , [make_image_tensor , make_image_pil , make_image ])
6473+ @pytest .mark .parametrize (
6474+ "make_input" ,
6475+ [
6476+ make_image_tensor ,
6477+ make_image_pil ,
6478+ make_image ,
6479+ pytest .param (
6480+ make_image_cvcuda , marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA not available" )
6481+ ),
6482+ ],
6483+ )
64256484 def test_functional (self , make_input ):
64266485 check_functional (F .grayscale_to_rgb , make_input ())
64276486
@@ -6431,20 +6490,54 @@ def test_functional(self, make_input):
64316490 (F .rgb_to_grayscale_image , torch .Tensor ),
64326491 (F ._color ._rgb_to_grayscale_image_pil , PIL .Image .Image ),
64336492 (F .rgb_to_grayscale_image , tv_tensors .Image ),
6493+ pytest .param (
6494+ F ._color ._rgb_to_grayscale_cvcuda ,
6495+ "cvcuda.Tensor" ,
6496+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA not available" ),
6497+ ),
64346498 ],
64356499 )
64366500 def test_functional_signature (self , kernel , input_type ):
6501+ if input_type == "cvcuda.Tensor" :
6502+ input_type = _import_cvcuda ().Tensor
64376503 check_functional_kernel_signature_match (F .grayscale_to_rgb , kernel = kernel , input_type = input_type )
64386504
6439- @pytest .mark .parametrize ("make_input" , [make_image_tensor , make_image_pil , make_image ])
6505+ @pytest .mark .parametrize (
6506+ "make_input" ,
6507+ [
6508+ make_image_tensor ,
6509+ make_image_pil ,
6510+ make_image ,
6511+ pytest .param (
6512+ make_image_cvcuda , marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA not available" )
6513+ ),
6514+ ],
6515+ )
64406516 def test_transform (self , make_input ):
64416517 check_transform (transforms .RGB (), make_input (color_space = "GRAY" ))
64426518
6519+ @pytest .mark .parametrize (
6520+ "make_input" ,
6521+ [
6522+ make_image ,
6523+ pytest .param (
6524+ make_image_cvcuda , marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "CVCUDA not available" )
6525+ ),
6526+ ],
6527+ )
64436528 @pytest .mark .parametrize ("fn" , [F .grayscale_to_rgb , transform_cls_to_functional (transforms .RGB )])
6444- def test_image_correctness (self , fn ):
6445- image = make_image (dtype = torch .uint8 , device = "cpu" , color_space = "GRAY" )
6529+ def test_image_correctness (self , make_input , fn ):
6530+ image = make_input (dtype = torch .uint8 , device = "cpu" , color_space = "GRAY" )
64466531
64476532 actual = fn (image )
6533+
6534+ if make_input is make_image_cvcuda :
6535+ actual = F .cvcuda_to_tensor (actual ).to (device = "cpu" )
6536+ actual = actual .squeeze (0 )
6537+ # drop the batch dimension
6538+ image = F .cvcuda_to_tensor (image ).to (device = "cpu" )
6539+ image = image .squeeze (0 )
6540+
64486541 expected = F .to_image (F .grayscale_to_rgb (F .to_pil_image (image )))
64496542
64506543 assert_equal (actual , expected , rtol = 0 , atol = 1 )
0 commit comments