-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
Fix Automatic Download of Pretrained Weights in DETR #17712
Conversation
The documentation is not available anymore as the PR was closed or merged. |
>>> # model use pretrained backbone weights by default | ||
>>> # to prevent this set use_pretrained_backbone = False | ||
>>> # model = DetrModel.from_pretrained("facebook/detr-resnet-50", use_pretrained_backbone = False) |
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.
I don't think this makes sense, cause it will load pre-trained weights anyway.
A better code example (in my opinion) would be:
# randomly initialize a DETR model with pre-trained ResNet weights
config = DetrConfig()
model = DetrModel(config)
# randomly initialize a DETR model (with randomly initialized ResNet)
config = DetrConfig(use_pretrained_backbone=False)
model = DetrModel(config)
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.
@NielsRogge. Done. Works like you asked.
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! We could perhaps add a small code example snippet in detr.mdx.
@NielsRogge Any Update here? |
docs/source/en/model_doc/detr.mdx
Outdated
from transformers import DetrConfig | ||
|
||
Option 1: instantiate DETR with pre-trained weights for entire model | ||
model = DetrForObjectDetection.from_pretrained("facebook/resnet-50") | ||
|
||
Option 2: instantiate DETR with randomly initialized weights for Transformer, but pre-trained weights for backbone | ||
config = DetrConfig() | ||
model = DetrForObjectDetection(config) | ||
|
||
Option 3: instantiate DETR with randomly initialized weights for backbone + Transformer | ||
config = DetrConfig(use_pretrained_backbone=False) | ||
model = DetrForObjectDetection(config) |
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.
from transformers import DetrConfig | |
Option 1: instantiate DETR with pre-trained weights for entire model | |
model = DetrForObjectDetection.from_pretrained("facebook/resnet-50") | |
Option 2: instantiate DETR with randomly initialized weights for Transformer, but pre-trained weights for backbone | |
config = DetrConfig() | |
model = DetrForObjectDetection(config) | |
Option 3: instantiate DETR with randomly initialized weights for backbone + Transformer | |
config = DetrConfig(use_pretrained_backbone=False) | |
model = DetrForObjectDetection(config) | |
``` | |
from transformers import DetrConfig | |
Option 1: instantiate DETR with pre-trained weights for entire model | |
model = DetrForObjectDetection.from_pretrained("facebook/resnet-50") | |
Option 2: instantiate DETR with randomly initialized weights for Transformer, but pre-trained weights for backbone | |
config = DetrConfig() | |
model = DetrForObjectDetection(config) | |
Option 3: instantiate DETR with randomly initialized weights for backbone + Transformer | |
config = DetrConfig(use_pretrained_backbone=False) | |
model = DetrForObjectDetection(config) | |
``` |
This won't properly render if you don't add the code statements.
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.
The black command failed when added python after `. Unclear how to proceed here in that case.
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.
Oh I think you need to do ```python for the first statement
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.
Did exactly that 66eae21 The circle ci failed
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.
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 your contribution!
Co-authored-by: Sylvain Gugger <[email protected]>
* added use_backbone_pretrained * style fixes * update * Update detr.mdx * Update detr.mdx * Update detr.mdx * update using doc py * Update detr.mdx * Update src/transformers/models/detr/configuration_detr.py Co-authored-by: Sylvain Gugger <[email protected]> Co-authored-by: Sylvain Gugger <[email protected]>
* added use_backbone_pretrained * style fixes * update * Update detr.mdx * Update detr.mdx * Update detr.mdx * update using doc py * Update detr.mdx * Update src/transformers/models/detr/configuration_detr.py Co-authored-by: Sylvain Gugger <[email protected]> Co-authored-by: Sylvain Gugger <[email protected]>
What does this PR do?
Fixes #15764