PyTorch图像处理:解决'pretrained'参数废弃警告在使用PyTorch进行图像处理时,你可能会遇到以下警告信息:C:/Users/31370/AppData/Roaming/Python/Python311/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/31370/AppData/Roaming/Python/Python311/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)**原因:**这个警告是因为在torchvision的_utils.py文件中,pretrained参数被标记为废弃,建议使用weights参数代替。**影响:**尽管出现警告,你的代码目前仍然可以正常运行。然而,为了避免在未来的torchvision版本中出现问题,建议你根据警告信息进行修改。**解决方案:**将代码中所有使用pretrained=True的地方替换为weights='imagenet',以使用预训练的ImageNet权重。 **示例:**将以下代码:python# 加载预训练的ResNet-101模型model = resnet101(pretrained=True)修改为:python# 加载预训练的ResNet-101模型model = resnet101(weights='imagenet')**总结:**通过使用weights参数代替pretrained参数,你可以轻松解决这个警告信息,并确保你的代码在未来版本的torchvision中也能正常运行。

PyTorch图像处理:解决'pretrained'参数废弃警告

原文地址: https://www.cveoy.top/t/topic/bBkl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录