voxel51/fiftyone

[FR] torchvision: use weights instead of depcrecated pretrained parameter

Open

#1,977 opened on Aug 4, 2022

View on GitHub
 (11 comments) (1 reaction) (0 assignees)Python (400 forks)batch import
enhancementgood first issue

Repository metrics

Stars
 (4,021 stars)
PR merge metrics
 (Avg merge 3d 11h) (161 merged PRs in 30d)

Description

When loading most Torch models from the FiftyOne Model Zoo with torchvision==0.13.0 installed:

import fiftyone.zoo as foz

model = foz.load_zoo_model("mobilenet-v2-imagenet-torch")

I see the following error:

/path/to/python3.9/site-packages/torchvision/models/_utils.py:208: UserWarning:
The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead.

/path/to/python3.9/site-packages/torchvision/models/_utils.py:223: UserWarning:
Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing `weights=MobileNet_V2_Weights.IMAGENET1K_V1`. You can also use `weights=MobileNet_V2_Weights.DEFAULT` to get the most up-to-date weights.

So it looks like, when torchvision==0.15.0 is released (as of this writing, the latest version is 0.13.0 so this isn't a problem yet...), we'll need to follow the above advice and use weights='ResNet50_Weights.DEFAULT' instead of pretrained=True.

Here's where the pretrained=True is currently coming from: https://github.com/voxel51/fiftyone/blob/79fe485ae8da86a7aef156fdf466f6f7d81a7045/fiftyone/zoo/models/manifest-torch.json#L700-L710

Note that, if we're going to update the syntax, we either need to require a sufficiently new torchvision version (unsure if weights was available prior to torchvision==0.13.0, for example), or we need to bake some logic into the code to selectively use the appropriate parameter based on the installed torchvision version...

Contributor guide