Skip to content

Commit f3eb9f5

Browse files
committed
update to main standards
1 parent 0379038 commit f3eb9f5

File tree

5 files changed

+15
-28
lines changed

5 files changed

+15
-28
lines changed

test/test_transforms_v2.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
assert_equal,
2626
cache,
2727
cpu_and_cuda,
28-
cvcuda_to_pil_compatible_tensor,
2928
freeze_rng_state,
3029
ignore_jit_no_profile_information_warning,
3130
make_bounding_boxes,
@@ -5473,14 +5472,14 @@ def test_functional(self, make_input):
54735472
(F.equalize_image, tv_tensors.Image),
54745473
(F.equalize_video, tv_tensors.Video),
54755474
pytest.param(
5476-
F._color._equalize_cvcuda,
5477-
"cvcuda.Tensor",
5475+
F._color._equalize_image_cvcuda,
5476+
None,
54785477
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA not available"),
54795478
),
54805479
],
54815480
)
54825481
def test_functional_signature(self, kernel, input_type):
5483-
if input_type == "cvcuda.Tensor":
5482+
if kernel is F._color._equalize_image_cvcuda:
54845483
input_type = _import_cvcuda().Tensor
54855484
check_functional_kernel_signature_match(F.equalize, kernel=kernel, input_type=input_type)
54865485

@@ -5526,7 +5525,7 @@ def test_image_correctness(self, low, high, tensor_type, fn):
55265525
actual = fn(image)
55275526

55285527
if tensor_type == "cvcuda.Tensor":
5529-
image = cvcuda_to_pil_compatible_tensor(image)
5528+
image = F.cvcuda_to_tensor(image)[0].cpu()
55305529

55315530
expected = F.to_image(F.equalize(F.to_pil_image(image)))
55325531

torchvision/transforms/v2/_color.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import torch
66
from torchvision import transforms as _transforms
77
from torchvision.transforms.v2 import functional as F, Transform
8+
from torchvision.transforms.v2.functional._utils import _is_cvcuda_available, _is_cvcuda_tensor
89

910
from ._transform import _RandomApplyTransform
1011
from ._utils import query_chw
11-
from .functional._utils import is_cvcuda_tensor
12+
13+
14+
CVCUDA_AVAILABLE = _is_cvcuda_available()
1215

1316

1417
class Grayscale(Transform):
@@ -266,7 +269,8 @@ class RandomEqualize(_RandomApplyTransform):
266269

267270
_v1_transform_cls = _transforms.RandomEqualize
268271

269-
_transformed_types = _RandomApplyTransform._transformed_types + (is_cvcuda_tensor,)
272+
if CVCUDA_AVAILABLE:
273+
_transformed_types = _RandomApplyTransform._transformed_types + (_is_cvcuda_tensor,)
270274

271275
def transform(self, inpt: Any, params: dict[str, Any]) -> Any:
272276
return self._call_kernel(F.equalize, inpt)

torchvision/transforms/v2/functional/_augment.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io
2-
from typing import TYPE_CHECKING
32

43
import PIL.Image
54

@@ -9,15 +8,7 @@
98
from torchvision.transforms.functional import pil_to_tensor, to_pil_image
109
from torchvision.utils import _log_api_usage_once
1110

12-
from ._utils import _get_kernel, _import_cvcuda, _is_cvcuda_available, _register_kernel_internal
13-
14-
15-
CVCUDA_AVAILABLE = _is_cvcuda_available()
16-
17-
if TYPE_CHECKING:
18-
import cvcuda # type: ignore[import-not-found]
19-
if CVCUDA_AVAILABLE:
20-
cvcuda = _import_cvcuda() # noqa: F811
11+
from ._utils import _get_kernel, _register_kernel_internal
2112

2213

2314
def erase(

torchvision/transforms/v2/functional/_color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,15 @@ def equalize_video(video: torch.Tensor) -> torch.Tensor:
659659
return equalize_image(video)
660660

661661

662-
def _equalize_cvcuda(
662+
def _equalize_image_cvcuda(
663663
image: "cvcuda.Tensor",
664664
) -> "cvcuda.Tensor":
665665
cvcuda = _import_cvcuda()
666666
return cvcuda.histogrameq(image, dtype=image.dtype)
667667

668668

669669
if CVCUDA_AVAILABLE:
670-
_register_kernel_internal(equalize, _import_cvcuda().Tensor)(_equalize_cvcuda)
670+
_register_kernel_internal(equalize, _import_cvcuda().Tensor)(_equalize_image_cvcuda)
671671

672672

673673
def invert(inpt: torch.Tensor) -> torch.Tensor:

torchvision/transforms/v2/functional/_misc.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import math
2-
from typing import Optional, TYPE_CHECKING
2+
from typing import Optional
33

44
import PIL.Image
55
import torch
@@ -13,14 +13,7 @@
1313

1414
from ._meta import _convert_bounding_box_format
1515

16-
from ._utils import _get_kernel, _import_cvcuda, _is_cvcuda_available, _register_kernel_internal, is_pure_tensor
17-
18-
CVCUDA_AVAILABLE = _is_cvcuda_available()
19-
20-
if TYPE_CHECKING:
21-
import cvcuda # type: ignore[import-not-found]
22-
if CVCUDA_AVAILABLE:
23-
cvcuda = _import_cvcuda() # noqa: F811
16+
from ._utils import _get_kernel, _register_kernel_internal, is_pure_tensor
2417

2518

2619
def normalize(

0 commit comments

Comments
 (0)