開始使用免費開始

載入預先訓練的模型

你正在打造一個從社群媒體圖片自動加上標籤的應用程式。這個工作需要高準確率與高速度。你將使用預先訓練好的 ResNet18 模型來推論影像的類別。

本練習屬於課程

使用 PyTorch 進行影像深度學習

檢視課程

練習說明

  • torchvision.models 匯入 resnet18ResNet18_Weights
  • 使用 resnet18() 建立 model,並將 weights 參數設為 weights
  • model 設定為評估模式。
  • 初始化輸入轉換,並指派給 transform

動手互動練習

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

# Import resnet18 model
from torchvision.models import ____

# Initialize model with default weights
weights = ResNet18_Weights.DEFAULT
model = ____

# Set model to evaluation mode
model.____

# Initialize the transforms
transform = ____
編輯並執行程式碼