-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Closed
Description
🚀 Feature
Currently, negative padding values for functional.pad are not supported for any kind of padding mode and data type
import torch
import torchvision
from torchvision.transforms.functional import pad, to_pil_image
print(torch.__version__, torchvision.__version__)
x = torch.randint(0, 256, size=(3, 32, 32), dtype=torch.uint8)
x_pil = to_pil_image(x)
padding = (-1, -2, -3, -4)
for m in ["constant", "edge", "reflect"]:
try:
pad(x, padding, padding_mode=m)
except ValueError:
print("Tensor: Failed with ", m)
for m in ["constant", "edge", "reflect", "symmetric"]:
try:
pad(x_pil, padding, padding_mode=m)
except ValueError:
print("PIL: Failed with ", m)
> 1.7.0.dev20200701 0.8.0.dev20200701
> PIL: Failed with edge
> PIL: Failed with reflect
> PIL: Failed with symmetricThis is due to np.pad used internally for PIL input.
Motivation
It would be better to provide uniform behaviour for pad with respect of input data type and negative padding values:
- raise an error
- support it in the cases