Skip to content

Commit c799674

Browse files
committed
pad passing all tests
1 parent f59e9e9 commit c799674

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

test/test_transforms_v2.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4748,7 +4748,7 @@ def test_functional(self, make_input):
47484748
(F.pad_mask, tv_tensors.Mask),
47494749
(F.pad_video, tv_tensors.Video),
47504750
pytest.param(
4751-
F.pad_image_cvcuda,
4751+
F._geometry._pad_cvcuda,
47524752
"cvcuda.Tensor",
47534753
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="test requires CVCUDA"),
47544754
),
@@ -4813,6 +4813,26 @@ def test_image_correctness(self, padding, padding_mode, fill, fn):
48134813

48144814
assert_equal(actual, expected)
48154815

4816+
@pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="test requires CVCUDA")
4817+
@pytest.mark.parametrize("padding", CORRECTNESS_PADDINGS)
4818+
@pytest.mark.parametrize(
4819+
("padding_mode", "fill"),
4820+
[
4821+
*[("constant", fill) for fill in CORRECTNESS_FILLS],
4822+
*[(padding_mode, None) for padding_mode in ["symmetric", "edge", "reflect"]],
4823+
],
4824+
)
4825+
@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")
4828+
4829+
fill = adapt_fill(fill, dtype=torch.uint8)
4830+
4831+
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)
4833+
4834+
assert_equal(F.cvcuda_to_tensor(actual), expected)
4835+
48164836
def _reference_pad_bounding_boxes(self, bounding_boxes, *, padding):
48174837
if isinstance(padding, int):
48184838
padding = [padding]

torchvision/transforms/v2/functional/_geometry.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,12 +1683,12 @@ def _pad_with_vector_fill(
16831683

16841684

16851685
if _CVCUDA_AVAILABLE:
1686-
cvcuda = _import_cvcuda()
16871686
_pad_mode_to_cvcuda = {
1688-
"constant": cvcuda.BorderType.CONSTANT,
1689-
"reflect": cvcuda.BorderType.REFLECT,
1690-
"replicate": cvcuda.BorderType.REPLICATE,
1691-
"symmetric": cvcuda.BorderType.WRAP,
1687+
"constant": cvcuda.Border.CONSTANT,
1688+
"reflect": cvcuda.Border.REFLECT101,
1689+
"replicate": cvcuda.Border.REPLICATE,
1690+
"edge": cvcuda.Border.REPLICATE,
1691+
"symmetric": cvcuda.Border.REFLECT,
16921692
}
16931693

16941694

@@ -1700,7 +1700,7 @@ def _pad_cvcuda(
17001700
) -> "cvcuda.Tensor":
17011701
cvcuda = _import_cvcuda()
17021702

1703-
if padding_mode not in _pad_mode_to_cvcuda:
1703+
if _pad_mode_to_cvcuda.get(padding_mode) is None:
17041704
raise ValueError(f"Padding mode '{padding_mode}' is not supported with CVCUDA")
17051705

17061706
if fill is None:

0 commit comments

Comments
 (0)