Views
No views yet

| metric | VideoFeedback-test |
|---|---|
| VideoScore-v1.1 | 74.0 |
| Gemini-1.5-Pro | 22.1 |
| Gemini-1.5-Flash | 20.8 |
| GPT-4o | 23.1 |
| CLIP-sim | 8.9 |
| DINO-sim | 7.5 |
| SSIM-sim | 13.4 |
| CLIP-Score | -7.2 |
| LLaVA-1.5-7B | 8.5 |
| LLaVA-1.6-7B | -3.1 |
| X-CLIP-Score | -1.9 |
| PIQE | -10.1 |
| BRISQUE | -20.3 |
| Idefics2 | 6.5 |
| MSE-dyn | -5.5 |
| SSIM-dyn | -12.9 |
pip install git+https://github.com/TIGER-AI-Lab/VideoScore.git
# or
# pip install mantis-vlcd VideoScore/examples1import av
2import numpy as np
3from typing import List
4from PIL import Image
5import torch
6from transformers import AutoProcessor
7from mantis.models.idefics2 import Idefics2ForSequenceClassification
8def _read_video_pyav(
9 frame_paths:List[str],
10 max_frames:int,
11):
12 frames = []
13 container.seek(0)
14 start_index = indices[0]
15 end_index = indices[-1]
16 for i, frame in enumerate(container.decode(video=0)):
17 if i > end_index:
18 break
19 if i >= start_index and i in indices:
20 frames.append(frame)
21 return np.stack([x.to_ndarray(format="rgb24") for x in frames])
22
23ROUND_DIGIT=3
24REGRESSION_QUERY_PROMPT = """
25Suppose you are an expert in judging and evaluating the quality of AI-generated videos,
26please watch the following frames of a given video and see the text prompt for generating the video,
27then give scores from 5 different dimensions:
28(1) visual quality: the quality of the video in terms of clearness, resolution, brightness, and color
29(2) temporal consistency, both the consistency of objects or humans and the smoothness of motion or movements
30(3) dynamic degree, the degree of dynamic changes
31(4) text-to-video alignment, the alignment between the text prompt and the video content
32(5) factual consistency, the consistency of the video content with the common-sense and factual knowledge
33for each dimension, output a float number from 1.0 to 4.0,
34the higher the number is, the better the video performs in that sub-score,
35the lowest 1.0 means Bad, the highest 4.0 means Perfect/Real (the video is like a real video)
36Here is an output example:
37visual quality: 3.2
38temporal consistency: 2.7
39dynamic degree: 4.0
40text-to-video alignment: 2.3
41factual consistency: 1.8
42For this video, the text prompt is "{text_prompt}",
43all the frames of video are as follows:
44"""
45
46# MAX_NUM_FRAMES=16
47# model_name="TIGER-Lab/VideoScore"
48
49# =======================================
50# we support 48 frames in VideoScore-v1.1
51# =======================================
52MAX_NUM_FRAMES=48
53model_name="TIGER-Lab/VideoScore-v1.1"
54
55video_path="video1.mp4"
56video_prompt="Near the Elephant Gate village, they approach the haunted house at night. Rajiv feels anxious, but Bhavesh encourages him. As they reach the house, a mysterious sound in the air adds to the suspense."
57
58processor = AutoProcessor.from_pretrained(model_name,torch_dtype=torch.bfloat16)
59model = Idefics2ForSequenceClassification.from_pretrained(model_name,torch_dtype=torch.bfloat16).eval()
60device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
61model.to(device)
62
63# sample uniformly 8 frames from the video
64container = av.open(video_path)
65total_frames = container.streams.video[0].frames
66if total_frames > MAX_NUM_FRAMES:
67 indices = np.arange(0, total_frames, total_frames / MAX_NUM_FRAMES).astype(int)
68else:
69 indices = np.arange(total_frames)
70
71frames = [Image.fromarray(x) for x in _read_video_pyav(container, indices)]
72eval_prompt = REGRESSION_QUERY_PROMPT.format(text_prompt=video_prompt)
73num_image_token = eval_prompt.count("<image>")
74if num_image_token < len(frames):
75 eval_prompt += "<image> " * (len(frames) - num_image_token)
76flatten_images = []
77for x in [frames]:
78 if isinstance(x, list):
79 flatten_images.extend(x)
80 else:
81 flatten_images.append(x)
82
83flatten_images = [Image.open(x) if isinstance(x, str) else x for x in flatten_images]
84inputs = processor(text=eval_prompt, images=flatten_images, return_tensors="pt")
85inputs = {k: v.to(model.device) for k, v in inputs.items()}
86
87with torch.no_grad():
88 outputs = model(**inputs)
89logits = outputs.logits
90num_aspects = logits.shape[-1]
91aspect_scores = []
92for i in range(num_aspects):
93 aspect_scores.append(round(logits[0, i].item(),ROUND_DIGIT))
94
95print(aspect_scores)
96"""
97model output on visual quality, temporal consistency, dynamic degree,
98text-to-video alignment, factual consistency, respectively
99VideoScore:
100[2.297, 2.469, 2.906, 2.766, 2.516]
101
102VideoScore-v1.1:
103[2.328, 2.484, 2.562, 1.969, 2.594]
104"""1@article{he2024videoscore,
2 title = {VideoScore: Building Automatic Metrics to Simulate Fine-grained Human Feedback for Video Generation},
3 author = {He, Xuan and Jiang, Dongfu and Zhang, Ge and Ku, Max and Soni, Achint and Siu, Sherman and Chen, Haonan and Chandra, Abhranil and Jiang, Ziyan and Arulraj, Aaran and Wang, Kai and Do, Quy Duc and Ni, Yuansheng and Lyu, Bohan and Narsupalli, Yaswanth and Fan, Rongqi and Lyu, Zhiheng and Lin, Yuchen and Chen, Wenhu},
4 journal = {ArXiv},
5 year = {2024},
6 volume={abs/2406.15252},
7 url = {https://arxiv.org/abs/2406.15252},
8}