自動化標題品質評估
你已經正確分類了這件洋裝的圖片,但原始描述到底寫得多好呢?
Maa Fab wrap with a Trendy design dress with Vibrant color for an elegant touch of Fabric completely Soft and Comfortable wear with amazing design of Solid Boat ? Neck Flared Dress to make a perfect addition to your wardrobe collection.
現在你要使用 CLIP 模型,透過 CLIP 分數來量化這段描述的準確度。已載入的物件包含:標題(description)、影像(image)、ToTensor 類別,以及來自 torchmetrics 的 clip_score() 函式。
本練習屬於課程
使用 Hugging Face 的多模態模型
練習說明
- 將影像轉換成 PyTorch 張量,強度範圍為 0–255。
- 使用
clip_score()函式,以openai/clip-vit-base-patch32模型比較image_tensor與description,評估標題的品質。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Convert the image to a PyTorch tensor
image_tensor = ____()(image)*____
# Use the clip_score function to assess the quality of the caption
score = ____(____, ____, "____")
print(f"CLIP score: {score}")