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

Convert all non-RGB images to RGB in CLIPImageTransform #1975

Closed
vancoykendall opened this issue Nov 8, 2024 · 4 comments
Closed

Convert all non-RGB images to RGB in CLIPImageTransform #1975

vancoykendall opened this issue Nov 8, 2024 · 4 comments

Comments

@vancoykendall
Copy link
Contributor

In the CLIPImageTransfrom, only RGBA images get converted to RGB. I don't see a reason to not convert all non-RGB images. I have a multimodal dataset with mostly RGB images, but a handful are in CMYK and L. I'm finetuning a Llama3.2 VLM which uses the CLIPImageTransform and my first training crashed in the middle because a CMYK image finally was loaded, didn't get converted, and the size didn't match.

# Make image torch.tensor((3, H, W), dtype=dtype), 0<=values<=1
if hasattr(image, "mode") and image.mode == "RGBA":
image = image.convert("RGB")

I noticed the code in the eval recipe actually does convert all non-RGB images to RGB:

for image in images:
if image.mode != "RGB":
image = image.convert("RGB")

@ebsmothers
Copy link
Contributor

Thanks for creating the issue. Actually this was done as a bit of a one-off so we probably can consider changing to match the eval recipe. cc @pbontrager in case you have any strong objections to this, but otherwise @vancoykendall we'd love to have you open a PR with the change if you're interested.

@vancoykendall
Copy link
Contributor Author

@ebsmothers sounds good. Also, I think like the eval code I can remove the check for the mode attribute as all PIL.Images have the attribute

@vancoykendall
Copy link
Contributor Author

@ebsmothers Just created a pr #1976

@ebsmothers
Copy link
Contributor

Closing now that the fix has landed. Thanks again!

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

2 participants