@@ -3506,6 +3506,9 @@ def test_kernel_video(self):
35063506 make_segmentation_mask ,
35073507 make_video ,
35083508 make_keypoints ,
3509+ pytest .param (
3510+ make_image_cvcuda , marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "test requires CVCUDA" )
3511+ ),
35093512 ],
35103513 )
35113514 def test_functional (self , make_input ):
@@ -3521,6 +3524,11 @@ def test_functional(self, make_input):
35213524 (F .crop_mask , tv_tensors .Mask ),
35223525 (F .crop_video , tv_tensors .Video ),
35233526 (F .crop_keypoints , tv_tensors .KeyPoints ),
3527+ pytest .param (
3528+ F ._geometry ._crop_cvcuda ,
3529+ _import_cvcuda ().Tensor ,
3530+ marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "test requires CVCUDA" ),
3531+ ),
35243532 ],
35253533 )
35263534 def test_functional_signature (self , kernel , input_type ):
@@ -3549,15 +3557,18 @@ def test_functional_image_correctness(self, kwargs):
35493557 make_segmentation_mask ,
35503558 make_video ,
35513559 make_keypoints ,
3560+ pytest .param (
3561+ make_image_cvcuda , marks = pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "test requires CVCUDA" )
3562+ ),
35523563 ],
35533564 )
35543565 def test_transform (self , param , value , make_input ):
3555- input = make_input (self .INPUT_SIZE )
3566+ input_data = make_input (self .INPUT_SIZE )
35563567
35573568 check_sample_input = True
35583569 if param == "fill" :
35593570 if isinstance (value , (tuple , list )):
3560- if isinstance (input , tv_tensors .Mask ):
3571+ if isinstance (input_data , tv_tensors .Mask ):
35613572 pytest .skip ("F.pad_mask doesn't support non-scalar fill." )
35623573 else :
35633574 check_sample_input = False
@@ -3566,14 +3577,14 @@ def test_transform(self, param, value, make_input):
35663577 # 1. size is required
35673578 # 2. the fill parameter only has an affect if we need padding
35683579 size = [s + 4 for s in self .INPUT_SIZE ],
3569- fill = adapt_fill (value , dtype = input .dtype if isinstance (input , torch .Tensor ) else torch .uint8 ),
3580+ fill = adapt_fill (value , dtype = input_data .dtype if isinstance (input_data , torch .Tensor ) else torch .uint8 ),
35703581 )
35713582 else :
35723583 kwargs = {param : value }
35733584
35743585 check_transform (
35753586 transforms .RandomCrop (** kwargs , pad_if_needed = True ),
3576- input ,
3587+ input_data ,
35773588 check_v1_compatibility = param != "fill" or isinstance (value , (int , float )),
35783589 check_sample_input = check_sample_input ,
35793590 )
@@ -3637,6 +3648,31 @@ def test_transform_image_correctness(self, param, value, seed):
36373648
36383649 assert_equal (actual , expected )
36393650
3651+ @pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "test requires CVCUDA" )
3652+ @pytest .mark .parametrize ("size" , [(10 , 5 ), (25 , 15 ), (25 , 5 ), (10 , 15 ), (10 , 10 )])
3653+ @pytest .mark .parametrize ("seed" , list (range (5 )))
3654+ def test_transform_cvcuda_correctness (self , size , seed ):
3655+ pad_if_needed = False
3656+ if size [0 ] > self .INPUT_SIZE [0 ] or size [1 ] > self .INPUT_SIZE [1 ]:
3657+ pad_if_needed = True
3658+ transform = transforms .RandomCrop (size , pad_if_needed = pad_if_needed )
3659+
3660+ image = make_image (size = self .INPUT_SIZE , batch_dims = (1 ,), device = "cuda" )
3661+ cv_image = F .to_cvcuda_tensor (image )
3662+
3663+ with freeze_rng_state ():
3664+ torch .manual_seed (seed )
3665+ actual = transform (cv_image )
3666+
3667+ torch .manual_seed (seed )
3668+ expected = transform (image )
3669+
3670+ if not pad_if_needed :
3671+ torch .testing .assert_close (F .cvcuda_to_tensor (actual ), expected , rtol = 0 , atol = 0 )
3672+ else :
3673+ # if padding is requied, CV-CUDA will always fill with zeros
3674+ torch .testing .assert_close (F .cvcuda_to_tensor (actual ), expected , rtol = 0 , atol = get_max_value (image .dtype ))
3675+
36403676 def _reference_crop_bounding_boxes (self , bounding_boxes , * , top , left , height , width ):
36413677 affine_matrix = np .array (
36423678 [
@@ -3765,25 +3801,6 @@ def test_errors(self):
37653801 transforms .RandomCrop ([10 , 12 ], padding = 1 , padding_mode = "abc" )
37663802
37673803
3768- @pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "cvcuda not available" )
3769- @needs_cuda
3770- class TestCropCVCUDA :
3771- def test_functional (self ):
3772- check_functional (
3773- F .crop , make_image_cvcuda (TestCrop .INPUT_SIZE , batch_dims = (1 ,)), ** TestCrop .MINIMAL_CROP_KWARGS
3774- )
3775-
3776- def test_functional_signature (self ):
3777- check_functional_kernel_signature_match (F .crop , kernel = F .crop_cvcuda , input_type = cvcuda .Tensor )
3778-
3779- @pytest .mark .parametrize ("size" , [(10 , 5 ), (25 , 15 ), (25 , 5 ), (10 , 15 )])
3780- def test_functional_correctness (self , size ):
3781- image = make_image_cvcuda (TestCrop .INPUT_SIZE , batch_dims = (1 ,))
3782- actual = F .crop (image , 0 , 0 , * size )
3783- expected = F .crop (F .cvcuda_to_tensor (image ), 0 , 0 , * size )
3784- assert_equal (F .cvcuda_to_tensor (actual ), expected )
3785-
3786-
37873804class TestErase :
37883805 INPUT_SIZE = (17 , 11 )
37893806 FUNCTIONAL_KWARGS = dict (
0 commit comments