-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
improving TimmBackbone to support FrozenBatchNorm2d #27160
improving TimmBackbone to support FrozenBatchNorm2d #27160
Conversation
The documentation is not available anymore as the PR was closed or merged. |
…lla/transformers into optional_freeze_batch_norm_2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
There was a problem hiding this 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!
* 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>
What does this PR do?
The
TimmBackbone
offers 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'sBatchNorm2d
layers 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_2d
parameter, 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
BatchNorm2d
toFrozenBatchNorm2d
, theTimmBackbone
can 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