Skip to content

Why the supoort inputs of torchvision.transforms.functional.crop() and resize () on Windows is different from docs on website? #2580

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

Closed
track-ac opened this issue Aug 12, 2020 · 1 comment

Comments

@track-ac
Copy link

track-ac commented Aug 12, 2020

❓ Questions and Help

Windows 10:
CUDA version :10.1
torchvision.version is 0.7.0
python: 3.7

The docs on the website: torchvision.transforms.functional.resize() and torchvision.transforms.functional.crop() are written that the two functions support both PIL and tensor as inputs.

But when I use the two functions on Windows, I found that it still only support PIL as inputs. I'd like to use tensor as inputs. Some of the source code in functional.py is:

def resize(img, size, interpolation=Image.BILINEAR):
    r"""Resize the input PIL Image to the given size.

    Args:
        img (PIL Image): Image to be resized.
        size (sequence or int): Desired output size. If size is a sequence like
            (h, w), the output size will be matched to this. If size is an int,
            the smaller edge of the image will be matched to this number maintaining
            the aspect ratio. i.e, if height > width, then image will be rescaled to
            :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`
        interpolation (int, optional): Desired interpolation. Default is
            ``PIL.Image.BILINEAR``

    Returns:
        PIL Image: Resized image.
    """
    if not _is_pil_image(img):
        raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
    if not (isinstance(size, int) or (isinstance(size, Iterable) and len(size) == 2)):
        raise TypeError('Got inappropriate size arg: {}'.format(size))

    if isinstance(size, int):
        w, h = img.size
        if (w <= h and w == size) or (h <= w and h == size):
            return img
        if w < h:
            ow = size
            oh = int(size * h / w)
            return img.resize((ow, oh), interpolation)
        else:
            oh = size
            ow = int(size * w / h)
            return img.resize((ow, oh), interpolation)
    else:
        return img.resize(size[::-1], interpolation)
@vfdev-5
Copy link
Collaborator

vfdev-5 commented Aug 12, 2020

This is docs issue, #2551

Currently, v0.7.0 supports only few ops like hflip, vflip. Nightly version should support more, see #2292 for progress on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants