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

Integrate with Hugging Face #128

Merged
merged 18 commits into from
Aug 7, 2024
Merged

Conversation

NielsRogge
Copy link
Contributor

@NielsRogge NielsRogge commented Aug 3, 2024

This PR fixes #1. It aims to make it possible to load any SAM 2 model directly from the hub.

The checkpoints are already part of the facebook org:

This PR allows to do the following:

from sam2.sam2_image_predictor import SAM2ImagePredictor

predictor = SAM2ImagePredictor.from_pretrained("facebook/sam2-hiera-small")

This also ensures that download stats work, meaning you'll be able to see how many times people actually load one of these checkpoints from the hub. This will also allow us to compare to the download stats of Transformers which will be interesting :)

To do:

  • update README to link to HF artifacts
  • update notebooks (?)
  • support video predictor

@bhack
Copy link

bhack commented Aug 4, 2024

Is this also in the to-do list at huggingface/transformers#32394 ?

Copy link
Contributor

@haithamkhedr haithamkhedr left a comment

Choose a reason for hiding this comment

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

@NielsRogge Thanks for supporting ckpt download from HF. Can we make huggingface_hub a soft dependency?

sam2/sam2_image_predictor.py Outdated Show resolved Hide resolved
sam2/build_sam.py Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
sam2/build_sam.py Outdated Show resolved Hide resolved
sam2/build_sam.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@haithamkhedr haithamkhedr left a comment

Choose a reason for hiding this comment

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

Thanks for adding support to load the models through HF hub.

@haithamkhedr haithamkhedr merged commit 6ba4c65 into facebookresearch:main Aug 7, 2024
2 checks passed
@giswqs
Copy link

giswqs commented Aug 7, 2024

This is great! Is there a plan to make it compatible with transformers, like SAM 1?

https://huggingface.co/docs/transformers/en/tasks/mask_generation

@NielsRogge
Copy link
Contributor Author

Yes there is, the authors are adding a PR here: huggingface/transformers#32394

@giswqs
Copy link

giswqs commented Aug 7, 2024

Fantastic! Can't wait for the PR to be merged!

@sueszli
Copy link

sueszli commented Aug 7, 2024

This is just amazing <3

@leonmkim
Copy link

Sorry potentially dumb question, but should this line in the video predictor be changed from return cls(sam_model) to return sam_model? It seems like the former would work for the image predictor based on its constructor but not the video predictor. But I could be wrong :p

@haithamkhedr
Copy link
Contributor

haithamkhedr commented Aug 13, 2024

@leonmkim Good catch! Fixed in #205

xydy666 pushed a commit to xydy666/segment-anything-2 that referenced this pull request Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve discoverability on HF
7 participants