当前位置:   article > 正文

预训练模型加载报错_userwarning: arguments other than a weight enum or

userwarning: arguments other than a weight enum or `none` for 'weights' are

 pytorch提供了一系列预训练模型,一般可通过以下代码加载

net = models.resnet50(pretrained=True)

 然而运行之后会报如下错误

UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
  warnings.warn(
/usr/local/lib/python3.11/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=ResNet50_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet50_Weights.DEFAULT` to get the most up-to-date weights.

 主要是因为从 torchvision 0.13开始,加载预训练模型函数的参数从 pretrained = True 改为 了weights=预训练模型参数版本 

可以尝试如下:

net = models.resnet50(weights="IMAGENET1K_V1")

net = models.resnet50(weights=ResNet50_Weights.IMAGENET1K_V1)

net = models.resnet50(weights=ResNet50_Weights.DEFAULT)

 这样就可以自动加载模型,输出如下

需要说明的是IMAGENET1K_V1代表的是第一个版本,以此类推,可以使用更新版本。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/497857
推荐阅读
  

闽ICP备14008679号