No Resize in torchVision.transforms

I installed pytorch and torchvision with anaconda.
But there is no Resize class/module in torchvision.transforms.
The code in official github surely has these codes, but I failed to build pytorch from source.
So how can I use Resize?
Thansks

download related files
and replace your local files (find them by locate torchvision/transforms)

You can use the old Scale transform. But if the size provided is just int, it will resize the minimum size of image to that number. If you want to resize the image’s maximum length to size and keep aspect ratio. Just write your own resize, it is just a few line of code, see example code below for a reference,


class Resize(object):
    def __init__(self, size, interpolation=Image.BILINEAR):
        self.size = size
        self.interpolation = interpolation

    def __call__(self, img):
        old_size = img.size  # old_size[0] is in (width, height) format

        ratio = float(self.size)/max(old_size)
        new_size = tuple([int(x * ratio) for x in old_size])

        return img.resize(new_size, resample=self.interpolation)
1 Like

As @chenyuntc said, download related files and don’t forget to reboot your system to get things updated.

Sorry for such a long delay.
locate torchvision/transforms prints nothing, and I guess just downloading the scripts without lib files may not work.
I just found that, for python2 and torch0.2, there is no Resize and as @jdhao said, Scale is prefered, for python3 and torch0.3, Resize is prefered.
Just wondering why there’s no torch0.3 for python2 if using pip install.

Have you read about this?

1 Like

It works! updated to torch0.3.0post4, thanks

Cheers, always search through the forum before posting your question.

Definitely. Didn’t realize that this is due to low version and asked a stupid qestion:blush: