微调预训练模型 MobileNet_V3_Large PyTorch
Fine Tuning Pretrained Model MobileNet_V3_Large PyTorch
我正在尝试添加一个层来微调 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 的线性层应该是什么样子。
对于 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)
对于微调,人们经常(但不总是)冻结除最后一层之外的所有层。同样,not 冻结的层是 model_ft.classifier[-1]
而不是 model_ft.classifier[1]
。
是否应冻结图层取决于您拥有多少数据,最好根据经验确定。
我正在尝试添加一个层来微调 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 的线性层应该是什么样子。
对于 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)
对于微调,人们经常(但不总是)冻结除最后一层之外的所有层。同样,not 冻结的层是 model_ft.classifier[-1]
而不是 model_ft.classifier[1]
。
是否应冻结图层取决于您拥有多少数据,最好根据经验确定。