ประเมินประสิทธิภาพการสร้างวิดีโอ
คุณสามารถประเมินประสิทธิภาพของ pipeline การสร้างวิดีโอได้โดยใช้โมเดล CLIP แบบ multi-modal ซึ่งทดสอบความคล้ายคลึงระหว่างภาพแต่ละเฟรมของวิดีโอกับ prompt นำสิ่งนี้ไปใช้ประเมินว่าวิดีโอที่สร้างขึ้นจากแบบฝึกหัดก่อนหน้าตรงกับ prompt มากน้อยเพียงใด
ฟังก์ชัน load_video() ได้ถูก import มาจาก diffusers.utils ให้แล้ว และโมดูล clip_score ก็ได้ถูก import มาจาก torchmetrics เช่นกัน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
โมเดล Multi-Modal ด้วย Hugging Face
คำแนะนำการฝึกหัด
- สร้างฟังก์ชันคำนวณคะแนน CLIP ชื่อ
clip_score_fn()จากเมตริกclip_score() - คำนวณคะแนน CLIP ระหว่าง frame tensor แต่ละตัวใน
frame_tensorsกับprompt
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Setup CLIP scoring
clip_score_fn = partial(____, model_name_or_path="openai/clip-vit-base-patch32")
frame_tensors = []
for frame in frames:
frame = np.array(frame)
frame_int = (frame * 255).astype("uint8")
frame_tensor = torch.from_numpy(frame_int).permute(2, 0, 1)
frame_tensors.append(frame_tensor)
# Pass a list of CHW tensors as expected by clip_score
scores = clip_score_fn(____, [____] * len(frame_tensors)).detach().cpu().numpy()
avg_clip_score = round(np.mean(scores), 4)
print(f"Average CLIP score: {avg_clip_score}")