【warning】UserWarning: O parâmetro 'pretrained' está obsoleto desde 0.13 e pode ser removido

import torchvision.models as models
self.backbone = models.resnet101(pretrained=True) #旧版本写法

Conteúdo do erro:

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

Para traduzir, o pré-treinado na lista de parâmetros foi abandonado na nova versão, e o parâmetro pesos deve ser utilizado. Em seguida, ensine como usar os novos parâmetros.

Basta redefinir o conteúdo após models.resnet101() conforme escrito em watch.


O primeiro: pesos = models.ResNet101_Weights.DEFAULT

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

Resultado de saída: 

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

Segundo tipo: pesos = models.ResNet101_Weights.IMAGENET1K_V1

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

 Resultado de saída:

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

Explicação oficial do peso em res101

Acho que você gosta

Origin blog.csdn.net/m0_70813473/article/details/127940420
Recomendado
Clasificación