Closed Athospd closed 4 months ago
Hi, this is also affected by the thing corrected in https://github.com/mlverse/torchvision/pull/46, but to completely fix transform_center_crop
there is something else to be done:
In https://pytorch.org/vision/stable/_modules/torchvision/transforms/functional.html#center_crop, there is a paragraph that is missing in the R function, which deals with what should happen if the image is smaller than the desired size:
if crop_width > image_width or crop_height > image_height:
padding_ltrb = [
(crop_width - image_width) // 2 if crop_width > image_width else 0,
(crop_height - image_height) // 2 if crop_height > image_height else 0,
(crop_width - image_width + 1) // 2 if crop_width > image_width else 0,
(crop_height - image_height + 1) // 2 if crop_height > image_height else 0,
]
img = pad(img, padding_ltrb, fill=0) # PIL uses fill value 0
image_width, image_height = _get_image_size(img)
if crop_width == image_width and crop_height == image_height:
return img
I can add that to #44 later today.
should be fixed in that same PR now (https://github.com/mlverse/torchvision/pull/46/commits/6f7faaf3feb20c8bdcec917a72c60867ef18ce4c)
Just to report that I installed from bug/img_size branch and it worked perfectly on my code. Thank you!
Thanks for reporting! I'm going ahead and merge, then.
I don't know if I'm using this function as expected, but I think zero height is not what it suposed to return in this situation.
Created on 2021-03-07 by the reprex package (v0.3.0)