開始使用免費開始

使用 Pipeline 產生影像說明文字

在這個練習中,你會再次使用 flickr 資料集,它包含 30,000 張影像與對應的說明文字。這次你將改用 pipeline(而非 auto 類別)來為下列影像產生說明文字。

Photo of a man standing on a ladder cleaning a window

資料集(dataset)已載入,結構如下:

Dataset({
    features: ['image', 'caption', 'sentids', 'split', 'img_id', 'filename'],
    num_rows: 10
})

pipeline 模組(pipeline)已載入。

本練習屬於課程

使用 Hugging Face 的多模態模型

檢視課程

練習說明

  • 載入 image-to-text pipeline,並使用 Salesforce/blip-image-captioning-base 預訓練模型。
  • 使用該 pipeline 為索引為 3 的影像產生說明文字。

動手互動練習

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

# Load the image-to-text pipeline
pipe = pipeline(task="____", model="____")

# Use the pipeline to generate a caption with the image of datapoint 3
pred = ____(dataset[3]["____"])

print(pred)
編輯並執行程式碼