Skip to content

Error with transfroms.Scale when feeding iterable size #200

Closed
@ntomita

Description

@ntomita

I'm having a problem with transforms.Scale function, which complains
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'
when feeding an iterable size.

It persists even after installed latest packages.
I don't see any problem in a source code, but seems like the if statement gets True for isinstance(self.size, int)

Here's how it fails.
>>> import torch
>>> import collections
>>> from torchvision.transforms import Scale
>>> from PIL import Image

>>> im = Image.open('pos19.jpg')
>>> Scale(size=(512,256))(im)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ntomita/pytorch-env/lib/python2.7/site-packages/torchvision-0.1.8-py2.7.egg/torchvision/transforms.py", line 139, in __call__
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'

Now checking each portion in a source.
>>> transform = Scale(size=(512, 224))
>>> isinstance(transform.size, int)
False
>>> (isinstance(transform.size, collections.Iterable) and len(transform.size) == 2)
True
Condition terms look fine, but when calling,
>>> transform(im)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ntomita/pytorch-env/lib/python2.7/site-packages/torchvision-0.1.8-py2.7.egg/torchvision/transforms.py", line 139, in __call__
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'
It fails. If I call resize directly,
>>> im.resize(transform.size, transform.interpolation)
<PIL.Image.Image image mode=L size=512x224 at 0x7F7F8C6D4F50>
works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions