RF-DETR
Un detection transformer che predice un insieme fisso di oggetti invece di una griglia densa, quindi non richiede NMS durante l'inferenza. LibreYOLO lo supporta per quattro task.
- Task
- detection, instance segmentation, pose, oriented boxes
- Dimensioni
- n, s, m, l for detection and oriented boxes; n through xx for segmentation; x for pose
- Installa
pip install "libreyolo[rfdetr]"- Livello di supporto
- Di punta, dalla v1.0.0. Le funzionalità vengono progettate e convalidate completamente su GPU prima per questo livello.
- Licenze
- Codice MIT, pesi Apache-2.0. Uso commerciale
Installazione
RF-DETR richiede un extra dedicato, che porta con sé transformers per il
backbone.
pip install "libreyolo[rfdetr]"Senza di esso, caricare un checkpoint o un nome di modello RF-DETR, da Python o dalla CLI, si ferma con un errore che indica questa riga di installazione.
Predizione
I pesi vengono scaricati da Hugging Face al primo utilizzo e restano nella cache locale.
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreRFDETRs.pt")result = model(SAMPLE_IMAGE, save=True) for box in result.boxes: print(box.cls, box.conf, box.xyxy)libreyolo predict model=LibreRFDETRs.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=Truefrom libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt") # Qualsiasi sorgente accettata dalla libreria: file, cartella, URL,# indice della webcam, stream RTSP o una lista .streamsfor result in model.predict("clip.mp4", stream=True, save=True): print(len(result.boxes))L'oggetto Results restituito è quello che restituisce ogni famiglia, quindi
passare a un rilevatore diverso è una modifica di una riga. conf e max_det
filtrano la selezione delle query; non c'è nessun passaggio di NMS da regolare.
Vedi predizione per sorgenti, streaming e gestione dei
risultati.
I percorsi di rilevamento, segmentazione e box orientati usano il ridimensionamento bilineare OpenCV in virgola mobile senza antialiasing; la posa mantiene il ridimensionamento con antialiasing. Il valore rettangolare imgsz=(height, width) deve rispettare la griglia di patch/finestre del task. L'inventario dei checkpoint include il rilevatore di interfacce utente. Gli istogrammi di eventi usano il profilo di input registrato.
Varianti
Quattro dimensioni per il rilevamento, da n a l, e quattro task che
condividono una sola architettura: segmentazione, posa e box orientati
riutilizzano il decoder di rilevamento con una testa diversa, quindi accettano
gli stessi argomenti. La segmentazione aggiunge x e xx, e la posa esiste
solo in x. Le dimensioni hanno un
numero di parametri simile e differiscono soprattutto per la risoluzione di
input.
| Checkpoint | Ingresso (px) | mAP 50-95 | Parametri (M) |
|---|---|---|---|
| LibreRFDETRn | 384 | 51.4 | 30.47 |
| LibreRFDETRs | 512 | 55.2 | 32.11 |
| LibreRFDETRm | 576 | 57.4 | 33.69 |
| LibreRFDETRl | 704 | 58.6 | 33.93 |
COCO val2017, 500 images. Misurato con il sistema di benchmark di LibreYOLO e pubblicato su Vision Analysis, dove vengono confrontate le latenze tra hardware e runtime e sono disponibili i record completi delle esecuzioni.
Addestramento
L'addestramento parte da un checkpoint pubblicato, per tutti e quattro i task.
pretrained=False invece reinizializza l'intera rete, backbone incluso, e
addestra da zero.
from libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt")model.train(data="my-dataset.yaml", epochs=50, imgsz=512, batch=8, lr0=1e-4)libreyolo train model=LibreRFDETRs.pt data=my-dataset.yaml \ epochs=50 imgsz=512 batch=8 lr0=1e-4from libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt")model.train(data="my-dataset.yaml", epochs=50, lora=True)libreyolo train model=LibreRFDETRs.pt data=my-dataset.yaml \ epochs=50 device=0,1 batch=-1Due argomenti contano più qui che su un rilevatore CNN. Tieni lr0 a 1e-4 o
sotto, perché i detection transformer divergono a learning rate che un modello
YOLO tollera. Lascia imgsz alla risoluzione nativa del checkpoint, a meno che
tu non abbia un motivo per cambiarla. L'input deve essere divisibile
esattamente per la dimensione delle patch del backbone moltiplicata per il
numero di finestre; LibreYOLO lo verifica prima che l'esecuzione parta e indica
le dimensioni valide più vicine.
Il fine-tuning di segmentazione parte da un checkpoint di segmentazione, perché
RF-DETR non ha il trasferimento da detect a segment.
libreyolo train model=LibreRFDETRn-seg.pt task=segment carica quel checkpoint,
e un checkpoint di rilevamento con task=segment si ferma con un errore.
Vedi addestramento per dataset, data augmentation, multi-GPU e logger.
Le nuove esecuzioni usano di default output_dir=None, che risolve a una directory incrementale runs/train/rfdetr_exp con exist_ok=False. Un'esecuzione ripresa continua a scrivere nella directory di run del suo checkpoint. I dataset di posa multiclasse usano kpt_names con l'indice o il nome della classe come chiave; una lista vuota indica una classe con soli box. Le predizioni aggiungono padding ai keypoint fino a kpt_shape; la fitness basata sulla mAP dei keypoint non valuta le classi con soli box.
Validazione
val() restituisce un dizionario di chiavi metrics/ che coprono mAP 50,
mAP 50-95, mAP 75 e il recall medio COCO, misurati su qualsiasi dataset nel formato su cui hai
addestrato.
from libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt") # val() restituisce un semplice dict, non un oggettometrics = model.val(data="my-dataset.yaml", imgsz=512) print(metrics["metrics/mAP50-95"])print(metrics["metrics/mAP50"])print(metrics["metrics/mAP75"], metrics["metrics/AR100"])libreyolo val model=LibreRFDETRs.pt data=my-dataset.yaml imgsz=512# Lo yaml di COCO incluso porta uno script di download integrato,# quindi serve un permesso esplicito a meno che il dataset non sia# già in locale.libreyolo val model=LibreRFDETRn.pt data=coco.yaml imgsz=384 \ allow_download_scripts=TrueEsportazione
| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Detection | Detection to ONNX: supportato | Detection to TorchScript: supportato | Detection to ExecuTorch: supportato | Detection to TensorRT: supportato. Runtime parity coverage lives in tests/e2e/test_tensorrt.py. | Detection to OpenVINO: supportato. Runtime parity coverage lives in tests/e2e/test_openvino.py. | Detection to Paddle: non supportato | Detection to MNN: supportato | Detection to RKNN: non supportato | Detection to ncnn: non supportato | Detection to TFLite: non supportato | Detection to CoreML: supportato. Conversion is available, but runtime parity requires a macOS runner. | Detection to Core AI: supportato |
| Instance segmentation | Instance segmentation to ONNX: supportato | Instance segmentation to TorchScript: supportato | Instance segmentation to ExecuTorch: supportato | Instance segmentation to TensorRT: supportato. A published Apache-2.0 trained segmentation checkpoint exports and reloads, but public top-k class membership changes. | Instance segmentation to OpenVINO: supportato. After Hungarian query alignment, the converted-runtime element match rate is 69.0%, below the validation bar. | Instance segmentation to Paddle: non supportato | Instance segmentation to MNN: non supportato | Instance segmentation to RKNN: non supportato | Instance segmentation to ncnn: non supportato | Instance segmentation to TFLite: non supportato | Instance segmentation to CoreML: non supportato | Instance segmentation to Core AI: non supportato |
| Pose | Pose to ONNX: supportato | Pose to TorchScript: supportato | Pose to ExecuTorch: supportato | Pose to TensorRT: supportato. A published Apache-2.0 trained pose checkpoint exports and reloads, but matched public boxes fall to 0.704 IoU with 41.4-pixel coordinate drift. | Pose to OpenVINO: supportato. After Hungarian query alignment, the converted-runtime element match rate is 72.75%, below the validation bar. | Pose to Paddle: non supportato | Pose to MNN: non supportato | Pose to RKNN: non supportato | Pose to ncnn: non supportato | Pose to TFLite: non supportato | Pose to CoreML: non supportato | Pose to Core AI: non supportato |
| Oriented boxes | Oriented boxes to ONNX: supportato | Oriented boxes to TorchScript: supportato | Oriented boxes to ExecuTorch: supportato | Oriented boxes to TensorRT: supportato. A deterministic synthetic OBB fixture exports and reloads, but public top-k class membership changes. | Oriented boxes to OpenVINO: supportato. After Hungarian query alignment, the converted-runtime element match rate is 91.25%, below the validation bar. | Oriented boxes to Paddle: non supportato | Oriented boxes to MNN: non supportato | Oriented boxes to RKNN: non supportato | Oriented boxes to ncnn: non supportato | Oriented boxes to TFLite: non supportato | Oriented boxes to CoreML: non supportato | Oriented boxes to Core AI: non supportato |
Un artefatto esportato si ricarica con LibreYOLO() in base al suffisso del
file, quindi un file .onnx o .engine si comporta come un checkpoint e
restituisce lo stesso Results. È supportato anche eseguire il grafo in un
runtime nudo, senza LibreYOLO installato, ma allora preprocessing e
postprocessing tocca scriverli a te.
from libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt")model.export(format="onnx", imgsz=512)model.export(format="tensorrt", imgsz=512, half=True) # Argomenti accettati per ogni formato:## format "onnx" | "torchscript" | "executorch" | "tensorrt"# | "openvino" | "paddle" | "mnn" | "rknn" | "ncnn"# | "tflite" | "coreml" | "coreai".# "engine" è un alias per tensorrt, "litert" per tflite.# imgsz int, oppure (altezza, larghezza). Di default la# risoluzione nativa del checkpoint.# batch int, default 1.# half bool, esporta in FP16. Default False.# int8 bool, esporta in INT8. Default False. Richiede `data`.# data percorso di uno YAML di dataset, usato per calibrare int8.# fraction float, quota di quel set di calibrazione da usare.# Default 1.0.# dynamic bool, assi dinamici. Default True.# simplify bool, esegue la semplificazione del grafo ONNX.# Default True.# opset int, opset ONNX. Scelto per famiglia se non indicato.# device str, dispositivo su cui tracciare. Di default quello# del modello.# output_path str, di default un nome derivato dal checkpoint.# verbose bool, default False.# allow_download_scripts bool, default False. Consente il Python# integrato in uno YAML di dataset che va scaricato.## Qualche formato accetta argomenti extra propri, come una piattaforma# target RKNN. Sono documentati nella pagina di ciascun formato.libreyolo export model=LibreRFDETRs.pt format=onnx imgsz=512libreyolo export model=LibreRFDETRs.pt format=tensorrt imgsz=512 half=Truefrom libreyolo import LibreYOLO, SAMPLE_IMAGE # La factory smista in base al suffisso del file, quindi un artefatto# esportato si carica come qualsiasi checkpoint e restituisce lo stesso# oggetto Results.model = LibreYOLO("LibreRFDETRs.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)import numpy as npimport onnxruntime as ort # Eseguire il grafo direttamente significa scrivere da sé il# preprocessing e il postprocessing. Ispeziona la firma prima di# collegare qualsiasi cosa.session = ort.InferenceSession("weights/LibreRFDETRs.onnx")name = session.get_inputs()[0].nameoutputs = session.run(None, {name: np.zeros((1, 3, 512, 512), dtype=np.float32)}) for meta, array in zip(session.get_outputs(), outputs): print(meta.name, array.shape)Input e output ONNX
| Tensore | input float32 [batch, 3, height, width] |
|---|---|
| Colore | RGB |
| Scala | pixel / 255 |
| Normalizzazione | media [0.485,0.456,0.406], deviazione standard [0.229,0.224,0.225] |
| Ridimensionamento | custom, bilinear |
The input tensor is named input, not images.
Square input only. Export rejects a non-square imgsz. The default size comes from the checkpoint and is stored in the imgsz metadata key: 384 for LibreRFDETRn, 312 for LibreRFDETRn-seg, 576 for LibreRFDETRx-pose.
A custom imgsz must be a multiple of patch size x windows: 32 for detection and OBB, 12 for segmentation n, 24 for the other segmentation sizes and for pose.
Stretch the whole image to width x height. There is no letterbox and no padding, so the aspect ratio is not kept.
Detection, segmentation and OBB: convert the 8-bit RGB image to float32 and divide by 255 first, then resize the float image with cv2.resize INTER_LINEAR (half-pixel centers, no antialiasing). Resizing the 8-bit image before dividing is close but moves scores by up to about 0.01.
Pose resizes differently: divide by 255 the same way, then resize the float image with antialiased bilinear, as torch.nn.functional.interpolate does with mode bilinear, align_corners False and antialias True. This is the filter of Pillow's BILINEAR, which widens by the shrink factor, but in float with no rounding to 8 bits. Per axis, let s = in_size / out_size and f = max(s, 1). Output pixel i has center c = (i + 0.5) * s. It reads source pixels j from int(c - f + 0.5) to int(c + f + 0.5) - 1, clipped to the image, each with weight max(0, 1 - |j + 0.5 - c| / f). Divide the weights by their sum.
The pose model is sensitive to this. On the test image, cv2.resize INTER_LINEAR or INTER_AREA adds 3 to 9 detections, and Pillow on the 8-bit image adds one and moves keypoints by more than 4 px.
Then subtract the mean and divide by the std per channel.
nms=True is not available for this family: export raises NotImplementedError.
Detection, esportazione predefinita
| Output | Forma | Significato |
|---|---|---|
dets | [batch, queries, 4] | Boxes as cx, cy, w, h, normalized 0 to 1 of the input. 300 queries. |
labels | [batch, queries, columns] | Raw class logits per query, sigmoid not applied. The COCO checkpoints have 91 columns, where column k is COCO category id k. For other checkpoints column j is class j. |
Post-elaborazione
- Apply sigmoid to labels.
- Flatten the scores of one image to queries x columns and take the top k over all of them, with k equal to queries (300). For flat index i, the query is i // columns and the column is i % columns. One query can yield several classes.
- Keep the entries whose score is strictly above the confidence threshold (0.25 by default). There is no NMS.
- When labels has 91 columns and nc is 80 (the COCO checkpoints), the column is a COCO category id. Class i is the i-th id, counting from 0, in this list: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90. Drop entries whose id is not in the list. With any other column count the column is the class.
- Convert the query's box to x1 = cx - w / 2, y1 = cy - h / 2, x2 = cx + w / 2, y2 = cy + h / 2.
- Map boxes back to the original image: multiply x by the original width and y by the original height. The input was stretched, so no pad offset applies. LibreYOLO does not clip these boxes.
Instance segmentation, esportazione predefinita
| Output | Forma | Significato |
|---|---|---|
dets | [batch, queries, 4] | Boxes as cx, cy, w, h, normalized 0 to 1 of the input. 100 queries for sizes n and s, 200 for m and l, 300 for x and xx. |
labels | [batch, queries, columns] | Raw class logits per query, sigmoid not applied. 91 columns for the COCO checkpoints, where column k is COCO category id k. |
masks | [batch, queries, mask_h, mask_w] | Raw mask logits per query over the whole input, at a quarter of the input size: 78 x 78 at 312 x 312. |
Post-elaborazione
- Select, threshold, map classes and decode boxes exactly as for detection, with k equal to queries.
- Take the mask of each kept query and resize the logits straight to the original image size with bilinear, half-pixel centers and no antialiasing (cv2.resize INTER_LINEAR on the float logits gives the same).
- A pixel is foreground when its resized logit is above 0.
Pose, esportazione predefinita
| Output | Forma | Significato |
|---|---|---|
dets | [batch, queries, 4] | Boxes as cx, cy, w, h, normalized 0 to 1 of the input. 100 queries. |
labels | [batch, queries, columns] | Raw class logits per query, sigmoid not applied, with the keypoint class term already added inside the graph. Column 0 is an empty slot and column j + 1 is class j, so the person checkpoint has 2 columns. |
keypoints | [batch, queries, columns * num_keypoints, 8] | One block of num_keypoints rows per label column, 2 x 17 = 34 rows here. Each row is x, y normalized 0 to 1 of the input, findable logit, visible logit, log_l11, l21, log_l22 and a class logit term. The num_keypoints_per_class metadata key ([0, 17]) says how many rows of each block are real keypoints. |
Post-elaborazione
- Apply sigmoid to labels. Flatten to queries x columns and take the top k over all of them, with k equal to queries (100). For flat index i, the query is i // columns and the column is i % columns.
- For each entry take its column's keypoint block: rows column * num_keypoints onward, of which the first num_keypoints_per_class[column] are used.
- Rescore each entry whose column has keypoints. Per used keypoint, with a = log_l11, b = l21, d = log_l22 and p = sigmoid(findable logit): sigma = exp(-2a) + exp(-2d) + b^2 * exp(-2a - 2d). Then trace = log(sum of p * sigma / sum of p) over the used keypoints, and score = score * exp(-0.2 * trace). Scores can go above 1.
- Drop entries whose column is 0. The class is column - 1.
- Keep the entries whose new score is strictly above the confidence threshold (0.25 by default). There is no NMS.
- Decode and map the box as for detection. LibreYOLO does not clip these boxes.
- Keypoint x is x * original width and keypoint y is y * original height. Keypoint confidence is sigmoid(findable logit). LibreYOLO does not use the visible logit.
Oriented boxes, esportazione predefinita
| Output | Forma | Significato |
|---|---|---|
dets | [batch, queries, 4] | Rotated boxes as cx, cy, w, h, normalized 0 to 1 of the input. 300 queries. |
labels | [batch, queries, columns] | Raw class logits per query, sigmoid not applied. Column j is class j. The 6-class checkpoint has 7 columns: the last one is not a class and LibreYOLO does not drop it. |
angles | [batch, queries, 1] | Rotation in radians from -pi / 2 to pi / 2, tanh already applied, measured on the square input. The width side points along (cos(angle), sin(angle)) with y pointing down. |
Post-elaborazione
- Select and threshold as for detection, with k equal to queries (300). The column is the class.
- The stretch scales x and y by different amounts, so map each box back through its corners. In normalized input units, with c = cos(angle) and s = sin(angle), the corners are (cx, cy) - u - v, + u - v, + u + v and - u + v, with u = (c * w / 2, s * w / 2) and v = (-s * h / 2, c * h / 2).
- Multiply corner x by the original width and corner y by the original height.
- Fit cv2.minAreaRect to the 4 corners and convert its angle to radians. Raise w and h to at least 1e-4. If h > w, swap them and add pi / 2 to the angle. Then wrap the angle to [-pi / 2, pi / 2) with angle = (angle + pi / 2) mod pi - pi / 2.
- The result is cx, cy, w, h, angle in original-image pixels, with w the long side.
Per verificare la tua implementazione, passa lo stesso file a LibreYOLO: LibreYOLO("model.onnx").predict("image.jpg") restituisce i risultati di riferimento. Verificato con LibreYOLO 1.7.0.
Checkpoint
Tutti i file di pesi pubblicati per questa famiglia.
| File | Ingresso (px) | Licenza dei pesi |
|---|---|---|
| Detection | ||
| LibreRFDETRl.pt | 704 | apache-2.0 |
| LibreRFDETRm.pt | 576 | apache-2.0 |
| LibreRFDETRn.pt | 384 | apache-2.0 |
| LibreRFDETRs.pt | 512 | apache-2.0 |
| LibreRFDETRm-ui.pt | mit | |
| Instance segmentation | ||
| LibreRFDETRn-seg.pt | 312 | apache-2.0 |
| LibreRFDETRs-seg.pt | 384 | apache-2.0 |
| LibreRFDETRm-seg.pt | 432 | apache-2.0 |
| LibreRFDETRl-seg.pt | 504 | apache-2.0 |
| LibreRFDETRx-seg.pt | 624 | apache-2.0 |
| LibreRFDETRxx-seg.pt | 768 | apache-2.0 |
| Pose | ||
| LibreRFDETRx-pose.pt | 576 | apache-2.0 |
| Oriented boxes | ||
| LibreRFDETRn-obb.pt | 384 | cc-by-4.0 |
| LibreRFDETRs-obb.pt | 512 | cc-by-4.0 |
| LibreRFDETRm-obb.pt | 576 | cc-by-4.0 |
| LibreRFDETRl-obb.pt | 704 | cc-by-4.0 |
Oggi tutti i file elencati sopra sono presenti nell<link>organizzazione LibreYOLO</link> e vengono scaricati al primo utilizzo.
Licenze
Controlla la licenza nel repository Hugging Face degli specifici pesi che scarichi. Ogni checkpoint nell<link>organizzazione LibreYOLO</link> ne include una e non è sempre la stessa per tutta la famiglia. Quel repository è la fonte autorevole; il riepilogo seguente descrive le condizioni applicabili al momento dellultima verifica di questa pagina.
Questa è una descrizione delle licenze coinvolte, non una consulenza legale. Se la risposta è importante a fini commerciali, leggi personalmente le licenze e chiedi una consulenza indipendente.
- Lavoro originale
- RF-DETR, Roboflow
- Licenza upstream
- Apache-2.0
- Sorgente upstream
- github.com/roboflow/rf-detr
- Codice LibreYOLO
- MIT
- Pesi
- Apache-2.0, ripubblicati su huggingface.co/LibreYOLO
- Interpretazione
- Apache-2.0 is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep its license text and attribution notices with any copy of the weights you redistribute, and it grants a patent license. It places no obligation on your own application code, and weights you train yourself on your own data are yours.
Citazione
@inproceedings{robinson2026rfdetr,
title = {RF-DETR: Real-Time Detection Transformer},
author = {Robinson, Isaac and Robicheaux, Peter and Popov, Matvei and Ramanan, Deva and Peri, Neehar},
booktitle = {International Conference on Learning Representations (ICLR)},
year = {2026},
url = {https://arxiv.org/abs/2511.09554}
}Copiato dal blocco di citazione degli autori disponibile su github.com/roboflow/rf-detr#citation.