Views
No views yet
image_path and prompt to your own settings.1import torch
2from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
3from qwen_vl_utils import process_vision_info
4
5# default: Load the model on the available device(s)
6model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
7 "comin/OmniVerifier-7B", torch_dtype=torch.bfloat16, device_map="auto"
8)
9# default processer
10processor = AutoProcessor.from_pretrained("comin/OmniVerifier-7B")
11
12image_path = '' # please replace it with your own image path
13prompt = '' # please replace it with the prompt you use to generate the image
14
15question = f"""This image was generated from the prompt: {prompt}.
16 Please carefully analyze the image and determine whether all the objects, attributes, and spatial relationships mentioned in the prompt are correctly represented in the image.
17
18 If the image accurately reflects the prompt, please answer 'true'; otherwise, answer 'false'.
19
20 Respond strictly in the following JSON format: """ + """
21
22 {
23 "answer": true/false,
24 "explanation": "If the answer is false, briefly summarize the main error.",
25 }
26 """
27
28messages = [
29 {
30 "role": "user",
31 "content": [
32 {
33 "type": "image",
34 "image": image_path,
35 },
36 {"type": "text", "text": question},
37 ],
38 }
39]
40
41# Preparation for inference
42text = processor.apply_chat_template(
43 messages, tokenize=False, add_generation_prompt=True
44)
45image_inputs, video_inputs = process_vision_info(messages)
46inputs = processor(
47 text=[text],
48 images=image_inputs,
49 videos=video_inputs,
50 padding=True,
51 return_tensors="pt",
52)
53inputs = inputs.to("cuda")
54
55# Inference: Generation of the output
56generated_ids = model.generate(**inputs, max_new_tokens=128)
57generated_ids_trimmed = [
58 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
59]
60output_text = processor.batch_decode(
61 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
62)
63print(output_text)@article{zhang2025generative,
author = {Zhang, Xinchen and Zhang, Xiaoying and Wu, Youbin and Cao, Yanbin and Zhang, Renrui and Chu, Ruihang and Yang, Ling and Yang, Yujiu},
title = {Generative Universal Verifier as Multimodal Meta-Reasoner},
journal = {arXiv preprint arXiv:2510.13804},
year = {2025}
}