@@ -6743,27 +6743,6 @@ def test_functional_error(self):
67436743class TestToNVCVTensor :
67446744 """Tests for to_nvcv_tensor function following patterns from TestToPil"""
67456745
6746- def test_1_channel_uint8_tensor_to_nvcv_tensor (self ):
6747- img_data = torch .randint (0 , 256 , (1 , 4 , 4 ), dtype = torch .uint8 , device = "cuda" )
6748- nvcv_img = F .to_nvcv_tensor (img_data )
6749- # Check that the conversion succeeded and format is correct
6750- assert nvcv_img is not None
6751-
6752- def test_1_channel_int16_tensor_to_nvcv_tensor (self ):
6753- img_data = torch .randint (0 , 256 , (1 , 4 , 4 ), dtype = torch .int16 , device = "cuda" )
6754- nvcv_img = F .to_nvcv_tensor (img_data )
6755- assert nvcv_img is not None
6756-
6757- def test_1_channel_int32_tensor_to_nvcv_tensor (self ):
6758- img_data = torch .randint (0 , 256 , (1 , 4 , 4 ), dtype = torch .int32 , device = "cuda" )
6759- nvcv_img = F .to_nvcv_tensor (img_data )
6760- assert nvcv_img is not None
6761-
6762- def test_1_channel_float32_tensor_to_nvcv_tensor (self ):
6763- img_data = torch .rand (1 , 4 , 4 , device = "cuda" )
6764- nvcv_img = F .to_nvcv_tensor (img_data )
6765- assert nvcv_img is not None
6766-
67676746 def test_3_channel_uint8_tensor_to_nvcv_tensor (self ):
67686747 img_data = torch .randint (0 , 256 , (3 , 4 , 4 ), dtype = torch .uint8 , device = "cuda" )
67696748 nvcv_img = F .to_nvcv_tensor (img_data )
@@ -6775,19 +6754,19 @@ def test_3_channel_float32_tensor_to_nvcv_tensor(self):
67756754 assert nvcv_img is not None
67766755
67776756 def test_unsupported_num_channels (self ):
6778- # Test 2 -channel image (CHW format: 2 channels x 5 height x 5 width )
6779- img_data = torch .rand (2 , 5 , 5 , device = "cuda" )
6780- with pytest .raises (ValueError , match = "Only 1 and 3 channel images are supported" ):
6757+ # Test 1 -channel image (not supported )
6758+ img_data = torch .rand (1 , 5 , 5 , device = "cuda" )
6759+ with pytest .raises (ValueError , match = "Only 3- channel RGB images are supported" ):
67816760 F .to_nvcv_tensor (img_data )
67826761
6783- # Test 4 -channel image (CHW format: 4 channels x 5 height x 5 width )
6784- img_data = torch .randint ( 0 , 256 , ( 4 , 5 , 5 ), dtype = torch . uint8 , device = "cuda" )
6785- with pytest .raises (ValueError , match = "Only 1 and 3 channel images are supported" ):
6762+ # Test 2 -channel image (not supported )
6763+ img_data = torch .rand ( 2 , 5 , 5 , device = "cuda" )
6764+ with pytest .raises (ValueError , match = "Only 3- channel RGB images are supported" ):
67866765 F .to_nvcv_tensor (img_data )
67876766
6788- # Test 5 -channel image (CHW format: 5 channels x 5 height x 5 width )
6789- img_data = torch .randint (0 , 256 , (5 , 5 , 5 ), dtype = torch .uint8 , device = "cuda" )
6790- with pytest .raises (ValueError , match = "Only 1 and 3 channel images are supported" ):
6767+ # Test 4 -channel image (not supported )
6768+ img_data = torch .randint (0 , 256 , (4 , 5 , 5 ), dtype = torch .uint8 , device = "cuda" )
6769+ with pytest .raises (ValueError , match = "Only 3- channel RGB images are supported" ):
67916770 F .to_nvcv_tensor (img_data )
67926771
67936772 def test_invalid_input_type (self ):
@@ -6807,30 +6786,19 @@ def test_invalid_dimensions(self):
68076786 with pytest .raises (ValueError , match = r"pic should be 3 or 4 dimensional" ):
68086787 F .to_nvcv_tensor (torch .randint (0 , 256 , (1 , 1 , 3 , 4 , 4 ), dtype = torch .uint8 , device = "cuda" ))
68096788
6810- def test_float64_tensor_to_nvcv_tensor (self ):
6811- # Test single channel float64 (F64 format is supported)
6812- img_data = torch .rand (1 , 4 , 4 , dtype = torch .float64 , device = "cuda" )
6813- nvcv_img = F .to_nvcv_tensor (img_data )
6814- assert nvcv_img is not None
6815-
68166789 def test_float64_rgb_not_supported (self ):
68176790 # Test 3-channel float64 is NOT supported (no RGBf64 format in CV-CUDA)
68186791 img_data = torch .rand (3 , 4 , 4 , dtype = torch .float64 , device = "cuda" )
68196792 with pytest .raises (TypeError , match = r"Unsupported dtype" ):
68206793 F .to_nvcv_tensor (img_data )
68216794
6822- @pytest .mark .parametrize ("num_channels" , [1 , 3 ])
6823- @pytest .mark .parametrize ("dtype" , [torch .uint8 , torch .float32 , torch .float64 ])
6824- def test_round_trip (self , num_channels , dtype ):
6825- # Skip float64 for 3-channel (not supported by CV-CUDA)
6826- if num_channels == 3 and dtype == torch .float64 :
6827- pytest .skip ("float64 is not supported for 3-channel RGB images" )
6828-
6829- # Setup: Create a tensor in CHW format (PyTorch standard)
6795+ @pytest .mark .parametrize ("dtype" , [torch .uint8 , torch .float32 ])
6796+ def test_round_trip (self , dtype ):
6797+ # Setup: Create a 3-channel tensor in CHW format (PyTorch standard)
68306798 if dtype == torch .uint8 :
6831- original_tensor = torch .randint (0 , 256 , (num_channels , 4 , 4 ), dtype = dtype , device = "cuda" )
6799+ original_tensor = torch .randint (0 , 256 , (3 , 4 , 4 ), dtype = dtype , device = "cuda" )
68326800 else :
6833- original_tensor = torch .rand (num_channels , 4 , 4 , dtype = dtype , device = "cuda" )
6801+ original_tensor = torch .rand (3 , 4 , 4 , dtype = dtype , device = "cuda" )
68346802
68356803 # Execute: Convert to NVCV and back to tensor
68366804 # CHW -> (to_nvcv_tensor) -> NVCV NHWC -> (nvcv_to_tensor) -> CHW
@@ -6841,19 +6809,14 @@ def test_round_trip(self, num_channels, dtype):
68416809 # Use allclose for robust comparison that handles floating-point precision
68426810 assert torch .allclose (result_tensor , original_tensor , rtol = 1e-5 , atol = 1e-7 )
68436811
6844- @pytest .mark .parametrize ("num_channels" , [1 , 3 ])
6845- @pytest .mark .parametrize ("dtype" , [torch .uint8 , torch .float32 , torch .float64 ])
6812+ @pytest .mark .parametrize ("dtype" , [torch .uint8 , torch .float32 ])
68466813 @pytest .mark .parametrize ("batch_size" , [1 , 2 , 4 ])
6847- def test_round_trip_batched (self , num_channels , dtype , batch_size ):
6848- # Skip float64 for 3-channel (not supported by CV-CUDA)
6849- if num_channels == 3 and dtype == torch .float64 :
6850- pytest .skip ("float64 is not supported for 3-channel RGB images" )
6851-
6852- # Setup: Create a batched tensor in NCHW format
6814+ def test_round_trip_batched (self , dtype , batch_size ):
6815+ # Setup: Create a batched 3-channel tensor in NCHW format
68536816 if dtype == torch .uint8 :
6854- original_tensor = torch .randint (0 , 256 , (batch_size , num_channels , 4 , 4 ), dtype = dtype , device = "cuda" )
6817+ original_tensor = torch .randint (0 , 256 , (batch_size , 3 , 4 , 4 ), dtype = dtype , device = "cuda" )
68556818 else :
6856- original_tensor = torch .rand (batch_size , num_channels , 4 , 4 , dtype = dtype , device = "cuda" )
6819+ original_tensor = torch .rand (batch_size , 3 , 4 , 4 , dtype = dtype , device = "cuda" )
68576820
68586821 # Execute: Convert to NVCV and back to tensor
68596822 # NCHW -> (to_nvcv_tensor) -> NVCV NHWC -> (nvcv_to_tensor) -> NCHW
@@ -6870,7 +6833,7 @@ def test_round_trip_batched(self, num_channels, dtype, batch_size):
68706833@pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "test requires CVCUDA" )
68716834@pytest .mark .skipif (not CUDA_AVAILABLE , reason = "test requires CUDA" )
68726835class TestNVCVToTensor :
6873- @pytest .mark .parametrize ("color_space" , ["RGB" , "GRAY" ])
6836+ @pytest .mark .parametrize ("color_space" , ["RGB" ])
68746837 @pytest .mark .parametrize (
68756838 "fn" ,
68766839 [F .nvcv_to_tensor , transform_cls_to_functional (transforms .NVCVToTensor )],
0 commit comments