RF-DETR Nano for RK3588: detection and instance segmentation without NMS

Compiled models for the Rockchip RK3588 / RK3588S NPU, ready to load: no ONNX export, no conversion. They are .rnpu files, fp16 builds made by the NPU compiler of RCDL and run by RCDL's own NPU runtime, which drives the board's rknpu kernel driver directly. librknnrt and rknn-toolkit2 are not involved, and there is no .rknn build of these models. RCDL is a C++17 / Python library that drives the NPU, RGA and VPU on these boards as one zero-copy pipeline. Its NPU stack is described in docs/OPEN_NPU.md.

Upstream: Roboflow's RF-DETR, Nano and Seg Nano: DETR models on a DINOv2 backbone, trained on COCO. Exported with the rfdetr package (RFDETRNano().export(opset_version=17), and RFDETRSegNano() for the segmenter).

Redistributable, including commercially. RF-DETR Nano and RF-DETR-Seg Nano are Apache-2.0 on the code and on the weights, and so is their DINOv2 backbone. See Licence.

Files

file what it is input size
rfdetr_nano_384_fp16.rnpu detection, 80 COCO classes, 300 queries 384×384 RGB, stretched 186.3 MB
rfdetr_seg_nano_312_fp16.rnpu instance segmentation, 80 COCO classes, 100 queries with a 78×78 mask each 312×312 RGB, stretched 81.3 MB

Both take uint8 RGB, with ImageNet mean / std inside the build. The image is stretched onto the square input, as RF-DETR is trained, not letterboxed; RGA or the CPU writes it straight into the NPU's input tensor. Each query is a box (cx, cy, w, h in 0..1) and one logit per COCO category id. Every (query, class) pair whose sigmoid passes the threshold is a detection, and nothing is suppressed: there is no NMS.

Measured on RK3588S and RK3588

model infer, RK3588S whole task, RK3588S infer, RK3588 whole task, RK3588 result on bus.jpg
RF-DETR Nano 131.41 ms 132.7 ms 130.35 ms 131.6 ms 1 bus, 4 people
RF-DETR-Seg Nano 211.42 ms 214.4 ms 210.16 ms 213.0 ms 5 instances: 1 bus, 4 people

From RCDL's benchmark: RCDL 0.3.0 conda packages on RCDL's own NPU runtime, NPU driver 0.9.8, one NPU core, the performance CPU governor with the process pinned to the A76 cores, median of nine runs after at least a second of warm-up. The RK3588S ran BSP kernel 6.1.118, the RK3588 6.1.141. Infer is the model run as the runtime times it: its NPU segments and the CPU operators between them. Whole task adds the resize into the input tensor and the decode.

Against the float ONNX models on 20 COCO images, stretched the same way, with detections at score 0.5 matched by class and IoU 0.5:

build F1 against float median score difference masks
RF-DETR Nano 0.983 0.0014 —
RF-DETR-Seg Nano 0.988 — mean IoU 0.994 to float

Every detection that did not match scores within 0.03 of the threshold.

The time is the model's, not the decode's. Inside the model run, the CPU's share is the decoder's deformable-attention sampling (GridSample) and the reshapes between windowed and global attention. On all three NPU cores, with the boards' default governors, an RK3588 took 101 ms for RF-DETR Nano and 159 ms for RF-DETR-Seg Nano, against 130 and 209 ms on one core.

Use it

On the board (linux-aarch64), with RCDL 0.3.1 or newer:

conda create -n rcdl -c https://mirrors.ruis.ai/conda -c conda-forge rcdl
conda activate rcdl
curl -LO https://huggingface.co/ruisv/rcdl-rf-detr/resolve/main/rfdetr_nano_384_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-rf-detr/resolve/main/rfdetr_seg_nano_312_fp16.rnpu
import cv2, numpy as np, rcdl

img = cv2.imread("bus.jpg")

det = rcdl.Engine("rfdetr_nano_384_fp16.rnpu").detr_detector(conf_thresh=0.5)
for d in rcdl.detect_detr(det, img):
    print("det", rcdl.coco_class_name(d.class_id), f"{d.score:.2f}",
          f"{d.x1:.0f} {d.y1:.0f} {d.x2:.0f} {d.y2:.0f}")

seg = rcdl.Engine("rfdetr_seg_nano_312_fp16.rnpu").detr_segmenter()
for m in rcdl.segment_instances(seg, img):
    px = int((np.asarray(m.mask) > 0).sum())        # the mask is stored within its box
    print("seg", rcdl.coco_class_name(m.class_id), f"{m.score:.2f}", f"mask {px} px")

Boxes and masks come back in source pixels. The detector's det.process_frame(frame) takes a VPU-decoded video frame instead of a numpy image. rcdl.Engine(path, core=rcdl.NpuCore.ALL) runs a model on all three cores.

What to know before deploying

The classes come back as the 80 COCO indices. RF-DETR's head scores COCO's category ids: 91 slots, 11 of them unused. detr_detector() and detr_segmenter() map them to the contiguous indices every other COCO model in RCDL uses, so rcdl.coco_class_name reads them. coco_category_ids=False turns the mapping off.

The threshold is the only filter. There is no NMS: conf_thresh (0.5) alone decides what is a detection, and it applies per (query, class) pair.

Stretched, not letterboxed. A wide or tall frame is squashed onto the square input, which is what the model was trained on. Pass the frame as it is.

Masks live inside their box. Each query's 78×78 mask logits are resized bilinearly to the image and kept where positive, within the query's box. An InstanceMask holds that part only, placed at mask_x0, mask_y0, sized mask_w × mask_h.

Time it under the performance governor. The boards default to schedutil, which clocks the CPU down while it waits for the NPU. Under it, benchmark rows that alternate NPU and CPU work measured up to about four times the numbers above, and different ones on every run. The results did not change.

.rnpu is RCDL's own format, and its NPU stack is marked experimental. The .rnpu format may still change. These files run on RK3588 / RK3588S through the rknpu driver of the vendor BSP kernels (rknpu 0.9.8, verified on kernels 6.1.118 and 6.1.141). RK3576 and RK356x are not verified, and the mainline kernel's rocket driver is not supported.

Licence

Apache-2.0, on the RF-DETR code and on the Nano and Seg Nano weights (Roboflow). Their DINOv2 backbone is Apache-2.0 too. Both models are trained on COCO.

RCDL itself is Apache-2.0 and is unrelated to these terms. It is a general-purpose runtime that loads any .rnpu or .rknn. The licence above applies to these weights and these compiled files only.

How each build was made, and the input contract for every model, are documented in RCDL's docs/MODELS.md. The licence status of every model RCDL has verified is in model_zoo/.

中文说明

RF-DETR Nano(目标检测)和 RF-DETR-Seg Nano(实例分割)为 瑞芯微 RK3588 / RK3588S NPU 编译好的模型,下载后直接加载,不用导出 ONNX,也不用转换。文件是 .rnpu 格式的 fp16 构建:由 RCDL 自研的 NPU 编译器生成,由 RCDL 自己的 NPU 运行时直接驱动板子上的 rknpu 内核驱动来运行,不需要 librknnrt,也不需要 rknn-toolkit2;这两个模型没有 .rknn 版本。自研 NPU 栈的介绍见 docs/OPEN_NPU.zh.md。

上游是 Roboflow 的 RF-DETR:基于 DINOv2 主干的 DETR 模型,在 COCO 上训练,用 rfdetr 包导出(opset 17)。代码和权重都是 Apache-2.0,DINOv2 主干也是,可以再分发,包括商用。

文件

文件 内容 输入 大小
rfdetr_nano_384_fp16.rnpu 检测,COCO 80 类,300 个 query 384×384 RGB,拉伸 186.3 MB
rfdetr_seg_nano_312_fp16.rnpu 实例分割,COCO 80 类,100 个 query,每个带一张 78×78 掩码 312×312 RGB,拉伸 81.3 MB

两个模型都吃 uint8 RGB,ImageNet 均值和方差已经放进模型里。图像按训练时的方式 拉伸到正方形输入上,不做 letterbox,由 RGA 或 CPU 直接写进 NPU 的输入张量。每个 query 给出一个框和每个 COCO 类别 id 的 logit;sigmoid 后过阈值的每个(query, 类别) 对就是一个检测,没有 NMS,什么都不抑制。

实测

模型 推理 RK3588S 整个任务 RK3588S 推理 RK3588 整个任务 RK3588 bus.jpg 上的结果
RF-DETR Nano 131.41 ms 132.7 ms 130.35 ms 131.6 ms 1 辆公交车、4 个人
RF-DETR-Seg Nano 211.42 ms 214.4 ms 210.16 ms 213.0 ms 5 个实例:1 辆公交车、4 个人

数据来自 RCDL 的 benchmark: RCDL 0.3.0 的 conda 包,自研 NPU 运行时,NPU 驱动 0.9.8,单个 NPU 核,CPU 调频策略 performance、进程绑在 A76 大核上,预热至少一秒后取九次运行的中位数。RK3588S 的 BSP 内核是 6.1.118,RK3588 是 6.1.141。「推理」是运行时自己计时的一次模型运行(NPU 段 加上夹在中间的 CPU 算子),「整个任务」再加上缩放进输入张量和解码。

与浮点 ONNX 模型在 20 张 COCO 图上对比(同样拉伸,分数 0.5,按类别和 IoU 0.5 匹配): RF-DETR Nano 的检测 F1 0.983,分数差的中位数 0.0014;RF-DETR-Seg Nano 的检测 F1 0.988,掩码与浮点模型的平均 IoU 0.994。没匹配上的检测,分数都在阈值 0.03 以内。

时间基本花在模型本身。模型运行里 CPU 承担的部分是解码器的可变形注意力采样 (GridSample),以及窗口注意力和全局注意力之间的 reshape。在 RK3588 上用默认调频策略、 三个 NPU 核一起跑:RF-DETR Nano 101 ms,RF-DETR-Seg Nano 159 ms;单核分别是 130 ms 和 209 ms。

用法

需要 RCDL 0.3.1 或更新版本,安装、下载和调用见上面的代码。框和掩码都按原图像素返回。 检测器的 det.process_frame(frame) 可以直接接 VPU 解码出来的视频帧; rcdl.Engine(path, core=rcdl.NpuCore.ALL) 让模型跑在三个核上。

部署前须知

  • 类别按 COCO 的 80 个索引返回。 RF-DETR 的检测头输出的是 COCO 类别 id(91 个 位置,其中 11 个不用)。detr_detector() 和 detr_segmenter() 默认把它们换成 RCDL 其他 COCO 模型通用的连续索引,rcdl.coco_class_name 可以直接用; coco_category_ids=False 关掉这层转换。
  • 阈值是唯一的过滤。 没有 NMS,是否算检测只看 conf_thresh(默认 0.5),按每个 (query, 类别)对判断。
  • 拉伸,不是 letterbox。 宽图或长图会被压到正方形输入上,模型训练时就是这样, 直接把原图传进去即可。
  • 掩码只存在框内。 每个 query 的 78×78 掩码 logits 双线性缩放到图像尺寸,在框内取 正值部分。InstanceMask 只保存这一块,位置是 mask_x0、mask_y0,大小 mask_w × mask_h。
  • 测速请用 performance 调频策略。 板子默认的 schedutil 会在 CPU 等 NPU 时降频; 在它下面,NPU 和 CPU 交替工作的测试项最多慢到上表的约四倍,而且每次都不一样,结果 本身不变。
  • .rnpu 是 RCDL 自己的格式,自研 NPU 栈仍标为实验性,格式以后还可能变。这些 文件在 RK3588 / RK3588S 上通过厂商 BSP 内核的 rknpu 驱动运行(rknpu 0.9.8,已在 6.1.118 和 6.1.141 两个内核上验证);RK3576、RK356x 未验证,主线内核的 rocket 驱动不支持。

许可

RF-DETR 的代码以及 Nano、Seg Nano 的权重都是 Apache-2.0(Roboflow),DINOv2 主干也是 Apache-2.0;两个模型都在 COCO 上训练。RCDL 本身是 Apache-2.0,与这些条款无关: 它是能加载任意 .rnpu 或 .rknn 的通用运行时,上面的许可只适用于这些权重和这些编译 好的文件。每个构建的做法和输入约定见 docs/MODELS.md,RCDL 核实过的每个模型的许可情况见 model_zoo/。

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support