Skip to content
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

What is the difference between preprocess scale_width_and_crop and resize_and_crop? #1667

Open
bclaw524 opened this issue Jul 18, 2024 · 2 comments

Comments

@bclaw524
Copy link

The description seems to be the same where both resize the image to load_size and then crop the image to crop_size.

The only thing I seem to notice is that scale_width_and_crop seems to complete an epoch a bit faster than resize_and_crop.

(my images are 1024x1024 and the load size is 512)

@Jiwno
Copy link

Jiwno commented Sep 23, 2024

in the file "./data/base_dataset.py", you can easily find the part to precess the image you imported.
If you use resize_and_crop option, width and height(new_h & new_w) are eqaul to a load_size.

but if you use scale_width option, height of load image change refer to the ration of the original image.

As far as I know, resize_and_crop option loads the images as square, same width and height, but scale_width_and_crop option loads the image as rectangular with aspect ration of the original data.

@noooob-ody
Copy link

i found it maybe a mistake in the source code
def __scale_width(img, target_size, crop_size, method=transforms.InterpolationMode.BICUBIC):
method = __transforms2pil_resize(method)
ow, oh = img.size
if ow == target_size and oh >= crop_size:
return img
w = target_size
h = int(max(target_size * oh / ow, crop_size))
return img.resize((w, h), method)
usually the width is bigger than height, so it still result in distortion, change it into def __scale_width(img, target_size, crop_size, method=transforms.InterpolationMode.BICUBIC):
method = __transforms2pil_resize(method)
ow, oh = img.size
if ow == target_size and oh >= crop_size:
return img
h = target_size
w = int(max(target_size * ow / oh, crop_size))
return img.resize((w, h), method)
and it keeps the aspect ratio

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

3 participants