hexuan21 commited on
Commit
368fab4
·
verified ·
1 Parent(s): 7088b05

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +190 -1
README.md CHANGED
@@ -12,4 +12,193 @@ base_model:
12
  pipeline_tag: visual-question-answering
13
  ---
14
 
15
- TODO
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  pipeline_tag: visual-question-answering
13
  ---
14
 
15
+ [📃Paper](https://www.arxiv.org/abs/2509.22799) | [🌐Website](https://tiger-ai-lab.github.io/VideoScore2/) | [💻Github](https://github.com/TIGER-AI-Lab/VideoScore2) | [🛢️Datasets](https://huggingface.co/datasets/TIGER-Lab/VideoFeedback2) | [🤗Model (VideoScore2)](https://huggingface.co/TIGER-Lab/VideoScore2)
16
+
17
+
18
+ ![VideoScore](https://tiger-ai-lab.github.io/VideoScore2/static/images/teaser.png)
19
+
20
+
21
+ ## Introduction
22
+
23
+ ## Usage
24
+
25
+ ### Inference
26
+ For running inference of VideoScore2, firstly install:
27
+ ```
28
+ pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0
29
+ pip install transformers==4.53.2
30
+ pip install qwen-vl-utils
31
+ pip install accelerate
32
+ pip install scipy
33
+ pip install opencv-python-headless
34
+ pip install numpy==2.2.6
35
+ ```
36
+
37
+ Run inference over one video:
38
+ ```
39
+ from transformers import AutoProcessor, AutoModelForVision2Seq, AutoTokenizer
40
+ from qwen_vl_utils import process_vision_info
41
+ import torch
42
+ import numpy as np
43
+ import cv2
44
+ import os
45
+ import re
46
+ from string import Template
47
+
48
+ def _get_video_fps(url_or_p: str):
49
+ cap = cv2.VideoCapture(url_or_p)
50
+ if not cap.isOpened():
51
+ raise ValueError(f"Cannot open video: {url_or_p}")
52
+ fps = cap.get(cv2.CAP_PROP_FPS)
53
+ cap.release()
54
+ return fps
55
+
56
+ def ll_based_soft_score_normed(hard_val, token_idx, scores, tokenizer):
57
+ if hard_val is None or token_idx < 0:
58
+ return None
59
+ logits = scores[token_idx][0]
60
+ score_range = list(range(1, 6))
61
+ score_probs = []
62
+ for s in score_range:
63
+ ids = tokenizer.encode(str(s), add_special_tokens=False)
64
+ if len(ids) == 1:
65
+ tid = ids[0]
66
+ logp = torch.log_softmax(logits, dim=-1)[tid].item()
67
+ prob = float(np.exp(logp))
68
+ score_probs.append((s, prob))
69
+ if not score_probs:
70
+ print("[warn] No valid score token found.")
71
+ return None
72
+ scores_list, probs_list = zip(*score_probs)
73
+ total_prob = sum(probs_list)
74
+ max_prob = max(probs_list)
75
+ best_score = scores_list[probs_list.index(max_prob)]
76
+ normalized_prob = max_prob / total_prob if total_prob > 0 else 0
77
+ return round(best_score * normalized_prob, 4)
78
+
79
+ def find_score_token_index_by_prompt(prompt_text, tokenizer, gen_ids):
80
+ gen_str = tokenizer.decode(gen_ids, skip_special_tokens=False)
81
+ pattern = r"(?:\(\d+\)\s*|\n\s*)?" + re.escape(prompt_text)
82
+ match = re.search(pattern, gen_str, flags=re.IGNORECASE)
83
+ if not match:
84
+ return -1
85
+ after_text = gen_str[match.end():]
86
+ num_match = re.search(r"\d", after_text)
87
+ if not num_match:
88
+ return -1
89
+ target_substr = gen_str[:match.end() + num_match.start() + 1]
90
+ for i in range(len(gen_ids)):
91
+ partial = tokenizer.decode(gen_ids[:i+1], skip_special_tokens=False)
92
+ if partial == target_substr:
93
+ return i
94
+ return -1
95
+
96
+ def main(MODEL_NAME, video_path, t2v_prompt):
97
+ # --- prepare query ---
98
+ VS2_QUERY_TEMPLATE = Template("""
99
+ You are an expert for evaluating AI-generated videos from three dimensions:
100
+ (1) visual quality – clarity, smoothness, artifacts;
101
+ (2) text-to-video alignment – fidelity to the prompt;
102
+ (3) physical/common-sense consistency – naturalness and physics plausibility.
103
+
104
+ Video prompt: $t2v_prompt
105
+
106
+ Please output in this format:
107
+ visual quality: <v_score>;
108
+ text-to-video alignment: <t_score>,
109
+ physical/common-sense consistency: <p_score>
110
+ """)
111
+ user_prompt = VS2_QUERY_TEMPLATE.substitute(t2v_prompt=t2v_prompt)
112
+
113
+ if not os.path.exists(video_path):
114
+ raise ValueError(f"Video not found: {video_path}")
115
+
116
+ infer_fps, max_tokens, temperature = 2.0, 1024, 0.7
117
+ if infer_fps == "raw":
118
+ infer_fps = _get_video_fps(video_path)
119
+
120
+ print(f"[Init] Loading model: {MODEL_NAME}")
121
+ model = AutoModelForVision2Seq.from_pretrained(MODEL_NAME, trust_remote_code=True).to("cuda")
122
+ processor = AutoProcessor.from_pretrained(MODEL_NAME, trust_remote_code=True)
123
+ tokenizer = getattr(processor, "tokenizer", None) or AutoTokenizer.from_pretrained(
124
+ MODEL_NAME, trust_remote_code=True, use_fast=False
125
+ )
126
+
127
+ # --- preprocess ---
128
+ messages = [{"role": "user", "content": [
129
+ {"type": "video", "video": video_path, "fps": infer_fps},
130
+ {"type": "text", "text": user_prompt}
131
+ ]}]
132
+ text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
133
+ image_inputs, video_inputs = process_vision_info(messages)
134
+
135
+ inputs = processor(
136
+ text=[text], images=image_inputs, videos=video_inputs,
137
+ fps=infer_fps, padding=True, return_tensors="pt"
138
+ ).to("cuda")
139
+
140
+ # --- inference ---
141
+ gen_out = model.generate(
142
+ **inputs,
143
+ max_new_tokens=max_tokens,
144
+ output_scores=True,
145
+ return_dict_in_generate=True,
146
+ do_sample=True,
147
+ temperature=temperature,
148
+ )
149
+
150
+ sequences = gen_out.sequences
151
+ scores = gen_out.scores
152
+ input_len = inputs["input_ids"].shape[1]
153
+ gen_token_ids = sequences[0, input_len:].tolist()
154
+
155
+ output_text = processor.batch_decode(
156
+ sequences[:, input_len:], skip_special_tokens=True, clean_up_tokenization_spaces=False
157
+ )[0]
158
+ print("\n[Raw Model Output]\n", output_text)
159
+
160
+ # --- parse scores ---
161
+ pattern = r"visual quality:\s*(\d+).*?text-to-video alignment:\s*(\d+).*?physical/common-sense consistency:\s*(\d+)"
162
+ match = re.search(pattern, output_text, re.DOTALL | re.IGNORECASE)
163
+ v_score = int(match.group(1)) if match else None
164
+ t_score = int(match.group(2)) if match else None
165
+ p_score = int(match.group(3)) if match else None
166
+
167
+ idx_v = find_score_token_index_by_prompt("visual quality:", tokenizer, gen_token_ids)
168
+ idx_t = find_score_token_index_by_prompt("text-to-video alignment:", tokenizer, gen_token_ids)
169
+ idx_p = find_score_token_index_by_prompt("physical/common-sense consistency:", tokenizer, gen_token_ids)
170
+
171
+ v_soft = ll_based_soft_score_normed(v_score, idx_v, scores, tokenizer)
172
+ t_soft = ll_based_soft_score_normed(t_score, idx_t, scores, tokenizer)
173
+ p_soft = ll_based_soft_score_normed(p_score, idx_p, scores, tokenizer)
174
+
175
+ print("\n====== Inference Result ======")
176
+ print(f"Video Path: {video_path}")
177
+ print(f"Visual Quality: {v_soft}")
178
+ print(f"Text-to-Video Alignment: {t_soft}")
179
+ print(f"Physical Consistency: {p_soft}")
180
+ print("==============================\n")
181
+
182
+ if __name__ == "__main__":
183
+ MODEL_NAME = "TIGER-Lab/VideoScore2"
184
+ video_path = "" # ← your video path here
185
+ t2v_prompt = "" # ← the text prompt for this video
186
+ main(MODEL_NAME, video_path, t2v_prompt)
187
+ ```
188
+
189
+ ### Training (SFT and RL)
190
+ see [VideoScore2/training](https://github.com/TIGER-AI-Lab/VideoScore2/tree/main/training) for details
191
+
192
+ ### Evaluation
193
+ see [VideoScore2/evaluation](https://github.com/TIGER-AI-Lab/VideoScore2/tree/main/eval) for details
194
+
195
+ ## Citation
196
+ @misc{he2025videoscore2thinkscoregenerative,
197
+ title={VideoScore2: Think before You Score in Generative Video Evaluation},
198
+ author={Xuan He and Dongfu Jiang and Ping Nie and Minghao Liu and Zhengxuan Jiang and Mingyi Su and Wentao Ma and Junru Lin and Chun Ye and Yi Lu and Keming Wu and Benjamin Schneider and Quy Duc Do and Zhuofeng Li and Yiming Jia and Yuxuan Zhang and Guo Cheng and Haozhe Wang and Wangchunshu Zhou and Qunshu Lin and Yuanxing Zhang and Ge Zhang and Wenhao Huang and Wenhu Chen},
199
+ year={2025},
200
+ eprint={2509.22799},
201
+ archivePrefix={arXiv},
202
+ primaryClass={cs.CV},
203
+ url={https://arxiv.org/abs/2509.22799},
204
+ }