【warning】UserWarning: The parameter ‘pretrained‘ is deprecated since 0.13 and may be removed

8 篇文章 0 订阅
import torchvision.models as models
self.backbone = models.resnet101(pretrained=True) #旧版本写法

报错内容:

C:\Users\ting\anaconda3\envs\pytorch\python.exe C:\Users\Administrator\PycharmProjects\FCN\model\fcn_res101.py 
C:\Users\ting\anaconda3\envs\pytorch\lib\site-packages\torchvision\models\_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
  warnings.warn(
C:\Users\ting\anaconda3\envs\pytorch\lib\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=ResNet101_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet101_Weights.DEFAULT` to get the most up-to-date weights.
  warnings.warn(msg)
torch.Size([1, 21, 256, 256])

Process finished with exit code 0

翻译一下,就是参数列表中的pretrained在新版本中被弃了,要使用weights这个参数。然后教你用新的参数。

就按照watning里写的把models.resnet101()后面的内容重新设置就好。


第一种:weights = models.ResNet101_Weights.DEFAULT

import torchvision.models as models
self.backbone = models.resnet101(weights = models.ResNet101_Weights.DEFAULT)

输出结果: 

C:\Users\ting\anaconda3\envs\pytorch\python.exe C:\Users\Administrator\PycharmProjects\FCN\model\fcn_res101.py 
Downloading: "https://download.pytorch.org/models/resnet101-cd907fc2.pth" to C:\Users\Administrator/.cache\torch\hub\checkpoints\resnet101-cd907fc2.pth
100%|██████████| 171M/171M [00:42<00:00, 4.17MB/s]
torch.Size([1, 21, 256, 256])

Process finished with exit code 0

第二种:weights = models.ResNet101_Weights.IMAGENET1K_V1

import torchvision.models as models
self.backbone = models.resnet101(weights = models.ResNet101_Weights.IMAGENET1K_V1)

 输出结果:

C:\Users\ting\anaconda3\envs\pytorch\python.exe C:\Users\Administrator\PycharmProjects\FCN\model\fcn_res101.py 
torch.Size([1, 21, 256, 256])

Process finished with exit code 0

res101中weight官方解释

  • 14
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值