hexuan21 commited on
Commit
472e87c
1 Parent(s): e07b172

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +151 -3
README.md CHANGED
@@ -1,3 +1,151 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - TIGER-Lab/VideoFeedback
5
+ language:
6
+ - en
7
+ metrics:
8
+ - accuracy/spcc
9
+ library_name: transformers
10
+ pipeline_tag: visual-question-answering
11
+ ---
12
+
13
+ [📃Paper](https://arxiv.org/abs/2406.15252) | [🌐Website](https://tiger-ai-lab.github.io/VideoScore/) | [💻Github](https://github.com/TIGER-AI-Lab/VideoScore) | [🛢️Datasets](https://huggingface.co/datasets/TIGER-Lab/VideoFeedback) | [🤗Model](https://huggingface.co/TIGER-Lab/VideoScore-v1.1) | [🤗Demo](https://huggingface.co/spaces/TIGER-Lab/VideoScore) | [📉Wandb](https://api.wandb.ai/links/xuanhe/ptohlfcx)
14
+
15
+
16
+ ![VideoScore](https://tiger-ai-lab.github.io/VideoScore/static/images/teaser.png)
17
+
18
+ ## Introduction
19
+ - VideoScore-v1.1 is a variant from [VideoScore](https://huggingface.co/TIGER-Lab/VideoScore), which is a video quality evaluation model, taking [Mantis-8B-Idefics2](https://huggingface.co/TIGER-Lab/Mantis-8B-Idefics2) as base-model
20
+ and trained on [VideoFeedback](https://huggingface.co/datasets/TIGER-Lab/VideoFeedback),
21
+ a large video evaluation dataset with multi-aspect human scores.
22
+
23
+ - Following VideoScore, VideoScore-v1.1 can also reach about 75 Spearman correlation with humans on VideoFeedback-test, surpassing all the MLLM-prompting methods and feature-based metrics.
24
+ VideoScore-v1.1 also beat the best baselines on other two benchmarks GenAI-Bench and VBench, showing high alignment with human evaluations.
25
+ For the data details of these benchmarks, please refer to [VideoScore-Bench](https://huggingface.co/datasets/TIGER-Lab/VideoScore-Bench).
26
+
27
+ - VideoScore-v1.1 is a **regression version** model.
28
+
29
+ -
30
+
31
+ ## Usage
32
+ ### Installation
33
+ ```
34
+ pip install git+https://github.com/TIGER-AI-Lab/VideoScore.git
35
+ # or
36
+ # pip install mantis-vl
37
+ ```
38
+
39
+ ### Inference
40
+ ```
41
+ cd VideoScore/examples
42
+ ```
43
+
44
+ ```python
45
+ import av
46
+ import numpy as np
47
+ from typing import List
48
+ from PIL import Image
49
+ import torch
50
+ from transformers import AutoProcessor
51
+ from mantis.models.idefics2 import Idefics2ForSequenceClassification
52
+ def _read_video_pyav(
53
+ frame_paths:List[str],
54
+ max_frames:int,
55
+ ):
56
+ frames = []
57
+ container.seek(0)
58
+ start_index = indices[0]
59
+ end_index = indices[-1]
60
+ for i, frame in enumerate(container.decode(video=0)):
61
+ if i > end_index:
62
+ break
63
+ if i >= start_index and i in indices:
64
+ frames.append(frame)
65
+ return np.stack([x.to_ndarray(format="rgb24") for x in frames])
66
+
67
+ ## in VideoScore-v1.1, we support 48 frames in inference
68
+ MAX_NUM_FRAMES=48
69
+
70
+ ROUND_DIGIT=3
71
+ REGRESSION_QUERY_PROMPT = """
72
+ Suppose you are an expert in judging and evaluating the quality of AI-generated videos,
73
+ please watch the following frames of a given video and see the text prompt for generating the video,
74
+ then give scores from 5 different dimensions:
75
+ (1) visual quality: the quality of the video in terms of clearness, resolution, brightness, and color
76
+ (2) temporal consistency, both the consistency of objects or humans and the smoothness of motion or movements
77
+ (3) dynamic degree, the degree of dynamic changes
78
+ (4) text-to-video alignment, the alignment between the text prompt and the video content
79
+ (5) factual consistency, the consistency of the video content with the common-sense and factual knowledge
80
+ for each dimension, output a float number from 1.0 to 4.0,
81
+ the higher the number is, the better the video performs in that sub-score,
82
+ the lowest 1.0 means Bad, the highest 4.0 means Perfect/Real (the video is like a real video)
83
+ Here is an output example:
84
+ visual quality: 3.2
85
+ temporal consistency: 2.7
86
+ dynamic degree: 4.0
87
+ text-to-video alignment: 2.3
88
+ factual consistency: 1.8
89
+ For this video, the text prompt is "{text_prompt}",
90
+ all the frames of video are as follows:
91
+ """
92
+ model_name="TIGER-Lab/VideoScore-v1.1"
93
+ video_path="video1.mp4"
94
+ video_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."
95
+ processor = AutoProcessor.from_pretrained(model_name,torch_dtype=torch.bfloat16)
96
+ model = Idefics2ForSequenceClassification.from_pretrained(model_name,torch_dtype=torch.bfloat16).eval()
97
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
98
+ model.to(device)
99
+ # sample uniformly 8 frames from the video
100
+ container = av.open(video_path)
101
+ total_frames = container.streams.video[0].frames
102
+ if total_frames > MAX_NUM_FRAMES:
103
+ indices = np.arange(0, total_frames, total_frames / MAX_NUM_FRAMES).astype(int)
104
+ else:
105
+ indices = np.arange(total_frames)
106
+ frames = [Image.fromarray(x) for x in _read_video_pyav(container, indices)]
107
+ eval_prompt = REGRESSION_QUERY_PROMPT.format(text_prompt=video_prompt)
108
+ num_image_token = eval_prompt.count("<image>")
109
+ if num_image_token < len(frames):
110
+ eval_prompt += "<image> " * (len(frames) - num_image_token)
111
+ flatten_images = []
112
+ for x in [frames]:
113
+ if isinstance(x, list):
114
+ flatten_images.extend(x)
115
+ else:
116
+ flatten_images.append(x)
117
+ flatten_images = [Image.open(x) if isinstance(x, str) else x for x in flatten_images]
118
+ inputs = processor(text=eval_prompt, images=flatten_images, return_tensors="pt")
119
+ inputs = {k: v.to(model.device) for k, v in inputs.items()}
120
+ with torch.no_grad():
121
+ outputs = model(**inputs)
122
+ logits = outputs.logits
123
+ num_aspects = logits.shape[-1]
124
+ aspect_scores = []
125
+ for i in range(num_aspects):
126
+ aspect_scores.append(round(logits[0, i].item(),ROUND_DIGIT))
127
+ print(aspect_scores)
128
+ """
129
+ model output on visual quality, temporal consistency, dynamic degree,
130
+ text-to-video alignment, factual consistency, respectively
131
+ [2.328, 2.484, 2.562, 1.969, 2.594]
132
+ """
133
+ ```
134
+
135
+ ### Training
136
+ see [VideoScore/training](https://github.com/TIGER-AI-Lab/VideoScore/tree/main/training) for details
137
+
138
+ ### Evaluation
139
+ see [VideoScore/benchmark](https://github.com/TIGER-AI-Lab/VideoScore/tree/main/benchmark) for details
140
+
141
+ ## Citation
142
+ ```bibtex
143
+ @article{he2024videoscore,
144
+ title = {VideoScore: Building Automatic Metrics to Simulate Fine-grained Human Feedback for Video Generation},
145
+ 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},
146
+ journal = {ArXiv},
147
+ year = {2024},
148
+ volume={abs/2406.15252},
149
+ url = {https://arxiv.org/abs/2406.15252},
150
+ }
151
+ ```