開始使用免費開始

預先訓練模型的 backbone

現在該來建構 R-CNN 架構了!你會使用 vgg16 預先訓練模型的 backbone 來做特徵擷取。別忘了同時儲存 backbone 的輸出形狀,因為它會作為後續模組(分類器與方框回歸器)的輸入形狀。

已匯入 torchtorchvision、以及以 nn 命名的 torch.nn。 模型已以 vgg16 匯入,權重儲存在 VGG16_Weights

本練習屬於課程

使用 PyTorch 進行影像深度學習

檢視課程

練習說明

  • 載入預先訓練的 VGG16 權重。
  • 使用 .children()classifier 當成 sequential 區塊,從第一層擷取 in_features,並將其儲存為 input_dim
  • 使用 features.children() 建立一個作為 sequential 區塊的 backbone。
  • 印出這個 backbone 模型。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Load pretrained weights
vgg_model = vgg16(weights=____)

# Extract the input dimension
input_dim = nn.Sequential(*list(vgg_model.classifier.____()))[0].____

# Create a backbone with convolutional layers
backbone = nn.Sequential(*list(____))

# Print the backbone model
____
編輯並執行程式碼