Bắt đầu ngayBắt đầu miễn phí

Phân tích cảm xúc video với CLIP CLAP

Giờ bạn sẽ phân tích cảm xúc của mẫu quảng cáo bạn đã chuẩn bị trước đó bằng CLIP/CLAP. Để phân loại cảm xúc theo hướng đa phương thức, bạn sẽ kết hợp dự đoán của các mô hình này bằng cách lấy trung bình (được gọi là late fusion).

Video (video) và âm thanh tương ứng (audio_sample) bạn đã tạo trước đó vẫn còn sẵn:

Frames from the Bounce TV commercial

Một danh sách cảm xúc đã được nạp vào biến emotions.

Bài tập này là một phần của khóa học

Mô hình đa phương thức với Hugging Face

Xem khóa học

Hướng dẫn bài tập

  • Tạo một pipeline phân loại âm thanh cho zero-shot-audio-classification dùng mô hình laion/clap-htsat-unfused.
  • Tạo một pipeline phân loại ảnh cho zero-shot-image-classification dùng mô hình openai/clip-vit-base-patch32 (một biến thể nhỏ hơn so với mô hình dùng trong video).
  • Dùng pipeline phân loại ảnh để tạo dự đoán cho từng ảnh trong video.
  • Dùng pipeline phân loại âm thanh để tạo dự đoán cho audio_sample.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

# 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}")
Chỉnh sửa và Chạy Mã