Update README.md
Browse files
README.md
CHANGED
|
@@ -33,3 +33,108 @@ Project page: https://github.com/lll6gg/UI-R1
|
|
| 33 |
| GUI-R1-3B | w/ thinking | 114 | 26.6 |
|
| 34 |
| UI-R1-3B (v2) | w/ thinking | 129 | 29.8 |
|
| 35 |
| **UI-R1-E-3B** | w/o thinking | **28** | **33.5** |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
| GUI-R1-3B | w/ thinking | 114 | 26.6 |
|
| 34 |
| UI-R1-3B (v2) | w/ thinking | 129 | 29.8 |
|
| 35 |
| **UI-R1-E-3B** | w/o thinking | **28** | **33.5** |
|
| 36 |
+
|
| 37 |
+
## Evaluation Method for GUI Grounding
|
| 38 |
+
|
| 39 |
+
1. Prompt for UI-R1-E-3B:
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 43 |
+
args.model_path,
|
| 44 |
+
torch_dtype=torch.bfloat16,
|
| 45 |
+
attn_implementation="flash_attention_2",
|
| 46 |
+
device_map="cpu",
|
| 47 |
+
)
|
| 48 |
+
model = model.to(torch.device(rank))
|
| 49 |
+
model = model.eval()
|
| 50 |
+
processor = AutoProcessor.from_pretrained(ori_processor_path)
|
| 51 |
+
question_template = (
|
| 52 |
+
f"In this UI screenshot, I want to perform the command '{task_prompt}'.\n"
|
| 53 |
+
"Please provide the action to perform (enumerate in ['click'])"
|
| 54 |
+
"and the coordinate where the cursor is moved to(integer) if click is performed.\n"
|
| 55 |
+
"Output the final answer in <answer> </answer> tags directly."
|
| 56 |
+
"The output answer format should be as follows:\n"
|
| 57 |
+
"<answer>[{'action': 'click', 'coordinate': [x, y]}]</answer>\n"
|
| 58 |
+
"Please strictly follow the format."
|
| 59 |
+
)
|
| 60 |
+
query = '<image>\n' + question_template
|
| 61 |
+
messages = [
|
| 62 |
+
{
|
| 63 |
+
"role": "user",
|
| 64 |
+
"content": [
|
| 65 |
+
{"type": "image", "image": image_path}
|
| 66 |
+
] + [{"type": "text", "text": query}],
|
| 67 |
+
}
|
| 68 |
+
]
|
| 69 |
+
text = processor.apply_chat_template(
|
| 70 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 71 |
+
)
|
| 72 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 73 |
+
inputs = processor(
|
| 74 |
+
text=[text],
|
| 75 |
+
images=image_inputs,
|
| 76 |
+
videos=video_inputs,
|
| 77 |
+
padding=True,
|
| 78 |
+
return_tensors="pt",
|
| 79 |
+
)
|
| 80 |
+
generated_ids = model.generate(**inputs, max_new_tokens=1024)
|
| 81 |
+
generated_ids_trimmed = [
|
| 82 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 83 |
+
]
|
| 84 |
+
response = processor.batch_decode(
|
| 85 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 86 |
+
)
|
| 87 |
+
response = response[0]
|
| 88 |
+
pred_coord, _ = extract_coord(response)
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
2. Rescale the predicted coordinate according to the image resize
|
| 94 |
+
|
| 95 |
+
```python
|
| 96 |
+
image = Image.open(image_path)
|
| 97 |
+
origin_width, origin_height = image.size
|
| 98 |
+
resized_height,resized_width = smart_resize(origin_height,origin_width,max_pixels=12845056)
|
| 99 |
+
scale_x = origin_width / resized_width
|
| 100 |
+
scale_y = origin_height / resized_height
|
| 101 |
+
pred_coord[0] = int(pred_coord[0] * scale_x)
|
| 102 |
+
pred_coord[1] = int(pred_coord[1] * scale_y)
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
Function smart_resize is from Qwen2VL:
|
| 106 |
+
|
| 107 |
+
```python
|
| 108 |
+
import math
|
| 109 |
+
def smart_resize(
|
| 110 |
+
height: int, width: int, factor: int = 28, min_pixels: int = 56 * 56, max_pixels: int = 14 * 14 * 4 * 1280
|
| 111 |
+
):
|
| 112 |
+
"""Rescales the image so that the following conditions are met:
|
| 113 |
+
|
| 114 |
+
1. Both dimensions (height and width) are divisible by 'factor'.
|
| 115 |
+
|
| 116 |
+
2. The total number of pixels is within the range ['min_pixels', 'max_pixels'].
|
| 117 |
+
|
| 118 |
+
3. The aspect ratio of the image is maintained as closely as possible.
|
| 119 |
+
|
| 120 |
+
"""
|
| 121 |
+
if height < factor or width < factor:
|
| 122 |
+
raise ValueError(f"height:{height} or width:{width} must be larger than factor:{factor}")
|
| 123 |
+
elif max(height, width) / min(height, width) > 200:
|
| 124 |
+
raise ValueError(
|
| 125 |
+
f"absolute aspect ratio must be smaller than 200, got {max(height, width) / min(height, width)}"
|
| 126 |
+
)
|
| 127 |
+
h_bar = round(height / factor) * factor
|
| 128 |
+
w_bar = round(width / factor) * factor
|
| 129 |
+
if h_bar * w_bar > max_pixels:
|
| 130 |
+
beta = math.sqrt((height * width) / max_pixels)
|
| 131 |
+
h_bar = math.floor(height / beta / factor) * factor
|
| 132 |
+
w_bar = math.floor(width / beta / factor) * factor
|
| 133 |
+
elif h_bar * w_bar < min_pixels:
|
| 134 |
+
beta = math.sqrt(min_pixels / (height * width))
|
| 135 |
+
h_bar = math.ceil(height * beta / factor) * factor
|
| 136 |
+
w_bar = math.ceil(width * beta / factor) * factor
|
| 137 |
+
return h_bar, w_bar
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
|