Skip to content

Fixed issue with padding on CI #5875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions test/test_transforms_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ def _test_functional_op(f, device, channels=3, fn_kwargs=None, test_exact_match=
_assert_approx_equal_tensor_to_pil(transformed_tensor, transformed_pil_img, **match_kwargs)


def _test_class_op(method, device, channels=3, meth_kwargs=None, test_exact_match=True, **match_kwargs):
# TODO: change the name: it's not a method, it's a class.
def _test_class_op(transform_cls, device, channels=3, meth_kwargs=None, test_exact_match=True, **match_kwargs):
meth_kwargs = meth_kwargs or {}

# test for class interface
f = method(**meth_kwargs)
f = transform_cls(**meth_kwargs)
scripted_fn = torch.jit.script(f)

tensor, pil_img = _create_data(26, 34, channels, device=device)
Expand All @@ -86,7 +85,7 @@ def _test_class_op(method, device, channels=3, meth_kwargs=None, test_exact_matc
_test_transform_vs_scripted_on_batch(f, scripted_fn, batch_tensors)

with get_tmp_dir() as tmp_dir:
scripted_fn.save(os.path.join(tmp_dir, f"t_{method.__name__}.pt"))
scripted_fn.save(os.path.join(tmp_dir, f"t_{transform_cls.__name__}.pt"))


def _test_op(func, method, device, channels=3, fn_kwargs=None, meth_kwargs=None, test_exact_match=True, **match_kwargs):
Expand Down
5 changes: 4 additions & 1 deletion torchvision/transforms/functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,10 @@ def pad(img: Tensor, padding: List[int], fill: int = 0, padding_mode: str = "con
need_cast = True
img = img.to(torch.float32)

img = torch_pad(img, p, mode=padding_mode, value=float(fill))
if padding_mode in ("reflect", "replicate"):
img = torch_pad(img, p, mode=padding_mode)
else:
img = torch_pad(img, p, mode=padding_mode, value=float(fill))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a PR that resolves the accidental BC break at pytorch/pytorch#76307

It's not merged yet but we can go ahead and adopt this approach in TorchVision to avoid it regardless.


if need_squeeze:
img = img.squeeze(dim=0)
Expand Down