簡體   English   中英

如何在 PyTorch 中使用 Inception model 進行遷移學習?

[英]How to use the Inception model for transfer learning in PyTorch?

我創建了一個 PyTorch torchvision model 用於遷移學習,使用預先構建的ResNet50基礎 model,如下所示:

        # Create base model from torchvision.models
        model = resnet50(pretrained=True)
        num_features = model.fc.in_features

        # Define the network head and attach it to the model
        model_head = nn.Sequential(
            nn.Linear(num_features, 512),
            nn.ReLU(),
            nn.Dropout(0.25),
            nn.Linear(512, 256),
            nn.ReLU(),
            nn.Dropout(0.5),
            nn.Linear(256, num_classes),
        )
        model.fc = model_head

現在我想使用Ineception v3 model 作為基礎,所以我從上面的resnet50()切換到inception_v3() ,rest 保持原樣。 但是,在訓練期間,我收到以下錯誤:

TypeError:cross_entropy_loss():參數“輸入”(位置 1)必須是張量,而不是 InceptionOutputs

那么如何使用來自torchvision.modelsInception v3 model 作為基礎 model 進行遷移學習?

來自關於 Inceptionv3 架構的 PyTorch 文檔:

這個網絡是獨一無二的,因為它在訓練時有兩個 output 層。 初級 output 是網絡末端的線性層。 第二個 output 稱為輔助 output,包含在網絡的 AuxLogits 部分中。

看看這個教程: https://pytorch.org/tutorials/beginner/finetuning_torchvision_models_tutorial.html#inception-v3在那里你可以找到如何將遷移學習用於幾個模型,包括 ResNet 和 Inception。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM