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

a little problem when using some pretrained models #4274

Closed
ZhiyanWXZ opened this issue Aug 11, 2021 · 4 comments · Fixed by #4283
Closed

a little problem when using some pretrained models #4274

ZhiyanWXZ opened this issue Aug 11, 2021 · 4 comments · Fixed by #4283

Comments

@ZhiyanWXZ
Copy link

🐛 Bug

A little problem.

I used some pretrained models to do object detection.

However, when i used models whose name include others models' name, such as 'fasterrcnn_mobilenet_v3_large_320_fpn', (its name includes the name of model 'mobilenet_v3_large'), it will download the weight file of the short name models.

For example, when i used model 'fasterrcnn_mobilenet_v3_large_320_fpn', whenever the pretrained attribute is True or not, the weight file of model 'mobilenet_v3_large' will be downloaded.

This problem also happen in the models such as 'maskrcnn_resnet50_fpn' and many other models.

To Reproduce

Steps to reproduce the behavior:
it's easy to reproduce. For example:

from torchvision.models.detection import *
model = fasterrcnn_mobilenet_v3_large_320_fpn()

excute the code above, the weight file of model "mobilenet_v3_large" will be downloaded.
you can change the model name to other this kind of model names.

cc @fmassa @vfdev-5 @pmeier

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Aug 13, 2021

@ZhiyanWXZ you can pass pretrained_backbone=False and pretrained=False to skip any pretrained weights downloading

@fmassa fmassa transferred this issue from pytorch/pytorch Aug 13, 2021
@fmassa
Copy link
Member

fmassa commented Aug 13, 2021

@datumbox maybe we should only download the backbone weights if pretrained=False and pretrained_backbone=True?

@datumbox
Copy link
Contributor

@ZhiyanWXZ the vast majority of the models have pretrained=False and pretrained_backbone=True as default parameters which means this is an expected behaviour. As @vfdev-5 said, if you pass pretrained_backbone=False it won't download the backbone data.

As for when pretrained=True as far as I can tell the pretrained_backbone is set to False automatically for all models. Which version of TorchVision are you using?

fasterrcnn_mobilenet_v3_large_fpn/fasterrcnn_mobilenet_v3_large_320_fpn:

if pretrained:
pretrained_backbone = False

fasterrcnn_resnet50_fpn:

if pretrained:
# no need to download the backbone if pretrained is set
pretrained_backbone = False

keypointrcnn_resnet50_fpn:

if pretrained:
# no need to download the backbone if pretrained is set
pretrained_backbone = False

maskrcnn_resnet50_fpn:

if pretrained:
# no need to download the backbone if pretrained is set
pretrained_backbone = False

retinanet_resnet50_fpn:

if pretrained:
# no need to download the backbone if pretrained is set
pretrained_backbone = False

ssd300_vgg16:

if pretrained:
# no need to download the backbone if pretrained is set
pretrained_backbone = False

ssdlite320_mobilenet_v3_large:

if pretrained:
pretrained_backbone = False

fcn_resnet50/fcn_resnet101/deeplabv3_resnet50/deeplabv3_resnet101/deeplabv3_mobilenet_v3_large:

if pretrained:
aux_loss = True
kwargs["pretrained_backbone"] = False

The only problematic case I found was for lraspp_mobilenet_v3_large which I'll patch in a bit.

@ZhiyanWXZ
Copy link
Author

thanks, I get it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants