[go: nahoru, domu]

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

Backbone add out indices #22493

Merged
merged 5 commits into from
Apr 3, 2023

Conversation

amyeroberts
Copy link
Collaborator

What does this PR do?

Add out_indices as a way to specify which feature maps are returned in the backbone.

This isn't strictly necessary for cross loading timm backbones and is an optional design choice.

Reasoning:

  • Greater compatibility between timm and transformer models when loading with AutoBackbone. For the same model e.g. microsoft/resnet-50 and resnet50, the stage names are different, whereas the layer index is the same. out_indices=(1,) means the same for both model. whereas selecting features requires knowing one uses layer1 and the other uses stage1.
  • out_features requires knowing the names of the layers in order select which layers you want and is more prone to errors with typos
  • out_indices is the param used in timm. Once advantage of out_indices is that you can do negative indexing easily. For example, to get the last two feature maps, you need only pass out_indices=(-2, -1).

Outstanding question on whether both out_features and out_indices should exist at the same time.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@HuggingFaceDocBuilderDev
Copy link
HuggingFaceDocBuilderDev commented Mar 31, 2023

The documentation is not available anymore as the PR was closed or merged.

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.

I don't mind having both available. Thanks for implementing this!

Copy link
Contributor
@alaradirik alaradirik left a comment

Choose a reason for hiding this comment

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

LGTM! I agree that it'd be good to have both out_features and out_indices

@amyeroberts amyeroberts merged commit 559a45d into huggingface:main Apr 3, 2023
raghavanone pushed a commit to raghavanone/transformers that referenced this pull request Apr 5, 2023
* Add out_indices to backbones, deprecate out_features

* Update - can specify both out_features and out_indices but not both

* Can specify both

* Fix copies

* Add out_indices to convnextv2 configuration
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
* Add out_indices to backbones, deprecate out_features

* Update - can specify both out_features and out_indices but not both

* Can specify both

* Fix copies

* Add out_indices to convnextv2 configuration
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