improving TimmBackbone to support FrozenBatchNorm2d#27160
Merged
rafaelpadilla merged 8 commits intohuggingface:mainfrom Nov 1, 2023
Merged
improving TimmBackbone to support FrozenBatchNorm2d#27160rafaelpadilla merged 8 commits intohuggingface:mainfrom
rafaelpadilla merged 8 commits intohuggingface:mainfrom
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
…lla/transformers into optional_freeze_batch_norm_2d
amyeroberts
reviewed
Oct 31, 2023
Contributor
amyeroberts
left a comment
There was a problem hiding this comment.
Nice!
Great addition to the backbone class. Just a comment on adding it as a method instead and including the unfreeze option too.
src/transformers/models/timm_backbone/modeling_timm_backbone.py
Outdated
Show resolved
Hide resolved
amyeroberts
reviewed
Nov 1, 2023
Contributor
amyeroberts
left a comment
There was a problem hiding this comment.
Thanks for adding!
Just a note on the backwards compatibility of the model when loading in pretrained checkpoints.
src/transformers/models/timm_backbone/modeling_timm_backbone.py
Outdated
Show resolved
Hide resolved
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
amyeroberts
approved these changes
Nov 1, 2023
Contributor
amyeroberts
left a comment
There was a problem hiding this comment.
Thanks for adding this!
EduardoPach
pushed a commit
to EduardoPach/transformers
that referenced
this pull request
Nov 19, 2023
* supporting freeze_batch_norm_2d * supporting freeze_batch_norm_2d * including unfreeze + separate into methods * fix typo * calling unfreeze * lint * Update src/transformers/models/timm_backbone/modeling_timm_backbone.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> --------- Co-authored-by: Rafael Padilla <rafael.padilla@huggingface.co> Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The
TimmBackboneoffers various customizable parameters, such asnum_channels,features_only, andout_indices.Currently, we lack direct support for timm's
freeze_batch_norm_2d(...)function, which substitutes the backbone'sBatchNorm2dlayers withFrozenBatchNorm2d.For models like RTDetr, Detr, ConditionalDetr, DeformableDetr, etc that require freezing of batch norm layers, one currently needs to either reimplement and modify the backbone manually or use the
timm.layers.freeze_batch_norm_2d(...)function, like so:To simplify this, this PR introduces the
TimmBackboneConfig.freeze_batch_norm_2dparameter, which defaults to False for backward compatibility. When creating the backbone, if this parameter isTrue, it will applytimm's freeze_batch_norm_2d(...)function.This update simplifies the process of creating backbone models. For models requiring a switch from
BatchNorm2dtoFrozenBatchNorm2d, theTimmBackbonecan be used directly, eliminating additional steps.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@amyeroberts