D-FINE Nano for RK3588: COCO detection without NMS

A compiled model for the Rockchip RK3588 / RK3588S NPU, ready to load: no ONNX export, no conversion. It is an .rnpu file, an fp16 build 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 this model. 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: D-FINE Nano, a DETR detector on an HGNetv2 backbone at 640, trained on COCO. Exported from transformers' DFineForObjectDetection (ustc-community/dfine-nano-coco), opset 17.

Redistributable, including commercially. D-FINE Nano is Apache-2.0 on the code and on the weights. See Licence.

Files

file what it is input size
dfine_n_640_fp16.rnpu detection, 80 COCO classes, 300 queries 640×640 RGB, stretched 9.8 MB

The model takes uint8 RGB, with the /255 inside the build. The image is stretched onto the square input, as D-FINE is trained, not letterboxed; RGA or the CPU writes it straight into the NPU's input tensor. Each of the 300 queries is a box (cx, cy, w, h in 0..1) and 80 class logits, already the contiguous COCO indices. 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
D-FINE Nano 76.46 ms 79.8 ms 82.76 ms 87.0 ms 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 model on 20 COCO images, stretched the same way, with detections at score 0.5 matched by class and IoU 0.5: F1 0.998, a median score difference of 0.0012. Every detection that did not match scores within 0.03 of the threshold.

On all three NPU cores, with the boards' default governors, an RK3588 took 49 ms, against 73 ms on one core. The CPU's share of the model run is the decoder's deformable-attention sampling (GridSample).

The smaller of RCDL's two COCO DETR detectors is also the faster. In the same benchmark, RF-DETR Nano (186.3 MB) takes 131.41 ms to infer on the RK3588S, and both find the same bus and four people.

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-d-fine/resolve/main/dfine_n_640_fp16.rnpu
import cv2, rcdl

det = rcdl.Engine("dfine_n_640_fp16.rnpu").detr_detector(coco_category_ids=False, conf_thresh=0.5)
print(det.num_queries, "queries,", det.num_classes, "classes")
for d in rcdl.detect_detr(det, cv2.imread("bus.jpg")):
    print(rcdl.coco_class_name(d.class_id), f"{d.score:.2f}",
          f"{d.x1:.0f} {d.y1:.0f} {d.x2:.0f} {d.y2:.0f}")

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

What to know before deploying

Create the detector with coco_category_ids=False. D-FINE's 80 classes are already the contiguous indices that rcdl.coco_class_name takes. The default, True, is for RF-DETR, whose head scores COCO's category ids (1 = person ... 90) and needs them mapped.

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.

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. This file runs 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 D-FINE code and on the Nano weights. The model is 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 this compiled file only.

How the 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/.

中文说明

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

上游是 D-FINE Nano:HGNetv2 主干、640 输入的 DETR 检测器,在 COCO 上训练,从 transformers 的 DFineForObjectDetection (ustc-community/dfine-nano-coco) 导出,opset 17。代码和权重都是 Apache-2.0,可以再分发,包括商用。

文件

文件 内容 输入 大小
dfine_n_640_fp16.rnpu 检测,COCO 80 类,300 个 query 640×640 RGB,拉伸 9.8 MB

模型吃 uint8 RGB,/255 已经放进模型里。图像按训练时的方式拉伸到正方形输入上, 不做 letterbox,由 RGA 或 CPU 直接写进 NPU 的输入张量。300 个 query 每个给出一个框和 80 个类别 logit,类别已经是连续的 COCO 索引;sigmoid 后过阈值的每个(query, 类别)对 就是一个检测,没有 NMS。

实测

模型 推理 RK3588S 整个任务 RK3588S 推理 RK3588 整个任务 RK3588 bus.jpg 上的结果
D-FINE Nano 76.46 ms 79.8 ms 82.76 ms 87.0 ms 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 匹配): F1 0.998,分数差的中位数 0.0012;没匹配上的检测,分数都在阈值 0.03 以内。

在 RK3588 上用默认调频策略、三个 NPU 核一起跑是 49 ms,单核 73 ms。模型运行里 CPU 承担的是解码器的可变形注意力采样(GridSample)。同一套 benchmark 里, RF-DETR Nano(186.3 MB)在 RK3588S 上 推理要 131.41 ms,两者找到的都是同一辆公交车和四个人:D-FINE Nano 更小也更快。

用法

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

部署前须知

  • 创建检测器时要传 coco_category_ids=False。 D-FINE 的 80 个类别已经是 rcdl.coco_class_name 用的连续索引;默认值 True 是给 RF-DETR 用的,它的检测头 输出 COCO 类别 id(1 = person … 90),需要转换。
  • 阈值是唯一的过滤。 没有 NMS,是否算检测只看 conf_thresh(默认 0.5),按每个 (query, 类别)对判断。
  • 拉伸,不是 letterbox。 宽图或长图会被压到正方形输入上,模型训练时就是这样, 直接把原图传进去即可。
  • 测速请用 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 驱动不支持。

许可

D-FINE 的代码和 Nano 权重都是 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

Model tree for ruisv/rcdl-d-fine

Finetuned
(3)
this model