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

範例影像(image)與 pipeline 模組(pipeline)都已載入。
本練習屬於課程
使用 Hugging Face 的多模態模型
練習說明
- 載入
image-classificationpipeline,並使用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:", ____)