Skip to content

Commit 8564f0a

Browse files
committed
update to main standards
1 parent 2c68fc3 commit 8564f0a

File tree

4 files changed

+28
-45
lines changed

4 files changed

+28
-45
lines changed

test/test_transforms_v2.py

Lines changed: 17 additions & 18 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,
@@ -2846,14 +2845,14 @@ def test_functional(self, make_input):
28462845
(F.adjust_brightness_image, tv_tensors.Image),
28472846
(F.adjust_brightness_video, tv_tensors.Video),
28482847
pytest.param(
2849-
F._color._adjust_brightness_cvcuda,
2850-
"cvcuda.Tensor",
2848+
F._color._adjust_brightness_image_cvcuda,
2849+
None,
28512850
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA not available"),
28522851
),
28532852
],
28542853
)
28552854
def test_functional_signature(self, kernel, input_type):
2856-
if input_type == "cvcuda.Tensor":
2855+
if kernel is F._color._adjust_brightness_image_cvcuda:
28572856
input_type = _import_cvcuda().Tensor
28582857
check_functional_kernel_signature_match(F.adjust_brightness, kernel=kernel, input_type=input_type)
28592858

@@ -2873,7 +2872,7 @@ def test_image_correctness(self, make_input, brightness_factor):
28732872
actual = F.adjust_brightness(image, brightness_factor=brightness_factor)
28742873

28752874
if make_input is make_image_cvcuda:
2876-
image = cvcuda_to_pil_compatible_tensor(image)
2875+
image = F.cvcuda_to_tensor(image)[0].cpu()
28772876

28782877
expected = F.to_image(F.adjust_brightness(F.to_pil_image(image), brightness_factor=brightness_factor))
28792878

@@ -6111,14 +6110,14 @@ def test_functional(self, make_input):
61116110
(F.adjust_contrast_image, tv_tensors.Image),
61126111
(F.adjust_contrast_video, tv_tensors.Video),
61136112
pytest.param(
6114-
F._color._adjust_contrast_cvcuda,
6115-
"cvcuda.Tensor",
6113+
F._color._adjust_contrast_image_cvcuda,
6114+
None,
61166115
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA not available"),
61176116
),
61186117
],
61196118
)
61206119
def test_functional_signature(self, kernel, input_type):
6121-
if input_type == "cvcuda.Tensor":
6120+
if kernel is F._color._adjust_contrast_image_cvcuda:
61226121
input_type = _import_cvcuda().Tensor
61236122
check_functional_kernel_signature_match(F.adjust_contrast, kernel=kernel, input_type=input_type)
61246123

@@ -6145,7 +6144,7 @@ def test_correctness_image(self, make_input, contrast_factor):
61456144
actual = F.adjust_contrast(image, contrast_factor=contrast_factor)
61466145

61476146
if make_input is make_image_cvcuda:
6148-
image = cvcuda_to_pil_compatible_tensor(image)
6147+
image = F.cvcuda_to_tensor(image)[0].cpu()
61496148

61506149
expected = F.to_image(F.adjust_contrast(F.to_pil_image(image), contrast_factor=contrast_factor))
61516150

@@ -6224,14 +6223,14 @@ def test_functional(self, make_input):
62246223
(F.adjust_hue_image, tv_tensors.Image),
62256224
(F.adjust_hue_video, tv_tensors.Video),
62266225
pytest.param(
6227-
F._color._adjust_hue_cvcuda,
6228-
"cvcuda.Tensor",
6226+
F._color._adjust_hue_image_cvcuda,
6227+
None,
62296228
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA not available"),
62306229
),
62316230
],
62326231
)
62336232
def test_functional_signature(self, kernel, input_type):
6234-
if input_type == "cvcuda.Tensor":
6233+
if kernel is F._color._adjust_hue_image_cvcuda:
62356234
input_type = _import_cvcuda().Tensor
62366235
check_functional_kernel_signature_match(F.adjust_hue, kernel=kernel, input_type=input_type)
62376236

@@ -6259,8 +6258,8 @@ def test_correctness_image(self, make_input, hue_factor):
62596258
actual = F.adjust_hue(image, hue_factor=hue_factor)
62606259

62616260
if make_input is make_image_cvcuda:
6262-
actual = cvcuda_to_pil_compatible_tensor(actual)
6263-
image = cvcuda_to_pil_compatible_tensor(image)
6261+
actual = F.cvcuda_to_tensor(actual)[0].cpu()
6262+
image = F.cvcuda_to_tensor(image)[0].cpu()
62646263

62656264
expected = F.to_image(F.adjust_hue(F.to_pil_image(image), hue_factor=hue_factor))
62666265

@@ -6300,14 +6299,14 @@ def test_functional(self, make_input):
63006299
(F.adjust_saturation_image, tv_tensors.Image),
63016300
(F.adjust_saturation_video, tv_tensors.Video),
63026301
pytest.param(
6303-
F._color._adjust_saturation_cvcuda,
6304-
"cvcuda.Tensor",
6302+
F._color._adjust_saturation_image_cvcuda,
6303+
None,
63056304
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA not available"),
63066305
),
63076306
],
63086307
)
63096308
def test_functional_signature(self, kernel, input_type):
6310-
if input_type == "cvcuda.Tensor":
6309+
if kernel is F._color._adjust_saturation_image_cvcuda:
63116310
input_type = _import_cvcuda().Tensor
63126311
check_functional_kernel_signature_match(F.adjust_saturation, kernel=kernel, input_type=input_type)
63136312

@@ -6335,7 +6334,7 @@ def test_correctness_image(self, make_input, color_space, saturation_factor):
63356334
actual = F.adjust_saturation(image, saturation_factor=saturation_factor)
63366335

63376336
if make_input is make_image_cvcuda:
6338-
image = cvcuda_to_pil_compatible_tensor(image)
6337+
image = F.cvcuda_to_tensor(image)[0].cpu()
63396338

63406339
expected = F.to_image(F.adjust_saturation(F.to_pil_image(image), saturation_factor=saturation_factor))
63416340

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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def adjust_brightness_video(video: torch.Tensor, brightness_factor: float) -> to
145145
return adjust_brightness_image(video, brightness_factor=brightness_factor)
146146

147147

148-
def _adjust_brightness_cvcuda(image: "cvcuda.Tensor", brightness_factor: float) -> "cvcuda.Tensor":
148+
def _adjust_brightness_image_cvcuda(image: "cvcuda.Tensor", brightness_factor: float) -> "cvcuda.Tensor":
149149
cvcuda = _import_cvcuda()
150150

151151
cv_brightness = torch.tensor([brightness_factor], dtype=torch.float32, device="cuda")
@@ -155,7 +155,7 @@ def _adjust_brightness_cvcuda(image: "cvcuda.Tensor", brightness_factor: float)
155155

156156

157157
if CVCUDA_AVAILABLE:
158-
_register_kernel_internal(adjust_brightness, _import_cvcuda().Tensor)(_adjust_brightness_cvcuda)
158+
_register_kernel_internal(adjust_brightness, _import_cvcuda().Tensor)(_adjust_brightness_image_cvcuda)
159159

160160

161161
def adjust_saturation(inpt: torch.Tensor, saturation_factor: float) -> torch.Tensor:
@@ -197,7 +197,7 @@ def adjust_saturation_video(video: torch.Tensor, saturation_factor: float) -> to
197197
return adjust_saturation_image(video, saturation_factor=saturation_factor)
198198

199199

200-
def _adjust_saturation_cvcuda(image: "cvcuda.Tensor", saturation_factor: float) -> "cvcuda.Tensor":
200+
def _adjust_saturation_image_cvcuda(image: "cvcuda.Tensor", saturation_factor: float) -> "cvcuda.Tensor":
201201
if saturation_factor < 0:
202202
raise ValueError(f"saturation_factor ({saturation_factor}) is not non-negative.")
203203

@@ -225,7 +225,7 @@ def _adjust_saturation_cvcuda(image: "cvcuda.Tensor", saturation_factor: float)
225225

226226

227227
if CVCUDA_AVAILABLE:
228-
_register_kernel_internal(adjust_saturation, cvcuda.Tensor)(_adjust_saturation_cvcuda)
228+
_register_kernel_internal(adjust_saturation, cvcuda.Tensor)(_adjust_saturation_image_cvcuda)
229229

230230

231231
def adjust_contrast(inpt: torch.Tensor, contrast_factor: float) -> torch.Tensor:
@@ -267,7 +267,7 @@ def adjust_contrast_video(video: torch.Tensor, contrast_factor: float) -> torch.
267267
return adjust_contrast_image(video, contrast_factor=contrast_factor)
268268

269269

270-
def _adjust_contrast_cvcuda(image: "cvcuda.Tensor", contrast_factor: float) -> "cvcuda.Tensor":
270+
def _adjust_contrast_image_cvcuda(image: "cvcuda.Tensor", contrast_factor: float) -> "cvcuda.Tensor":
271271
cvcuda = _import_cvcuda()
272272

273273
if contrast_factor < 0:
@@ -294,7 +294,7 @@ def _adjust_contrast_cvcuda(image: "cvcuda.Tensor", contrast_factor: float) -> "
294294

295295

296296
if CVCUDA_AVAILABLE:
297-
_register_kernel_internal(adjust_contrast, _import_cvcuda().Tensor)(_adjust_contrast_cvcuda)
297+
_register_kernel_internal(adjust_contrast, _import_cvcuda().Tensor)(_adjust_contrast_image_cvcuda)
298298

299299

300300
def adjust_sharpness(inpt: torch.Tensor, sharpness_factor: float) -> torch.Tensor:
@@ -488,7 +488,7 @@ def adjust_hue_video(video: torch.Tensor, hue_factor: float) -> torch.Tensor:
488488
return adjust_hue_image(video, hue_factor=hue_factor)
489489

490490

491-
def _adjust_hue_cvcuda(image: "cvcuda.Tensor", hue_factor: float) -> "cvcuda.Tensor":
491+
def _adjust_hue_image_cvcuda(image: "cvcuda.Tensor", hue_factor: float) -> "cvcuda.Tensor":
492492
cvcuda = _import_cvcuda()
493493

494494
if not (-0.5 <= hue_factor <= 0.5):
@@ -513,7 +513,7 @@ def _adjust_hue_cvcuda(image: "cvcuda.Tensor", hue_factor: float) -> "cvcuda.Ten
513513

514514

515515
if CVCUDA_AVAILABLE:
516-
_register_kernel_internal(adjust_hue, _import_cvcuda().Tensor)(_adjust_hue_cvcuda)
516+
_register_kernel_internal(adjust_hue, _import_cvcuda().Tensor)(_adjust_hue_image_cvcuda)
517517

518518

519519
def adjust_gamma(inpt: torch.Tensor, gamma: float, gain: float = 1) -> 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)