站点图标 AI技术聚合

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

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官方解释

文章出处登录后可见!

已经登录?立即刷新
退出移动版