Skip to content

Commit e2b0b3d

Browse files
committed
update to new setup from PR reviews
1 parent c799674 commit e2b0b3d

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

test/test_transforms_v2.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4728,7 +4728,9 @@ def test_kernel_video(self):
47284728
make_segmentation_mask,
47294729
make_video,
47304730
make_keypoints,
4731-
make_image_cvcuda,
4731+
pytest.param(
4732+
make_image_cvcuda, marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="test requires CVCUDA")
4733+
),
47324734
],
47334735
)
47344736
def test_functional(self, make_input):
@@ -4769,7 +4771,9 @@ def test_functional_signature(self, kernel, input_type):
47694771
make_segmentation_mask,
47704772
make_video,
47714773
make_keypoints,
4772-
make_image_cvcuda,
4774+
pytest.param(
4775+
make_image_cvcuda, marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="test requires CVCUDA")
4776+
),
47734777
],
47744778
)
47754779
def test_transform(self, make_input):
@@ -4794,26 +4798,15 @@ def test_transform_errors(self):
47944798
with pytest.raises(ValueError, match="Padding mode should be either"):
47954799
transforms.Pad(12, padding_mode="abc")
47964800

4797-
@pytest.mark.parametrize("padding", CORRECTNESS_PADDINGS)
47984801
@pytest.mark.parametrize(
4799-
("padding_mode", "fill"),
4802+
"make_input",
48004803
[
4801-
*[("constant", fill) for fill in CORRECTNESS_FILLS],
4802-
*[(padding_mode, None) for padding_mode in ["symmetric", "edge", "reflect"]],
4804+
make_image,
4805+
pytest.param(
4806+
make_image_cvcuda, marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="test requires CVCUDA")
4807+
),
48034808
],
48044809
)
4805-
@pytest.mark.parametrize("fn", [F.pad, transform_cls_to_functional(transforms.Pad)])
4806-
def test_image_correctness(self, padding, padding_mode, fill, fn):
4807-
image = make_image(dtype=torch.uint8, device="cpu")
4808-
4809-
fill = adapt_fill(fill, dtype=torch.uint8)
4810-
4811-
actual = fn(image, padding=padding, padding_mode=padding_mode, fill=fill)
4812-
expected = F.to_image(F.pad(F.to_pil_image(image), padding=padding, padding_mode=padding_mode, fill=fill))
4813-
4814-
assert_equal(actual, expected)
4815-
4816-
@pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="test requires CVCUDA")
48174810
@pytest.mark.parametrize("padding", CORRECTNESS_PADDINGS)
48184811
@pytest.mark.parametrize(
48194812
("padding_mode", "fill"),
@@ -4823,15 +4816,19 @@ def test_image_correctness(self, padding, padding_mode, fill, fn):
48234816
],
48244817
)
48254818
@pytest.mark.parametrize("fn", [F.pad, transform_cls_to_functional(transforms.Pad)])
4826-
def test_cvcuda_correctness(self, padding, padding_mode, fill, fn):
4827-
image = make_image_cvcuda(dtype=torch.uint8, device="cuda")
4819+
def test_image_correctness(self, make_input, padding, padding_mode, fill, fn):
4820+
image = make_input(dtype=torch.uint8, device="cpu")
48284821

48294822
fill = adapt_fill(fill, dtype=torch.uint8)
48304823

48314824
actual = fn(image, padding=padding, padding_mode=padding_mode, fill=fill)
4832-
expected = F.pad(F.cvcuda_to_tensor(image), padding=padding, padding_mode=padding_mode, fill=fill)
48334825

4834-
assert_equal(F.cvcuda_to_tensor(actual), expected)
4826+
if make_input is make_image_cvcuda:
4827+
image = cvcuda_to_pil_compatible_tensor(image)
4828+
4829+
expected = F.to_image(F.pad(F.to_pil_image(image), padding=padding, padding_mode=padding_mode, fill=fill))
4830+
4831+
assert_equal(actual, expected)
48354832

48364833
def _reference_pad_bounding_boxes(self, bounding_boxes, *, padding):
48374834
if isinstance(padding, int):

torchvision/transforms/v2/_geometry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
get_bounding_boxes,
2727
has_all,
2828
has_any,
29+
is_cvcuda_tensor,
2930
is_pure_tensor,
3031
query_size,
3132
)
@@ -465,6 +466,8 @@ class Pad(Transform):
465466

466467
_v1_transform_cls = _transforms.Pad
467468

469+
_transformed_types = Transform._transformed_types + (is_cvcuda_tensor,)
470+
468471
def _extract_params_for_v1_transform(self) -> dict[str, Any]:
469472
params = super()._extract_params_for_v1_transform()
470473

torchvision/transforms/v2/functional/_geometry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ def _pad_with_vector_fill(
16821682
_pad_image_pil = _register_kernel_internal(pad, PIL.Image.Image)(_FP.pad)
16831683

16841684

1685-
if _CVCUDA_AVAILABLE:
1685+
if CVCUDA_AVAILABLE:
16861686
_pad_mode_to_cvcuda = {
16871687
"constant": cvcuda.Border.CONSTANT,
16881688
"reflect": cvcuda.Border.REFLECT101,
@@ -1721,7 +1721,7 @@ def _pad_cvcuda(
17211721
)
17221722

17231723

1724-
if _CVCUDA_AVAILABLE:
1724+
if CVCUDA_AVAILABLE:
17251725
_register_kernel_internal(pad, _import_cvcuda().Tensor)(_pad_cvcuda)
17261726

17271727

0 commit comments

Comments
 (0)