Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour of F.interpolate with bicubic mode. #34544

Open
gsygsy96 opened this issue Mar 10, 2020 · 4 comments
Open

Strange behaviour of F.interpolate with bicubic mode. #34544

gsygsy96 opened this issue Mar 10, 2020 · 4 comments
Labels
module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@gsygsy96
Copy link

gsygsy96 commented Mar 10, 2020

馃悰 Bug

Input:
X with shape (2,3,256,256)
RUN:
Y = F.interpolate(X, [256,256], mode='bicubic', align_corners=True)
Z = F.interpolate(Y, [256,256], mode='bicubic', align_corners=True)
ISSUE:
Y[1,:,:,:] = zeros and Z[1,:,:,:] = zeros.

Following is my code:


def interpolate_torch(x, s=256, mode='bicubic', align_corners=True):
    return F.interpolate(x, [s, s], mode=mode, align_corners=True)
def get_transform(resize_crop, colorJitter, horizen_flip, inputsize=1024):
    transform_list =[]
    if resize_crop:
        transform_list.append(transforms.RandomResizedCrop(inputsize, scale=(0.8, 1.0), interpolation=PIL.Image.BICUBIC))
    else:
        if inputsize != 1024:
            transform_list.append(transforms.Resize(inputsize, interpolation=PIL.Image.BICUBIC))
    if colorJitter:
        transform_list.append(transforms.ColorJitter())
    if horizen_flip:
        transform_list.append(transforms.RandomHorizontalFlip())
    transform_list += [transforms.ToTensor(),
                       transforms.Normalize((0.5, 0.5, 0.5),(0.5, 0.5, 0.5))]
    return transforms.Compose(transform_list)

def img2tensor(name):
    transf = get_transform(resize_crop=False, colorJitter=False,
                           horizen_flip=False, inputsize=256)
    img = Image.open(name)
    img_torch = transf(img)
    return img_torch

y2 = img2tensor('content.png').unsqueeze(0)
y1 = img2tensor('content.png').unsqueeze(0)
y = torch.cat([y2, y1],0)
print(y[1,:,:,:])
y_bicubic = interpolate_torch(y, s=256, mode='bicubic')
print(y_bicubic[1,:,:,:])
y_bicubic_bicubic = interpolate_torch(y_bicubic, s=128, mode='bicubic')

Environment:
pytorch 1.1.0
torchvision 0.2.2.post3
scikit-image 0.15.0
python3

@gsygsy96
Copy link
Author

When I use bilinear, everything is ok. Help someone can given me the answer.

@albanD albanD added module: nn Related to torch.nn module: operators triage review triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Mar 10, 2020
@Enealor
Copy link
Contributor

Enealor commented Mar 10, 2020

Maybe related to #32918. To make sure though: is content.png a 256x256 image?

@gsygsy96
Copy link
Author

gsygsy96 commented Mar 11, 2020

Maybe related to #32918. To make sure though: is content.png a 256x256 image?

The content.png is an 1024 x 1024 image.

@gsygsy96
Copy link
Author

gsygsy96 commented Mar 11, 2020

Also, in my training script, if I first interpolate images(Bx3x256x256) with bicubic mode and scale_factor=1 and then interpolate the results again using bicubic and scale_factor != 1, the final results will be left rotated 90 degrees.
PS: if the first interpolation is bilinear or the seconde interpolation use scale_factor = 1, everything will be ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

4 participants