voxel51/fiftyone

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

Open

#1977 aperta il 4 ago 2022

Vedi su GitHub
 (11 commenti) (1 reazione) (0 assegnatari)Python (400 fork)batch import
enhancementgood first issue

Metriche repository

Star
 (4021 star)
Metriche merge PR
 (Merge medio 3g 11h) (161 PR mergiate in 30 g)

Descrizione

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...

Guida contributor