CLIP CLAP으로 비디오 감정 분석
이제 이전에 준비한 광고를 CLIP/CLAP으로 감정 분석해 볼게요. 감정을 멀티모달로 분류하기 위해, 두 모델의 예측값을 평균으로 결합해요(이를 late fusion이라고 합니다).
앞서 만든 비디오(video)와 이에 대응하는 오디오(audio_sample)는 여전히 사용할 수 있어요:

감정 목록은 emotions로 로드되어 있어요.
이 연습은 강의의 일부입니다
Hugging Face로 배우는 멀티모달 모델
연습 안내
laion/clap-htsat-unfused모델을 사용해zero-shot-audio-classification용 오디오 분류 파이프라인을 만드세요.openai/clip-vit-base-patch32모델을 사용해zero-shot-image-classification용 이미지 분류 파이프라인을 만드세요(영상에서 사용한 모델의 더 작은 변형입니다).- 이미지 분류 파이프라인으로 비디오의 각 이미지에 대한 예측을 생성하세요.
- 오디오 분류 파이프라인으로
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}")