预训练模型加载报错

 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代表的是第一个版本,以此类推,可以使用更新版本。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值