voxel51/fiftyone

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

Open

#1.977 geöffnet am 4. Aug. 2022

Auf GitHub ansehen
 (11 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Python (400 Forks)batch import
enhancementgood first issue

Repository-Metriken

Stars
 (4.021 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 3T 11h) (161 gemergte PRs in 30 T)

Beschreibung

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