Views
No views yet
t2v_metrics approach which we recommend. The latter is a back-up approach directly using Qwen2.5-VL's inference demo.t2v_metrics Approach (recommended)1# Install the package using: pip install git+https://github.com/chancharikmitra/t2v_metrics.git
2
3import t2v_metrics
4
5### For a single (video, text) pair:
6qwen_score = t2v_metrics.VQAScore(model='qwen2.5-vl-7b', checkpoint='chancharikm/qwen2.5-vl-7b-cam-motion')
7video = "videos/baby.mp4" # a video path in string format
8text = "a baby crying"
9# Calculate probability of "Yes" response
10score = qwen_score(images=[video], texts=[text])1# Import necessary libraries
2from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
3from qwen_vl_utils import process_vision_info
4import torch
5
6# Load the model
7model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
8 "chancharikm/qwen2.5-vl-7b-cam-motion", torch_dtype="auto", device_map="auto"
9)
10processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
11
12# Prepare input data
13video_path = "file:///path/to/video1.mp4"
14text_description = "the camera tilting upward"
15question = f"Does this video show \"{text_description}\"?"
16
17# Format the input for the model
18messages = [
19 {
20 "role": "user",
21 "content": [
22 {
23 "type": "video",
24 "video": video_path,
25 "fps": 8.0, # Recommended FPS for optimal inference
26 },
27 {"type": "text", "text": question},
28 ],
29 }
30]
31
32text = processor.apply_chat_template(
33 messages, tokenize=False, add_generation_prompt=True
34)
35image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)
36inputs = processor(
37 text=[text],
38 images=image_inputs,
39 videos=video_inputs,
40 padding=True,
41 return_tensors="pt",
42 **video_kwargs
43)
44inputs = inputs.to("cuda")
45
46# Generate with score output
47with torch.inference_mode():
48 outputs = model.generate(
49 **inputs,
50 max_new_tokens=1,
51 do_sample=False, # Use greedy decoding to get reliable logprobs
52 output_scores=True,
53 return_dict_in_generate=True
54 )
55
56# Calculate probability of "Yes" response
57scores = outputs.scores[0]
58probs = torch.nn.functional.softmax(scores, dim=-1)
59yes_token_id = processor.tokenizer.encode("Yes")[0]
60score = probs[0, yes_token_id].item()
61
62print(f"Video: {video_path}")
63print(f"Description: '{text_description}'")
64print(f"Score: {score:.4f}")t2v_metrics approach which we recommend. The latter is a back-up approach directly using Qwen2.5-VL's inference demo.t2v_metrics Approach (recommended)1# Install the package using: pip install git+https://github.com/chancharikmitra/t2v_metrics.git
2
3import t2v_metrics
4
5### For a single (video, text) pair:
6qwen_score = t2v_metrics.VQAScore(model='qwen2.5-vl-7b', checkpoint='chancharikm/qwen2.5-vl-7b-cam-motion')
7video = "videos/baby.mp4" # a video path in string format
8text = "Please describe this image: "
9# Calculate probability of "Yes" response
10score = qwen_score.model.generate(images=[video], texts=[text])1# The model is trained on 8.0 FPS which we recommend for optimal inference
2
3from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
4from qwen_vl_utils import process_vision_info
5
6# default: Load the model on the available device(s)
7model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
8 "chancharikm/qwen2.5-vl-7b-cam-motion", torch_dtype="auto", device_map="auto"
9)
10
11# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
12# model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
13# "chancharikm/qwen2.5-vl-7b-cam-motion",
14# torch_dtype=torch.bfloat16,
15# attn_implementation="flash_attention_2",
16# device_map="auto",
17# )
18
19# default processor
20processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
21
22messages = [
23 {
24 "role": "user",
25 "content": [
26 {
27 "type": "video",
28 "video": "file:///path/to/video1.mp4",
29 "fps": 8.0,
30 },
31 {"type": "text", "text": "Describe the camera motion in this video."},
32 ],
33 }
34]
35
36text = processor.apply_chat_template(
37 messages, tokenize=False, add_generation_prompt=True
38)
39image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)
40inputs = processor(
41 text=[text],
42 images=image_inputs,
43 videos=video_inputs,
44 fps=fps,
45 padding=True,
46 return_tensors="pt",
47 **video_kwargs,
48)
49inputs = inputs.to("cuda")
50
51# Inference
52generated_ids = model.generate(**inputs, max_new_tokens=128)
53generated_ids_trimmed = [
54 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
55]
56output_text = processor.batch_decode(
57 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
58)
59print(output_text)@article{lin2025camerabench,
title={Towards Understanding Camera Motions in Any Video},
author={Lin, Zhiqiu and Cen, Siyuan and Jiang, Daniel and Karhade, Jay and Wang, Hewei and Mitra, Chancharik and Ling, Tiffany and Huang, Yuhan and Liu, Sifan and Chen, Mingyu and Zawar, Rushikesh and Bai, Xue and Du, Yilun and Gan, Chuang and Ramanan, Deva},
journal={arXiv preprint arXiv:2504.15376},
year={2025},
}