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 an initial Segformer implementation #1617

Merged
merged 2 commits into from
Mar 3, 2024

Conversation

jimexist
Copy link
Contributor

@jimexist jimexist commented Jan 24, 2024

this is a copy from the huggingface pytorch model.

this is inference only so i omitted the parts about dropout, etc.

for image classification with num_labels

the model outputs a tensor with shape [batch_size, num_labels] where the last dim is logits

for image segmentation with num_labels, height and width

the model outputs a tensor with shape [batch_size, num_labels, height // 4, width // 4] to represent each 4-pixel patch's logits

Classification example

burger

this shall give you burger label:

classification logits [3.275261e-5, 0.0008562019, 0.0008868563, 0.9977506, 0.0002465068, 0.0002241473, 2.846596e-6]
label: hamburger

Segmentation example

input image (url is https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg):
ADE_val_00000001

output segmentation image:
output

@jimexist jimexist marked this pull request as ready for review January 24, 2024 17:23
@jimexist jimexist force-pushed the add-segformer branch 3 times, most recently from 1944792 to 513ae54 Compare February 3, 2024 01:38
@LaurentMazare
Copy link
Collaborator

This looks like a neat addition, thanks for working on this.
Would you mind adding to the PR a couple sample input and output so as to illustrate what to expect from the model?

@jimexist
Copy link
Contributor Author

This looks like a neat addition, thanks for working on this. Would you mind adding to the PR a couple sample input and output so as to illustrate what to expect from the model?

@LaurentMazare i added some in the PR description

@LaurentMazare
Copy link
Collaborator

This looks like a neat addition, thanks for working on this. Would you mind adding to the PR a couple sample input and output so as to illustrate what to expect from the model?

@LaurentMazare i added some in the PR description

Apologies if I misread your update but I was more expecting some example images as well as the segmentation masks generated by the model.

@jimexist jimexist force-pushed the add-segformer branch 2 times, most recently from 56fe84e to 7862d0c Compare March 1, 2024 14:34
@jimexist
Copy link
Contributor Author

jimexist commented Mar 1, 2024

This looks like a neat addition, thanks for working on this. Would you mind adding to the PR a couple sample input and output so as to illustrate what to expect from the model?

@LaurentMazare i added some in the PR description

Apologies if I misread your update but I was more expecting some example images as well as the segmentation masks generated by the model.

sample image added with readme updated.

@jimexist
Copy link
Contributor Author

jimexist commented Mar 1, 2024

segmentation image added

@LaurentMazare
Copy link
Collaborator

Actually I meant more adding some details to the PR rather than to the repo, it's a bit tricky to add more image file in it as it's already on the large side and we would prefer limiting how much more we add. Could you remove the image files and replace them by some wget commands in the readme?

@jimexist
Copy link
Contributor Author

jimexist commented Mar 3, 2024

Actually I meant more adding some details to the PR rather than to the repo, it's a bit tricky to add more image file in it as it's already on the large side and we would prefer limiting how much more we add. Could you remove the image files and replace them by some wget commands in the readme?

ah i see. i have included the image into the pull request itself and updated the readme file accordingly, also removed the image files from git history.

@LaurentMazare LaurentMazare merged commit 924ccae into huggingface:main Mar 3, 2024
10 checks passed
@LaurentMazare
Copy link
Collaborator

Thanks!

@LaurentMazare
Copy link
Collaborator

Also I would encourage you to advertise this new model on reddit/X/... or via some form of blog post. Would be great to attract some attention on it as it seems like a potentially pretty useful model and it can be nicely illustrated with your sample pics.

@jimexist jimexist deleted the add-segformer branch March 4, 2024 00:00
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.

2 participants