D-FINE (HGNetV2, N / S / M / L / X) (fastforks)
D-FINE (Peng et al. 2025, USTC): real-time end-to-end detection like RT-DETR (HGNetV2 backbone, hybrid encoder, deformable-attention decoder over 300 selected queries, no NMS) whose decoder layers refine every box edge as a distribution over distances (fine-grained distribution refinement); boxes, scores and COCO classes at the input size. The portable module() is the whole network at 640x640 (class logits and normalised boxes).
This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/Peterande/D-FINE at 956d1709314c.
Author weight repos: https://huggingface.co/ustc-community/dfine-large-coco, https://huggingface.co/ustc-community/dfine-medium-coco, https://huggingface.co/ustc-community/dfine-nano-coco, https://huggingface.co/ustc-community/dfine-small-coco, https://huggingface.co/ustc-community/dfine-xlarge-coco.
Task: detection. Tier: stable. Outputs: boxes, scores, labels. Backends: portable, kernels.
Input: one RGB image. Output: boxes, class labels, scores and instance masks.
Variants
Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
dfine-l-coco@1 |
dfine-large-coco.safetensors | 4e9d77ba937a |
Apache-2.0 | yes |
dfine-m-coco@1 |
dfine-medium-coco.safetensors | 5a53154fb87a |
Apache-2.0 | yes |
dfine-n-coco@1 |
dfine-nano-coco.safetensors | 19e06bdc873d |
Apache-2.0 | yes |
dfine-s-coco@1 |
dfine-small-coco.safetensors | a144baff3a27 |
Apache-2.0 | yes |
dfine-x-coco@1 |
dfine-xlarge-coco.safetensors | 3ac6ea37c6c9 |
Apache-2.0 | yes |
Licence
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Files: LICENSE.
Training data: COCO 2017 (train, instance annotations), ImageNet-1k (ILSVRC 2012 classification) (COCO 2017 train; the HGNetV2 backbones start from ImageNet-1k pretraining).
Licence evidence: https://github.com/Peterande/D-FINE/blob/956d1709314c2c6a4df6f34de232054578a7449f/LICENSE
Input size
any H x W >= 32, padded to a multiple of 32
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): dfine-l-coco 3000x4000 (0.5 GiB peak allocated, 0.7 reserved); dfine-m-coco 3000x4000 (0.5 GiB peak allocated, 0.6 reserved); dfine-n-coco 3000x4000 (0.5 GiB peak allocated, 0.6 reserved); dfine-s-coco 3000x4000 (0.5 GiB peak allocated, 0.6 reserved); dfine-x-coco 3000x4000 (0.6 GiB peak allocated, 0.7 reserved)
Speed and memory
Detection, synthetic, 800x1344
| model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|---|---|---|---|---|---|---|---|---|---|
dfine-l-coco |
37.1 | 44.9 | 16.2 | 8.70 | 4.3x | 1.9x | 278 / 350 | 152 / 172 | 179 / 300 |
dfine-m-coco |
30.8 | 38.2 | 13.5 | 5.97 | 5.2x | 2.3x | 209 / 256 | 126 / 142 | 156 / 252 |
dfine-n-coco |
24.3 | 29.1 | 10.3 | 2.72 | 8.9x | 3.8x | 92 / 126 | 88 / 116 | 124 / 202 |
dfine-s-coco |
25.7 | 31.9 | 11.1 | 4.04 | 6.4x | 2.7x | 152 / 184 | 105 / 128 | 138 / 212 |
dfine-x-coco |
44.9 | 54.6 | 18.5 | 14.1 | 3.2x | 1.3x | 476 / 536 | 227 / 258 | 237 / 364 |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
dfine-l-coco |
3.68 | 1.09 | 1.46 | 1.41 | 0.67 | 0.47 |
dfine-m-coco |
3.63 | 1.04 | 1.20 | 1.55 | 0.69 | 0.56 |
dfine-n-coco |
5.24 | 1.25 | 1.21 | 4.07 | 0.85 | 0.62 |
dfine-s-coco |
2.99 | 1.05 | 1.16 | 1.44 | 0.71 | 0.52 |
dfine-x-coco |
3.88 | 1.39 | 1.41 | 1.45 | 0.65 | 0.45 |
torch.compile and TensorRT
| model | input | portable ms | compile ms | compile s (cold) | TensorRT fp16 ms | ONNX + build s | kernels ms | peak MiB (alloc / reserved): portable | compile | TensorRT (device) |
|---|---|---|---|---|---|---|---|---|---|---|
dfine-n-coco |
800x1344 | 10.3 | 5.4 | 26.7 | 1.4 | 51 | 2.72 | 88 / 116 | 101 / 118 | 94 |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the authors' code at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.
Accuracy
Parity with the original code
Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.2 and p99 <= 1.0 (absolute error of the output boxes).
Limitations
- The original in the benchmarks and goldens is the Hugging Face transformers 5.19.0 port (DFineForObjectDetection, ustc-community weights) of the official D-FINE (Apache-2.0); the official repository code itself was not run.
Usage
from fastforks import detection
model = detection.load("dfine-l-coco") # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.boxes, result.scores, result.labels # [N, 4], [N], [N]
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: dfine-l-coco, dfine-m-coco, dfine-n-coco, dfine-s-coco, dfine-x-coco.
Kernels backend
detection.load("dfine-l-coco", mode="kernels") runs our CUDA kernels (cudnn_hacc). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels on first use) and a recent NVIDIA driver; if there is none it raises BackendUnavailableError with the reason and never falls back silently. mode="auto" picks kernels when it can run and logs the choice.