3737 make_video ,
3838 make_video_tensor ,
3939 needs_cuda ,
40+ needs_cvcuda ,
4041 set_rng_seed ,
4142)
4243
5253from torchvision .transforms .v2 import functional as F
5354from torchvision .transforms .v2 ._utils import check_type , is_pure_tensor
5455from torchvision .transforms .v2 .functional ._geometry import _get_perspective_coeffs , _parallelogram_to_bounding_boxes
55- from torchvision .transforms .v2 .functional ._utils import (
56- _get_kernel ,
57- _import_cvcuda ,
58- _is_cvcuda_available ,
59- _register_kernel_internal ,
60- )
61-
56+ from torchvision .transforms .v2 .functional ._utils import _get_kernel , _import_cvcuda , _register_kernel_internal
6257
63- CVCUDA_AVAILABLE = _is_cvcuda_available ()
64- if CVCUDA_AVAILABLE :
65- cvcuda = _import_cvcuda ()
6658
6759# turns all warnings into errors for this module
6860pytestmark = [pytest .mark .filterwarnings ("error" )]
@@ -1242,7 +1234,7 @@ def test_kernel_video(self):
12421234 make_image ,
12431235 pytest .param (
12441236 make_image_cvcuda ,
1245- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
1237+ marks = pytest .mark .needs_cvcuda ,
12461238 ),
12471239 make_bounding_boxes ,
12481240 make_segmentation_mask ,
@@ -1262,7 +1254,7 @@ def test_functional(self, make_input):
12621254 pytest .param (
12631255 F ._geometry ._horizontal_flip_image_cvcuda ,
12641256 None ,
1265- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
1257+ marks = pytest .mark .needs_cvcuda ,
12661258 ),
12671259 (F .horizontal_flip_bounding_boxes , tv_tensors .BoundingBoxes ),
12681260 (F .horizontal_flip_mask , tv_tensors .Mask ),
@@ -1283,7 +1275,7 @@ def test_functional_signature(self, kernel, input_type):
12831275 make_image ,
12841276 pytest .param (
12851277 make_image_cvcuda ,
1286- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
1278+ marks = pytest .mark .needs_cvcuda ,
12871279 ),
12881280 make_bounding_boxes ,
12891281 make_segmentation_mask ,
@@ -1304,7 +1296,7 @@ def test_transform(self, make_input, device):
13041296 make_image ,
13051297 pytest .param (
13061298 make_image_cvcuda ,
1307- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
1299+ marks = pytest .mark .needs_cvcuda ,
13081300 ),
13091301 ],
13101302 )
@@ -1372,7 +1364,7 @@ def test_keypoints_correctness(self, fn):
13721364 make_image ,
13731365 pytest .param (
13741366 make_image_cvcuda ,
1375- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
1367+ marks = pytest .mark .needs_cvcuda ,
13761368 ),
13771369 make_bounding_boxes ,
13781370 make_segmentation_mask ,
@@ -1884,7 +1876,7 @@ def test_kernel_video(self):
18841876 make_image ,
18851877 pytest .param (
18861878 make_image_cvcuda ,
1887- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
1879+ marks = pytest .mark .needs_cvcuda ,
18881880 ),
18891881 make_bounding_boxes ,
18901882 make_segmentation_mask ,
@@ -1904,7 +1896,7 @@ def test_functional(self, make_input):
19041896 pytest .param (
19051897 F ._geometry ._vertical_flip_image_cvcuda ,
19061898 None ,
1907- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
1899+ marks = pytest .mark .needs_cvcuda ,
19081900 ),
19091901 (F .vertical_flip_bounding_boxes , tv_tensors .BoundingBoxes ),
19101902 (F .vertical_flip_mask , tv_tensors .Mask ),
@@ -1925,7 +1917,7 @@ def test_functional_signature(self, kernel, input_type):
19251917 make_image ,
19261918 pytest .param (
19271919 make_image_cvcuda ,
1928- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
1920+ marks = pytest .mark .needs_cvcuda ,
19291921 ),
19301922 make_bounding_boxes ,
19311923 make_segmentation_mask ,
@@ -1944,7 +1936,7 @@ def test_transform(self, make_input, device):
19441936 make_image ,
19451937 pytest .param (
19461938 make_image_cvcuda ,
1947- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
1939+ marks = pytest .mark .needs_cvcuda ,
19481940 ),
19491941 ],
19501942 )
@@ -2008,7 +2000,7 @@ def test_keypoints_correctness(self, fn):
20082000 make_image ,
20092001 pytest .param (
20102002 make_image_cvcuda ,
2011- marks = pytest .mark .skipif ( not CVCUDA_AVAILABLE , reason = "CVCUDA is not available" ) ,
2003+ marks = pytest .mark .needs_cvcuda ,
20122004 ),
20132005 make_bounding_boxes ,
20142006 make_segmentation_mask ,
@@ -6794,8 +6786,7 @@ def test_functional_error(self):
67946786 F .pil_to_tensor (object ())
67956787
67966788
6797- @pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "test requires CVCUDA" )
6798- @needs_cuda
6789+ @needs_cvcuda
67996790class TestToCVCUDATensor :
68006791 @pytest .mark .parametrize ("image_type" , (torch .Tensor , tv_tensors .Image ))
68016792 @pytest .mark .parametrize ("dtype" , [torch .uint8 , torch .uint16 , torch .float32 , torch .float64 ])
@@ -6813,7 +6804,7 @@ def test_functional_and_transform(self, image_type, dtype, device, color_space,
68136804 assert is_pure_tensor (image )
68146805 output = fn (image )
68156806
6816- assert isinstance (output , cvcuda .Tensor )
6807+ assert isinstance (output , _import_cvcuda () .Tensor )
68176808 assert F .get_size (output ) == F .get_size (image )
68186809 assert output is not None
68196810
@@ -6856,9 +6847,8 @@ def test_round_trip(self, dtype, device, color_space, batch_size):
68566847 assert result_tensor .shape [0 ] == batch_size
68576848
68586849
6859- @pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "test requires CVCUDA" )
6860- @needs_cuda
6861- class TestCVDUDAToTensor :
6850+ @needs_cvcuda
6851+ class TestCVCUDAToTensor :
68626852 @pytest .mark .parametrize ("dtype" , [torch .uint8 , torch .uint16 , torch .float32 , torch .float64 ])
68636853 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
68646854 @pytest .mark .parametrize ("color_space" , ["RGB" , "GRAY" ])
0 commit comments