Skip to content

bug in RandomCrop when accepting a tuple as padding using python 3 #488

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
KovenYu opened this issue May 6, 2018 · 0 comments
Closed

bug in RandomCrop when accepting a tuple as padding using python 3 #488

KovenYu opened this issue May 6, 2018 · 0 comments

Comments

@KovenYu
Copy link
Contributor

KovenYu commented May 6, 2018

when RandomCrop accepts a tuple of integers as padding, it simply absorbs this argument:

"""
padding (int or sequence, optional): Optional padding on each border
  of the image. Default is 0, i.e no padding. If a sequence of length
  4 is provided, it is used to pad left, top, right, bottom borders
  respectively.
"""
    def __init__(self, size, padding=0, pad_if_needed=False):
        if isinstance(size, numbers.Number):
            self.size = (int(size), int(size))
        else:
            self.size = size
        self.padding = padding
        self.pad_if_needed = pad_if_needed

then, when it is called, this argument is compared with 0:

    def __call__(self, img):
        """
        Args:
            img (PIL Image): Image to be cropped.
        Returns:
            PIL Image: Cropped image.
        """
        if self.padding > 0:
            img = F.pad(img, self.padding)

this is okay in python 2 where this comparison always returns True. but in python 3, comparison between tuple and int is illegal, and thus it will raise an type error.

P.S. there is another confusing feature. when I use RandomCrop((128, 32), padding=(16, 4)), I obviously expect each entry of padding should match the corresponding entry in size (i.e. the height 128 should be padded with 16, and width 32 padded with 4), but in fact it is inverse (128 with 4, 32 with 16). I think this is weird...

KovenYu added a commit to KovenYu/vision that referenced this issue May 6, 2018
KovenYu added a commit to KovenYu/vision that referenced this issue May 20, 2018
KovenYu added a commit to KovenYu/vision that referenced this issue May 21, 2018
fmassa pushed a commit that referenced this issue May 24, 2018
* fix a bug described in issue #488

* improve doc described in issue #488

* add arguments in RandomCrop as proposed by vfdev-5 in PR #489
@KovenYu KovenYu closed this as completed May 25, 2018
KovenYu added a commit to KovenYu/vision that referenced this issue May 27, 2018
varunagrawal pushed a commit to varunagrawal/vision that referenced this issue Jul 23, 2018
* fix a bug described in issue pytorch#488

* improve doc described in issue pytorch#488

* add arguments in RandomCrop as proposed by vfdev-5 in PR pytorch#489
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant