UserWarning: The parameter ‘pretrained‘ is deprecated since 0.13 and will be removed in 0.15, please

Usage scenario: Call torchvision's API, want to use the restnet model on the ImageNet data set, and want to use the error reported when pretrained. The general meaning is that pretrained in the parameter list has been deprecated in the new version, and the weights parameter must be used.

Solution:

  from torchvision.models import resnet18, ResNet18_Weights
  # 使用预训练的 ResNet18 作为特征提取器
  self.feature_extractor = resnet18(weights=ResNet18_Weights.IMAGENET1K_V1)

Visit this webpage to query the weight of the corresponding model:
https://pytorch.org/vision/main/models.html
Insert image description here

Guess you like

Origin blog.csdn.net/qq_43374694/article/details/132588344