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-nano")
10model = RfDetrForObjectDetection.from_pretrained("stevenbucaille/rf-detr-nano")
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.994 at location [14.23, 54.15, 316.36, 473.81]
Detected remote with confidence 0.989 at location [334.14, 76.85, 371.13, 188.12]
Detected cat with confidence 0.956 at location [347.04, 26.2, 639.14, 375.12]
Detected remote with confidence 0.986 at location [40.14, 73.54, 175.75, 117.99]
Detected couch with confidence 0.42 at location [1.1, 1.34, 641.29, 473.79]
Detected couch with confidence 0.446 at location [0.73, 1.16, 641.54, 475.87]
Detected remote with confidence 0.341 at location [335.15, 77.2, 371.18, 187.61]
Detected remote with confidence 0.2 at location [334.06, 138.49, 351.61, 184.69]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}