Views
No views yet
1from transformers import AutoImageProcessor, RfDetrForObjectDetection
2import torch
3from PIL import Image
4import requests
5
6url = "http://images.cocodataset.org/val2017/000000039769.jpg"
7image = Image.open(requests.get(url, stream=True).raw)
8
9processor = AutoImageProcessor.from_pretrained("stevenbucaille/rf-detr-base")
10model = RfDetrForObjectDetection.from_pretrained("stevenbucaille/rf-detr-base")
11
12inputs = processor(images=image, return_tensors="pt")
13outputs = model(**inputs)
14
15# convert outputs (bounding boxes and class logits) to COCO API
16# let's only keep detections with score > 0.35
17target_sizes = torch.tensor([image.size[::-1]])
18results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.35)[0]
19
20for score, label, box in list(zip(results["scores"], results["labels"], results["boxes"]))[:8]:
21 box = [round(i, 2) for i in box.tolist()]
22 print(
23 f"Detected {model.config.id2label[label.item()]} with confidence "
24 f"{round(score.item(), 3)} at location {box}"
25 )Detected cat with confidence 0.983 at location [7.5, 54.58, 318.47, 472.12]
Detected remote with confidence 0.976 at location [40.73, 72.61, 175.93, 117.58]
Detected cat with confidence 0.978 at location [342.97, 23.92, 639.33, 371.78]
Detected remote with confidence 0.864 at location [333.54, 76.98, 370.36, 187.34]
Detected couch with confidence 0.62 at location [0.82, 1.55, 640.33, 474.64]
Detected couch with confidence 0.165 at location [1.43, 0.44, 639.87, 194.17]
Detected couch with confidence 0.166 at location [1.05, 0.83, 638.5, 474.54]
Detected couch with confidence 0.19 at location [2.07, 2.02, 493.97, 352.97]config.id2label.1@misc{robinson2026rfdetrneuralarchitecturesearch,
2 title={RF-DETR: Neural Architecture Search for Real-Time Detection Transformers},
3 author={Isaac Robinson and Peter Robicheaux and Matvei Popov and Deva Ramanan and Neehar Peri},
4 year={2026},
5 eprint={2511.09554},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://huggingface.co/papers/2511.09554},
9}