Views
No views yet
1import os
2os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"
3from transformers import AutoProcessor,Qwen2_5_VLForConditionalGeneration
4from qwen_vl_utils import process_vision_info
5import torch
6
7# We recommend enabling flash_attention_2 for better acceleration and memory saving.
8model_dir = "Qwen2.5-VL-7B-Instruct-sft"
9model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
10 model_dir,
11 torch_dtype=torch.bfloat16,
12 # attn_implementation="flash_attention_2",
13 device_map="auto",
14)
15model.eval()
16processor = AutoProcessor.from_pretrained(model_dir)
17
18def format(images, text):
19 content = []
20 for img in images:
21 content.append({"type": "image", "image": img})
22 content.append({"type": "text", "text": text})
23 messages = [
24 {
25 "role": "user",
26 "content": content,
27 }
28 ]
29 return messages
30
31
32imgs = ["https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"]
33text = "Describe this image."
34messages = format(imgs, text)
35text = processor.apply_chat_template(
36 messages, tokenize=False, add_generation_prompt=True,add_vision_id=True
37)
38image_inputs, video_inputs = process_vision_info(messages)
39inputs = processor(
40 text=[text],
41 images=image_inputs,
42 videos=video_inputs,
43 padding=True,
44 return_tensors="pt",
45)
46
47inputs = inputs.to(model.device)
48with torch.no_grad():
49 generated_ids = model.generate(**inputs, max_new_tokens=1024)
50generated_ids_trimmed = [
51 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
52]
53output_text = processor.batch_decode(
54 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
55)[0].strip()
561@misc{wang2025cigeval,
2 title={A Unified Agentic Framework for Evaluating Conditional Image Generation},
3 author={Jifang Wang and Xue Yang and Longyue Wang and Zhenran Xu and Yiyu Wang and Yaowei Wang and Weihua Luo and Kaifu Zhang and Baotian Hu and Min Zhang},
4 year={2025},
5 eprint={2504.07046},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2504.07046},
9}