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

การวิเคราะห์ความรู้สึกจากวิดีโอด้วย CLIP CLAP

ตอนนี้จะทำการวิเคราะห์อารมณ์จากโฆษณาที่เตรียมไว้ก่อนหน้านี้โดยใช้ CLIP/CLAP เพื่อจำแนกอารมณ์แบบ multi-modal จะนำผลการทำนายของทั้งสองโมเดลมารวมกันด้วยค่าเฉลี่ย (เรียกว่า late fusion)

วิดีโอ (video) และไฟล์เสียงที่เกี่ยวข้อง (audio_sample) ที่สร้างไว้ก่อนหน้ายังคงพร้อมใช้งาน:

Frames from the Bounce TV commercial

โหลดรายการอารมณ์ไว้ในตัวแปร emotions แล้ว

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

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

ดูคอร์ส

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

  • สร้าง pipeline ตัวจำแนกเสียงสำหรับ zero-shot-audio-classification โดยใช้โมเดล laion/clap-htsat-unfused
  • สร้าง pipeline ตัวจำแนกภาพสำหรับ zero-shot-image-classification โดยใช้โมเดล openai/clip-vit-base-patch32 (ซึ่งเป็นเวอร์ชันที่เล็กกว่าที่ใช้ในวิดีโอ)
  • ใช้ pipeline ตัวจำแนกภาพเพื่อสร้างผลการทำนายสำหรับแต่ละเฟรมในวิดีโอ
  • ใช้ pipeline ตัวจำแนกเสียงเพื่อสร้างผลการทำนายสำหรับ audio_sample

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

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

# Make an audio classifier pipeline
audio_classifier = ____(model="____", task="____")

# Make an image classifier pipeline
image_classifier = ____(model="____", task="____")

# Create emotion scores for each video frame
predictions = image_classifier(video, candidate_labels=emotions)
scores = [
    {l['label']: l['score'] for l in prediction}
    for prediction in predictions
]

avg_image_scores = {emotion: sum([s[emotion] for s in scores])/len(scores) for emotion in emotions}

# Make audio scores
audio_scores = ____(____, candidate_labels=____)

audio_scores = {l['label']: l['score'] for l in audio_scores}
multimodal_scores = {emotion: (avg_image_scores[emotion] + audio_scores[emotion])/2 for emotion in emotions}
print(f"Multimodal scores: {multimodal_scores}")
แก้ไขและรันโค้ด