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 BeitForSemanticSegmentation #14096

Merged
merged 17 commits into from Nov 1, 2021

Conversation

NielsRogge
Copy link
Contributor

@NielsRogge NielsRogge commented Oct 21, 2021

What does this PR do?

This PR is a follow-up of #12994, and adds the semantic segmentation head of BEiT. It's the state-of-the-art model currently for semantic segmentation (i.e. the task of labeling each pixel of an image), on datasets like ADE20k and CityScapes (see this chart on paperswithcode).

Now it's easily available with a HuggingFace API! :)

Models are on the hub: https://huggingface.co/models?search=ade-640

Here's a notebook for quick inference: https://colab.research.google.com/drive/1AS3z0plOhWWibBvDgsQkRbfJB73vSsR3?usp=sharing

Copy link
Collaborator

@sgugger sgugger 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 this! You have two wiles in the PR by mistake I believe:

  • src/transformers/model/beit/test.ipynb
  • src/transformers/model/beit/test_semantic.py

src/transformers/models/beit/configuration_beit.py Outdated Show resolved Hide resolved
bias=bias,
dilation=dilation,
)
self.bn = nn.BatchNorm2d(out_channels)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that this is the first module I see adding a BatchNorm layer, so if used in the Trainer, we should probably add stuff to handle the weight decay.

src/transformers/models/beit/modeling_beit.py Outdated Show resolved Hide resolved
src/transformers/models/beit/modeling_beit.py Outdated Show resolved Hide resolved
src/transformers/models/beit/modeling_beit.py Outdated Show resolved Hide resolved
src/transformers/models/beit/modeling_beit.py Outdated Show resolved Hide resolved
src/transformers/models/beit/test_semantic.py Outdated Show resolved Hide resolved
tests/test_modeling_beit.py Outdated Show resolved Hide resolved
tests/test_modeling_beit.py Outdated Show resolved Hide resolved
@kamalkraj
Copy link
Contributor

@NielsRogge
Do you have plans to add an example fine-tuning script for the segmentation task?

@NielsRogge
Copy link
Contributor Author

Hi @kamalkraj,

Yes I do plan to add that. However, this will become easier once the Image feature will be available in the Datasets library.

@kamalkraj
Copy link
Contributor

Okay @NielsRogge

I can update the flax version of beit, after this PR merge

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for working on this @NielsRogge

src/transformers/models/beit/modeling_beit.py Show resolved Hide resolved
tests/test_modeling_beit.py Outdated Show resolved Hide resolved
@NielsRogge NielsRogge merged commit e20faa6 into huggingface:master Nov 1, 2021
Albertobegue pushed a commit to Albertobegue/transformers that referenced this pull request Jan 27, 2022
* Add first draft

* Make forward pass work

* Improve conversion script

* Add notebook that checks if it works

* Add BeitForSemanticSegmentation to the tests

* More improvements

* Make BeitForSemanticSegmentation consistent with Segformer

* Small bug fix

* Add BeitForSemanticSegmentation to docs

* Make sure model doesn't output hidden states when the user doesn't want to

* Make it possible to convert the large model

* Fix issue

* Fix conversion script for large model

* Add auxiliary_head option to semantic segmentation model

* Apply suggestions from @sgugger's review

* Apply suggestions from code review

* Fix failing test

Co-authored-by: Lysandre <lysandre.debut@reseau.eseo.fr>
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.

None yet

4 participants