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

Add SiglipForImageClassification and CLIPForImageClassification #28952

Merged

Conversation

NielsRogge
Copy link
Contributor

What does this PR do?

This PR adds 2 new classes to the library, SiglipForImageClassification and CLIPForImageClassification.

This makes it easier to fine-tune SigLIP/CLIP for image classification, as otherwise people had to manually write a class based on SiglipVisionModel/CLIPVisionModel with a head on top. Given that SigLIP and CLIP are among the best vision encoders out there, it makes sense to add them.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - thanks for adding!

@NielsRogge
Copy link
Contributor Author

@amyeroberts I assume the "build PR documentation" check is failing but unrelated to this PR, so I can merge?

@amyeroberts
Copy link
Collaborator

@NielsRogge Yes, if you look on main you can see that the build is failing for lots of (unrelated) PRs at the moment. I'm happy for you to merge as all the other CIs are passing.

@NielsRogge NielsRogge merged commit 63ffd56 into huggingface:main Feb 14, 2024
20 of 21 checks passed
@zhjohnchan
Copy link

zhjohnchan commented Feb 14, 2024

Hi @NielsRogge and @amyeroberts,

Thanks for your contribution to the community @NielsRogge! I am wondering if "do_rescale": true is necessary for SiglipImageProcessor? Let me know if I miss anything!

Also, did you encounter the same problem as in #28968?

Thanks!

Best,

@amyeroberts
Copy link
Collaborator

@zhjohnchan do_rescale=True is necessary if the input images are in the range [0, 255]. If they've already been rescaled to [0, 1] you can set it to False.

sbucaille pushed a commit to sbucaille/transformers that referenced this pull request Feb 14, 2024
…ingface#28952)

* First draft

* Add CLIPForImageClassification

* Remove scripts

* Fix doctests
@zhjohnchan
Copy link

@amyeroberts Thank you so much! Just realized it should be rescaled for all Transformers' preprocessors.

@NielsRogge
Copy link
Contributor Author

@zhjohnchan I haven't encountered the same problem, made a fine-tuning notebook for SigLIP here: https://github.com/NielsRogge/Transformers-Tutorials/blob/master/SigLIP/Fine_tuning_SigLIP_and_friends_for_multi_label_image_classification.ipynb.

@zhjohnchan
Copy link

@NielsRogge Got it! Thank you so much!

@NielsRogge NielsRogge mentioned this pull request Feb 19, 2024
2 tasks
@Andron00e
Copy link

Hi, I am the one who proposed to add a CLIPForImageClassification. Now I am back to contributing with it.
I see "Build documentation" failure. How can it be fixed?

@NielsRogge
Copy link
Contributor Author

@Andron00e
Copy link

Thank you! I'll try to fix minor bugs with CLIPForImageClassification and place its code into SigLIP's directory.

itazap pushed a commit that referenced this pull request May 14, 2024
* First draft

* Add CLIPForImageClassification

* Remove scripts

* Fix doctests
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

Successfully merging this pull request may close these issues.

5 participants