[GH-ISSUE #335] preprocess _transfrom function #290

Open
opened 2026-10-31 21:13:29 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @sherlock666 on GitHub (Mar 10, 2023).
Original GitHub issue: https://github.com/openai/CLIP/issues/335

For preprocess:

Compose(
Resize(size=224, interpolation=bicubic, max_size=None, antialias=None)
CenterCrop(size=(224, 224))
<function _convert_image_to_rgb at 0x7f6d51348af0>
ToTensor()
Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))
)

I don't understand that why the code uses CenterCrop with size 224,224
when image is already resized to 224,224? (Resize(size=224, interpolation=bicubic, max_size=None, antialias=None))
what's the use for CenterCrop here? is it neccesary to do centercrop here?

thanks!!

Originally created by @sherlock666 on GitHub (Mar 10, 2023). Original GitHub issue: https://github.com/openai/CLIP/issues/335 For preprocess: Compose( Resize(size=224, interpolation=bicubic, max_size=None, antialias=None) CenterCrop(size=(224, 224)) <function _convert_image_to_rgb at 0x7f6d51348af0> ToTensor() Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711)) ) I don't understand that why the code uses CenterCrop with size 224,224 when image is already resized to 224,224? (Resize(size=224, interpolation=bicubic, max_size=None, antialias=None)) what's the use for CenterCrop here? is it neccesary to do centercrop here? thanks!!
Author
Owner

@shreydan commented on GitHub (Mar 14, 2023):

torchvision docs: Resize

size: Desired output size. If size is a sequence like (h, w), output size will be matched to this. If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size).

_transform(n_px) takes in a single n_px value equal to the input_resolution of the image model. So as per the docs, the smaller edge on image becomes n_px long. Then a final CenterCrop for n_px*n_px image.

<!-- gh-comment-id:1467283310 --> @shreydan commented on GitHub (Mar 14, 2023): torchvision docs: [Resize](https://pytorch.org/vision/stable/generated/torchvision.transforms.Resize.html#torchvision.transforms.Resize) > size: Desired output size. If size is a sequence like (h, w), output size will be matched to this. If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size). `_transform(n_px)` takes in a single n_px value equal to the input_resolution of the image model. So as per the docs, the smaller edge on image becomes n_px long. Then a final CenterCrop for n_px*n_px image.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#290
No description provided.