Closed
Description
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...
Metadata
Metadata
Assignees
Labels
No labels