RT-DETRv2: Improved Baseline with Bag-of-Freebies for Real-Time Detection Transformer
Paper โข 2407.17140 โข Published โข 2
How to use cavi-ai/bobby-control-detector with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("object-detection", model="cavi-ai/bobby-control-detector") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForObjectDetection
tokenizer = AutoTokenizer.from_pretrained("cavi-ai/bobby-control-detector")
model = AutoModelForObjectDetection.from_pretrained("cavi-ai/bobby-control-detector", device_map="auto")Finds the interactable controls in a web page screenshot: buttons, links, text fields, search boxes, selects, checkboxes, radio buttons, switches and tabs, all as one interactable class. It is a fine-tune of PekingU/rtdetr_v2_r18vd (RT-DETRv2 with a ResNet-18 backbone) on synthetic pages labeled from the DOM, made for the bobby-browser automation runtime.
5650961749fa93567c0d46fc7f43ea4f9e914107.| Path | Format | For | Size |
|---|---|---|---|
model.safetensors, config.json, preprocessor_config.json |
transformers RTDetrV2ForObjectDetection, float32 |
Python inference and further fine-tuning | 80.5 MB |
onnx/model.onnx |
ONNX, opset 17, float32 | ONNX Runtime, tract and other ONNX engines | 80.7 MB |
interactable, id 0. The model finds controls; it does not name them or tell their role. Pair its boxes with OCR or the page's DOM for that.preprocessor_config.json does this for transformers.pixel_values: [1, 3, 544, 1024]. Outputs logits: [1, 300, 1] and pred_boxes: [1, 300, 4] as center x, center y, width, height, normalized to the image. A box's score is the sigmoid of its logit. No NMS is needed.pip install transformers torch pillowpip install onnxruntime numpy pillow huggingface_hubfrom transformers import pipeline
detector = pipeline("object-detection", model="cavi-ai/bobby-control-detector", threshold=0.6)
for hit in detector("screenshot.png"):
print(round(hit["score"], 3), hit["box"])
box holds xmin, ymin, xmax, ymax in screenshot pixels, rounded to whole pixels.import numpy as np
import onnxruntime
from huggingface_hub import hf_hub_download
from PIL import Image
session = onnxruntime.InferenceSession(hf_hub_download("cavi-ai/bobby-control-detector", "onnx/model.onnx"))
image = Image.open("screenshot.png").convert("RGB")
width, height = image.size
pixels = np.asarray(image.resize((1024, 544), Image.BILINEAR), dtype=np.float32) / 255.0
logits, boxes = session.run(["logits", "pred_boxes"], {"pixel_values": pixels.transpose(2, 0, 1)[None]})
scores = 1 / (1 + np.exp(-logits[0, :, 0]))
for score, (cx, cy, w, h) in zip(scores, boxes[0]):
if score >= 0.6:
print(round(float(score), 3), [round(float(v), 1) for v in ((cx - w / 2) * width, (cy - h / 2) * height, w * width, h * height)])
x, y, width, height in screenshot pixels.generate_pages.py: navigation bars, forms, cards, tables, toolbars, tabs, result lists, filters, banners, prose and pagers, with random light and dark themes, fonts, sizes, corner radii and spacing.train_detector.py reproduces the training and eval_detector.py the evaluation and the ONNX export.Hardware: Apple M5 Max.
| Pages | Count | Precision | Recall | F1 |
|---|---|---|---|---|
| Held-out synthetic pages | 300 | 0.986 | 0.975 | 0.980 |
| Hand-built test pages from bobby-browser | 13 | 0.674 | 0.864 (95/110) | 0.757 |
| Runtime | Device | Time per screenshot |
|---|---|---|
| PyTorch (MPS) | GPU | 16 ms |
| ONNX Runtime | CPU | 74 ms |
| tract 0.23 (Rust) | CPU | 1.2 s |
LICENSE.The base model:
@misc{lv2024rtdetrv2,
title = {RT-DETRv2: Improved Baseline with Bag-of-Freebies for Real-Time Detection Transformer},
author = {Wenyu Lv and Yian Zhao and Qinyao Chang and Kui Huang and Guanzhong Wang and Yi Liu},
year = {2024},
eprint = {2407.17140},
archivePrefix = {arXiv},
primaryClass = {cs.CV}
}
Base model
PekingU/rtdetr_v2_r18vd