import torchvision.models as models
self.backbone = models.resnet101(pretrained=True) #舊版本寫法
報錯內(nèi)容:
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
翻譯一下,就是參數(shù)列表中的pretrained在新版本中被棄了,要使用weights這個參數(shù)。然后教你用新的參數(shù)。
就按照watning里寫的把models.resnet101()后面的內(nèi)容重新設置就好。
第一種:weights = models.ResNet101_Weights.DEFAULT
import torchvision.models as models
self.backbone = models.resnet101(weights = models.ResNet101_Weights.DEFAULT)
輸出結(jié)果:?
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)
?輸出結(jié)果:文章來源:http://www.zghlxwxcb.cn/news/detail-548676.html
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官方解釋文章來源地址http://www.zghlxwxcb.cn/news/detail-548676.html
到了這里,關于【warning】UserWarning: The parameter ‘pretrained‘ is deprecated since 0.13 and may be removed的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!