RF-DETR

密なグリッドではなく固定された物体集合を予測するため、推論時にNMSを必要としない検出Transformerです。LibreYOLOは4つのタスクでRF-DETRをサポートします。

タスク
detection, instance segmentation, pose, oriented boxes
サイズ
n, s, m, l for detection and oriented boxes; n through xx for segmentation; x for pose
インストール
pip install "libreyolo[rfdetr]"
サポートティア
フラッグシップ、v1.0.0以降。機能はまずここで設計され、GPUで完全に検証されます。
アップストリーム
RoboflowのRF-DETR、Apache-2.0。論文、ソース
ライセンス
コード:MIT、重み:Apache-2.0。商用利用
LibreRFDETRs、512 pxでの動画検出。

インストール

RF-DETRには専用の追加パッケージが必要で、バックボーン用のtransformersがインストールされます。

bash
pip install "libreyolo[rfdetr]"

これがないと、PythonからでもCLIからでも、RF-DETRのチェックポイントやモデル名を読み込む時点で、このインストール行を示すエラーで停止します。

推論

重みは初回使用時にHugging Faceからダウンロードされ、ローカルにキャッシュされます。

Python
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)
CLI
libreyolo predict model=LibreRFDETRs.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
動画
from libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt") # ライブラリが受け付ける任意のソース: ファイル フォルダー URL Webカメラ番号# RTSP ストリーム または .streams リストfor result in model.predict("clip.mp4", stream=True, save=True):    print(len(result.boxes))

返されるResultsオブジェクトはすべてのファミリーに共通するため、別の検出器への切り替えは1行の変更で済みます。confとmax_detはクエリ選択をフィルタリングします。調整するNMSステップはありません。ソース、ストリーミング、結果の処理については推論を参照してください。

物体検出、セグメンテーション、回転ボックスの処理では、アンチエイリアスなしの浮動小数点OpenCVバイリニアリサイズを使います。姿勢推定ではアンチエイリアス付きリサイズを維持します。長方形のimgsz=(height, width)は、タスクのパッチとウィンドウのグリッドを満たす必要があります。チェックポイント一覧にはUI検出器も含まれます。イベントヒストグラムでは、記録された入力プロファイルを使います。

バリアント

nからlまでの4つの検出サイズと、1つのアーキテクチャを共有する4つのタスクがあります。セグメンテーション、姿勢推定、回転バウンディングボックスは異なるヘッドで検出デコーダーを再利用するため、同じ引数を受け取ります。セグメンテーションにはxとxxが加わり、姿勢推定はxのみです。各サイズのパラメータ数は近く、主に入力解像度が異なります。

チェックポイント入力(px)mAP 50-95パラメータ(M)
LibreRFDETRn38451.430.47
LibreRFDETRs51255.232.11
LibreRFDETRm57657.433.69
LibreRFDETRl70458.633.93

COCO val2017, 500 images。LibreYOLOベンチマークハーネスで測定し、Vision Analysisで公開しています。そこではハードウェアおよびランタイム別のレイテンシを比較でき、完全な実行記録も確認できます。

学習

4つすべてのタスクで、学習は公開済みチェックポイントから開始します。pretrained=Falseを指定すると、代わりにバックボーンを含むネットワーク全体を再初期化し、ゼロから学習します。

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt")model.train(data="my-dataset.yaml", epochs=50, imgsz=512, batch=8, lr0=1e-4)
CLI
libreyolo train model=LibreRFDETRs.pt data=my-dataset.yaml \  epochs=50 imgsz=512 batch=8 lr0=1e-4
LoRA
from libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt")model.train(data="my-dataset.yaml", epochs=50, lora=True)
マルチGPU
libreyolo train model=LibreRFDETRs.pt data=my-dataset.yaml \  epochs=50 device=0,1 batch=-1

ここでは、CNN検出器の場合より2つの引数が重要です。Transformer検出器はYOLOモデルが許容する学習率では発散するため、lr0を1e-4以下に保ってください。変更する理由がない限り、imgszはチェックポイントのネイティブ解像度のままにしてください。入力はバックボーンのパッチサイズとウィンドウ数の積で割り切れる必要があります。LibreYOLOは実行開始前にこれを確認し、最も近い有効なサイズを示します。

セグメンテーションのファインチューニングはセグメンテーションチェックポイントから始めます。RF-DETRには検出からセグメンテーションへの転移がないためです。libreyolo train model=LibreRFDETRn-seg.pt task=segmentはそのチェックポイントを読み込み、task=segmentを指定した検出チェックポイントはエラーで停止します。

データセット、データ拡張、マルチGPU、ロガーについては学習を参照してください。

新規実行のデフォルトはoutput_dir=Noneで、exist_ok=Falseにより連番付きのruns/train/rfdetr_expに解決されます。再開した実行は、そのチェックポイントの実行ディレクトリに引き続き書き込みます。複数クラスの姿勢推定データセットでは、クラスのインデックスまたは名前をキーとするkpt_namesを使います。空のリストはボックスのみのクラスを表します。推論ではキーポイントをkpt_shapeに合わせてパディングします。キーポイントmAPによる適合度の計算では、ボックスのみのクラスは評価しません。

検証

val()は、学習に使用した形式の任意のデータセットで測定したmAP 50、mAP 50-95、mAP 75、COCO平均再現率を含むmetrics/キーの辞書を返します。

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt") # val() はオブジェクトではなく通常の辞書を返すmetrics = model.val(data="my-dataset.yaml", imgsz=512) print(metrics["metrics/mAP50-95"])print(metrics["metrics/mAP50"])print(metrics["metrics/mAP75"], metrics["metrics/AR100"])
CLI
libreyolo val model=LibreRFDETRs.pt data=my-dataset.yaml imgsz=512
COCOで検証
# 同梱の COCO yaml はダウンロードスクリプトを内包するため# データセットがローカルにない場合は明示的な許可が必要libreyolo val model=LibreRFDETRn.pt data=coco.yaml imgsz=384 \  allow_download_scripts=True

エクスポート

タスクONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
DetectionDetection to ONNX:対応Detection to TorchScript:対応Detection to ExecuTorch:対応Detection to TensorRT:対応。Runtime parity coverage lives in tests/e2e/test_tensorrt.py.Detection to OpenVINO:対応。Runtime parity coverage lives in tests/e2e/test_openvino.py.Detection to Paddle:非対応Detection to MNN:対応Detection to RKNN:非対応Detection to ncnn:非対応Detection to TFLite:非対応Detection to CoreML:対応。Conversion is available, but runtime parity requires a macOS runner.Detection to Core AI:対応
Instance segmentationInstance segmentation to ONNX:対応Instance segmentation to TorchScript:対応Instance segmentation to ExecuTorch:対応Instance segmentation to TensorRT:対応。A published Apache-2.0 trained segmentation checkpoint exports and reloads, but public top-k class membership changes.Instance segmentation to OpenVINO:対応。After Hungarian query alignment, the converted-runtime element match rate is 69.0%, below the validation bar.Instance segmentation to Paddle:非対応Instance segmentation to MNN:非対応Instance segmentation to RKNN:非対応Instance segmentation to ncnn:非対応Instance segmentation to TFLite:非対応Instance segmentation to CoreML:非対応Instance segmentation to Core AI:非対応
PosePose to ONNX:対応Pose to TorchScript:対応Pose to ExecuTorch:対応Pose to TensorRT:対応。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:対応。After Hungarian query alignment, the converted-runtime element match rate is 72.75%, below the validation bar.Pose to Paddle:非対応Pose to MNN:非対応Pose to RKNN:非対応Pose to ncnn:非対応Pose to TFLite:非対応Pose to CoreML:非対応Pose to Core AI:非対応
Oriented boxesOriented boxes to ONNX:対応Oriented boxes to TorchScript:対応Oriented boxes to ExecuTorch:対応Oriented boxes to TensorRT:対応。A deterministic synthetic OBB fixture exports and reloads, but public top-k class membership changes.Oriented boxes to OpenVINO:対応。After Hungarian query alignment, the converted-runtime element match rate is 91.25%, below the validation bar.Oriented boxes to Paddle:非対応Oriented boxes to MNN:非対応Oriented boxes to RKNN:非対応Oriented boxes to ncnn:非対応Oriented boxes to TFLite:非対応Oriented boxes to CoreML:非対応Oriented boxes to Core AI:非対応

エクスポートした成果物は、ファイルサフィックスに基づいてLibreYOLO()から再度読み込めます。そのため、.onnxまたは.engineファイルはチェックポイントと同様に動作し、同じResultsを返します。LibreYOLOをインストールせず、単独のランタイムでグラフを実行することもサポートされますが、その場合は前処理と後処理を自分で実装する必要があります。

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreRFDETRs.pt")model.export(format="onnx", imgsz=512)model.export(format="tensorrt", imgsz=512, half=True) # すべての形式で受け付ける引数:##   format    "onnx" | "torchscript" | "executorch" | "tensorrt"#             | "openvino" | "paddle" | "mnn" | "rknn" | "ncnn"#             | "tflite" | "coreml" | "coreai".#             "engine" は tensorrt の別名で "litert" は tflite の別名#   imgsz     int または (height, width) デフォルトはチェックポイントの#             ネイティブ解像度#   batch     int デフォルト 1#   half      bool FP16 でエクスポート デフォルト False#   int8      bool INT8 でエクスポート デフォルト False `data` が必要#   data      int8 の較正に使うデータセット YAML のパス#   fraction  float 使用する較正セットの割合 デフォルト 1.0#   dynamic   bool 動的軸 デフォルト True#   simplify  bool ONNX グラフ簡略化を実行 デフォルト True#   opset     int ONNX opset 未指定時はファミリーごとに選択#   device    str トレースに使うデバイス デフォルトはモデルのデバイス#   output_path  str デフォルトはチェックポイント由来の名前#   verbose   bool デフォルト False#   allow_download_scripts  bool デフォルト False ダウンロードが必要な#             データセット YAML 内の Python 実行を許可## 一部の形式には RKNN ターゲットプラットフォームなど固有の追加引数がある# それらは各形式のページに記載
CLI
libreyolo export model=LibreRFDETRs.pt format=onnx imgsz=512libreyolo export model=LibreRFDETRs.pt format=tensorrt imgsz=512 half=True
エクスポートしたファイルを使う
from libreyolo import LibreYOLO, SAMPLE_IMAGE # ファクトリーはファイルサフィックスで振り分けるためエクスポート成果物も# 任意のチェックポイントと同様に読み込まれ同じ Results オブジェクトを返すmodel = LibreYOLO("LibreRFDETRs.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)
LibreYOLOを使わない場合
import numpy as npimport onnxruntime as ort # グラフを直接実行する場合は前処理と後処理を自分で実装# 接続前にシグネチャを確認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)

ONNX の入力と出力

テンソルinput float32 [batch, 3, height, width]
色RGB
スケーリングピクセル値 / 255
正規化平均 [0.485,0.456,0.406], 標準偏差 [0.229,0.224,0.225]
リサイズ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、デフォルトのエクスポート
出力形状意味
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.

後処理

  1. Apply sigmoid to labels.
  2. 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.
  3. Keep the entries whose score is strictly above the confidence threshold (0.25 by default). There is no NMS.
  4. 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.
  5. Convert the query's box to x1 = cx - w / 2, y1 = cy - h / 2, x2 = cx + w / 2, y2 = cy + h / 2.
  6. 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、デフォルトのエクスポート
出力形状意味
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.

後処理

  1. Select, threshold, map classes and decode boxes exactly as for detection, with k equal to queries.
  2. 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).
  3. A pixel is foreground when its resized logit is above 0.
Pose、デフォルトのエクスポート
出力形状意味
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.

後処理

  1. 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.
  2. 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.
  3. 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.
  4. Drop entries whose column is 0. The class is column - 1.
  5. Keep the entries whose new score is strictly above the confidence threshold (0.25 by default). There is no NMS.
  6. Decode and map the box as for detection. LibreYOLO does not clip these boxes.
  7. 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、デフォルトのエクスポート
出力形状意味
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.

後処理

  1. Select and threshold as for detection, with k equal to queries (300). The column is the class.
  2. 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).
  3. Multiply corner x by the original width and corner y by the original height.
  4. 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.
  5. The result is cx, cy, w, h, angle in original-image pixels, with w the long side.

自分の実装を確認するには、同じファイルを LibreYOLO で実行します。LibreYOLO("model.onnx").predict("image.jpg") が基準となる結果を返します。 LibreYOLO 1.7.0 で検証済み。

チェックポイント

このファミリーで公開されているすべての重みファイルです。

ファイル入力(px)重みのライセンス
Detection
LibreRFDETRl.pt704apache-2.0
LibreRFDETRm.pt576apache-2.0
LibreRFDETRn.pt384apache-2.0
LibreRFDETRs.pt512apache-2.0
LibreRFDETRm-ui.ptmit
Instance segmentation
LibreRFDETRn-seg.pt312apache-2.0
LibreRFDETRs-seg.pt384apache-2.0
LibreRFDETRm-seg.pt432apache-2.0
LibreRFDETRl-seg.pt504apache-2.0
LibreRFDETRx-seg.pt624apache-2.0
LibreRFDETRxx-seg.pt768apache-2.0
Pose
LibreRFDETRx-pose.pt576apache-2.0
Oriented boxes
LibreRFDETRn-obb.pt384cc-by-4.0
LibreRFDETRs-obb.pt512cc-by-4.0
LibreRFDETRm-obb.pt576cc-by-4.0
LibreRFDETRl-obb.pt704cc-by-4.0

上記のすべてのファイルは現在LibreYOLO orgにあり、初回使用時にダウンロードされます。

ライセンス

ダウンロードする特定の重みについて、Hugging Faceリポジトリのライセンスを確認してください。LibreYOLO orgの各チェックポイントにはライセンスが付与されており、同じファミリー内でも常に同一とは限りません。そのリポジトリが正式な情報源です。以下の概要は、このページを最後に検証した時点で適用されていた内容を示します。

これは関連するライセンスの説明であり、法的助言ではありません。商用上重要な場合は、自分でライセンスを読み、専門家の助言を受けてください。

原著作物
RF-DETR, Roboflow
アップストリームのライセンス
Apache-2.0
アップストリームのソース
github.com/roboflow/rf-detr
LibreYOLOのコード
MIT
重み
Apache-2.0、huggingface.co/LibreYOLOで再公開
解釈
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.

引用

@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}
}

著者によるgithub.com/roboflow/rf-detr#citationの引用ブロックからコピーしています。

LibreYOLO v1.6.0で検証済みです。このページのサポート表、チェックポイント、ベンチマーク値は手作業で記述したものではなく、リリース済みライブラリと公開済みの重みから生成されています。