เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Zero-shot learning ด้วย CLIP

ในแบบฝึกหัดนี้จะใช้ zero-shot learning เพื่อจำแนกรูปภาพจากชุดข้อมูล rajuptvs/ecommerce_products_clip ซึ่งมีภาพสินค้าประมาณ 2,000 รายการพร้อมคำอธิบายที่เกี่ยวข้อง:

Image of a woman modeling a dress

ชุดข้อมูล (dataset), CLIPProcessor (processor) และ CLIPModel (model) ถูกโหลดไว้ให้แล้ว พร้อมกับรายการหมวดหมู่ดังนี้:

categories = ["shirt", "trousers", "shoes", "dress", "hat", 
              "bag", "watch", "glasses", "jacket", "belt"]

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

โมเดล Multi-Modal ด้วย Hugging Face

ดูคอร์ส

คำแนะนำการฝึกหัด

  • ใช้ processor เพื่อประมวลผล categories และรูปภาพที่ index 999 ของ dataset โดยเปิดใช้งาน padding
  • ส่ง inputs ที่ unpack แล้วเข้าสู่ model
  • คำนวณค่าความน่าจะเป็นของแต่ละหมวดหมู่โดยใช้ attribute .logits_per_image และเมธอด .softmax()
  • ระบุหมวดหมู่ที่เป็นไปได้มากที่สุดโดยใช้ probs และ categories

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Preprocess the categories and image 
inputs = ____(text=____, images=____, return_tensors="pt", padding=____)

# Process the unpacked inputs with the model
outputs = ____

# Calculate the probabilities of each category
probs = outputs.____.____(dim=1)

# Find the most likely category
category = categories[probs.____.item()]
print(f"Predicted category: {category}")
แก้ไขและรันโค้ด