简体   繁体   English

在 PyTorch 中加载 resnet50 prettriated model

[英]Loading resnet50 prettrianed model in PyTorch

I want to use resnet50 pretrained model using PyTorch and I am using the following code for loading it:我想使用 resnet50 预训练 model 使用 PyTorch 并且我正在使用以下代码来加载它:

    import torch
    model = torch.hub.load("pytorch/vision", "resnet50", weights="IMAGENET1K_V2")

Although I upgrade the torchvision but I receive the following error:虽然我升级了 torchvision 但我收到以下错误:

Any idea?任何想法?

As per the latest definition, we now load models using torchvision library, you can try that using:根据最新定义,我们现在使用 torchvision 库加载模型,您可以尝试使用:

from torchvision.models import resnet50, ResNet50_Weights

# Old weights with accuracy 76.130%
model1 = resnet50(weights=ResNet50_Weights.IMAGENET1K_V1)

# New weights with accuracy 80.858%
model2 = resnet50(weights=ResNet50_Weights.IMAGENET1K_V2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM