開始使用免費開始

影像分類

在這個練習中,你會使用和前面相同的 flickr 資料集,其中包含 30,000 張影像與其標註文字。現在你要用預訓練模型來為影像分類。

Photo of 2 people, 1 is playing the guitar

範例影像(image)與 pipeline 模組(pipeline)都已載入。

本練習屬於課程

使用 Hugging Face 的多模態模型

檢視課程

練習說明

  • 載入 image-classification pipeline,並使用 google/mobilenet_v2_1.0_224 預訓練模型。
  • 使用該 pipeline 預測範例影像的類別。
  • 列印第一個(機率最高)的 label

動手互動練習

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

# Load the image-classification pipeline
pipe = ____

# Use the pipeline to predict the class of the sample image
pred = ____

# Print the first (highest probability) label
print("Predicted class:", ____)
編輯並執行程式碼