【问题标题】:Fine Tuning Pretrained Model MobileNet_V3_Large PyTorch微调预训练模型 MobileNet_V3_Large PyTorch
【发布时间】:2021-11-18 03:23:53
【问题描述】:

我正在尝试添加一个层来微调 MobileNet_V3_Large 预训练模型。我查看了 PyTorch 文档,但他们没有针对这个特定的预训练模型的教程。我确实发现我可以使用以下方法微调 MobileNet_V2:

model_ft =models.mobilenet_v2(pretrained=True,progress=True)
    
model_ft.classifier[1] = nn.Linear(model_ft.last_channel, out_features=len(class_names))

但我不确定 MobileNet V3 的线性层应该是什么样子。

【问题讨论】:

    标签: pytorch


    【解决方案1】:

    对于 V3 Large,您应该这样做

    model_ft = models.mobilenet_v3_large(pretrained=True, progress=True)
    model_ft.classifier[-1] = nn.Linear(1280, your_number_of_classes)
    

    (这也适用于 V2,但您发布的代码不适用于 V3)。

    要查看网络结构,您可以这样做

    print(model_ft.classifier)
    

    或

    print(model_ft)
    

    为了进行微调,人们经常(但不总是)冻结除最后一层之外的所有层。同样,不冻结的层是model_ft.classifier[-1],而不是model_ft.classifier[1]。

    是否应该冻结图层取决于您拥有多少数据,最好凭经验确定。

    【讨论】:

      猜你喜欢
      • 2019-12-08
      • 2017-06-05
      • 2019-09-11
      • 2018-02-20
      • 2021-04-05
      • 2019-01-22
      • 2021-10-29
      • 2020-02-07
      • 2019-07-17
      相关资源
      最近更新 更多