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