赞
踩
pytorch提供了一系列预训练模型,一般可通过以下代码加载
net = models.resnet50(pretrained=True)
然而运行之后会报如下错误
UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
warnings.warn(
/usr/local/lib/python3.11/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=ResNet50_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet50_Weights.DEFAULT` to get the most up-to-date weights.
主要是因为从 torchvision 0.13开始,加载预训练模型函数的参数从 pretrained = True
改为 了weights=预训练模型参数版本
可以尝试如下:
net = models.resnet50(weights="IMAGENET1K_V1")
或
net = models.resnet50(weights=ResNet50_Weights.IMAGENET1K_V1)
或
net = models.resnet50(weights=ResNet50_Weights.DEFAULT)
这样就可以自动加载模型,输出如下
需要说明的是IMAGENET1K_V1代表的是第一个版本,以此类推,可以使用更新版本。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。