【问题标题】:How can I use the Resnet architecture to classify a custom labeled set of images?如何使用 Resnet 架构对自定义标记的图像集进行分类?
【发布时间】:2021-01-02 02:19:45
【问题描述】:

我正在尝试在 resnet 152 上使用迁移学习来将自定义标记为 0/1 的图像数据集分类为是否包含感兴趣的对象。我参考了多个教程,但无法弄清楚。我将在下面放置一些我之前引用过的链接,但我正在尝试使用第一个代码。

我开始尝试使用它。 PyTorch transfer learning with pre-trained ImageNet model

# Load the pretrained model
model = models.resnet152(pretrained=True)

classifier_name, old_classifier = model._modules.popitem()

for param in model.parameters():
    param.requires_grad = False

classifier_input_size = old_classifier.in_features

classifier = nn.Sequential(OrderedDict([
                           ('fc1', nn.Linear(classifier_input_size, hidden_layer_size)),
                           ('activation', nn.SELU()),
                           ('dropout', nn.Dropout(p=0.5)),
                           ('fc2', nn.Linear(hidden_layer_size, output_layer_size)),
                           ('output', nn.LogSoftmax(dim=1))
                           ]))

但我得到 NameError,“OrderedDict”未定义。我想了解我在分类器步骤中做错了什么。在那之后,我仍然在努力理解如何在我自己的图像数据集上使用这个新模型和分类器(应该如何输入图像,指定为 0/1,指定为训练/测试等)。任何您可以指出我的帮助或教程将不胜感激。

【问题讨论】:

  • 请告诉python的版本

标签: python resnet transfer-learning torchvision image-classification


【解决方案1】:

您需要使用以下命令导入 OrderedDict

from collections import OrderedDict 

然后它会工作。

欲了解更多信息,请访问Link

【讨论】:

    猜你喜欢
    • 2020-06-09
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    • 2019-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    相关资源
    最近更新 更多