Views
No views yet
1from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
2from qwen_vl_utils import process_vision_info
3
4
5model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
6 "WangBiao/R1-Track-GRPO-wo-Think", torch_dtype="auto", device_map="auto"
7)
8
9
10min_pixels = 336*336
11max_pixels = 336*336
12processor = AutoProcessor.from_pretrained("WangBiao/R1-Track-GRPO-wo-Think", min_pixels=min_pixels, max_pixels=max_pixels)
13
14
15messages = [
16 {
17 "role": "system",
18 "content": "You are a helpful assistant.",
19 },
20 {
21 "role": "user",
22 "content": [
23 {
24 "type": "image",
25 "image": "image_1.jpg",
26 },
27 {
28 "type": "image",
29 "image": "image_2.jpg",
30 },
31 {"type": "text", "text": "Please identify the target specified by the bounding box [241,66,329,154] in the first image and locate it in the second image. Return the coordinates in [x_min,y_min,x_max,y_max] format."},
32 ],
33 }
34]
35
36
37
38text = processor.apply_chat_template(
39 messages, tokenize=False, add_generation_prompt=True
40)
41
42image_inputs, video_inputs = process_vision_info(messages)
43inputs = processor(
44 text=[text],
45 images=image_inputs,
46 videos=video_inputs,
47 padding=True,
48 return_tensors="pt",
49)
50inputs = inputs.to(model.device)
51
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)