Models · Object detection

D-FINE (HGNetV2, N / S / M / L / X)

D-FINE (N, S, M, L, X; HGNetV2, COCO) from USTC: real-time end-to-end detector in the RT-DETR style, 300 queries, deformable attention and box edges refined as distributions, no NMS. Also DEIM (N, S, M, L, X): the same network with SiLU decoder MLPs, trained with dense one-to-one matching.

stable Fork of Peterande/D-FINE@956d170 · backends: portable, kernels

Checkpoint

Paper 2024 Added in 0.1.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 2.48 ms 800x1344, fp16
vs the faster original 9.8× original fp32: 24.3 ms
Peak memory 94 MiB original: 91 MiB
Accuracy vs original fp32 +0.03 kernels box mAP, COCO val2017 (42.94 original)

Use it

pip install fastforks

Lean install with only what this model needs: pip install fastforks-core

from fastforks import detection

model = detection.load("dfine-n-coco")  # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.boxes  # also: scores, labels
result.backend  # what ran: mode, device, dtype, kernels
fastforks bench dfine-n-coco

Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.

Speed and memory

Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.

Input: synthetic, 800x1344 (the task’s standard size)

BackenddtypeTime per call (ms)vs original fp32Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir)fp32 24.3–91 MiB/122 MiB0.20.35
Original fp16torch.autocast(fp16) around the forward; incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir); fp16 differs from the reference (box max diff 65.17 px)fp16 29.10.83×92 MiB/126 MiB5.24.07
Portable fp32fp32not measured ––––
Portablefp16 10.42.3×92 MiB/114 MiB1.10.80
Kernelsfp16 2.489.8×94 MiB/118 MiB1.40.41
Portable + torch.compile 5.434.5×101 MiB/118 MiB27 (build)–
TensorRT fp16fp16 1.0822×56 MiBenginenot comparable64 (build)–

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-06 to 2026-11-16. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.

Other devices

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp3245.4 1,663 MiB process–800x1344
Portablefp1625.2 1,510 MiB processmatches800x1344
Portablefp3240.9 1,545 MiB processmatches800x1344
Kernelsfp16not implemented–800x1344
NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1617.4 65 MiB/76 MiB–800x1344
Kernelsfp163.45 77 MiB/160 MiB–800x1344
NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1611.8 65 MiB/76 MiB–800x1344
Kernelsfp162.41 77 MiB/160 MiB–800x1344
NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1610.2 65 MiB/76 MiB–800x1344
Kernelsfp163.68 78 MiB/160 MiB–800x1344
NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1612.5 65 MiB/76 MiB–800x1344
Kernelsfp164.06 81 MiB/160 MiB–800x1344
NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08Portablefp164.38 88 MiB/116 MiB–800x1344
Kernelsfp161.89 126 MiB/200 MiB–800x1344

CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.

Licence and weights

Commercial use allowed

Code
Apache-2.0 LICENSELICENSE-DEIM
Weights
Apache-2.0 source
Training data

Our reading of the licences, not legal advice.

Weights

dfine-nano-coco.safetensors 15.3 MB· hosted on Hugging Face

fastforks downloads and checks these files on first use (fastforks download dfine-n-coco).

Accuracy

The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.

COCO val2017

every 10th image, box mAP

Rundtypebox mAP ↑Δ box mAP vs fp32 originalimagesms / image
Original fp32fp3242.94 reference 500 19.1
Original fp16fp1642.91 −0.03 500 23.6
Portable fp32fp3242.98 +0.04 500 10.5
Portablefp1642.91 −0.03 500 10.2
Kernelsfp1642.97 +0.03 500 2.67

pycocotools COCOeval of the top 100 detections per image. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-11; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 675d6e93, 2026-11-11.

Closeness to the original

Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. 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).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.002 not recorded
GPU default dtypes, mean |diff|≤ 0.2 0.091
GPU default dtypes, p99 |diff|≤ 1 0.32514

Recorded for dfine-n-coco on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: cudnn_haccfvm_conv

Details

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).

Input / output
Input: one RGB image. Output: boxes, class labels, scores and instance masks.
Input size
any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (498 MiB allocated)
Options
  • score_threshold=0.050.0 to 1.0· changes the output
  • max_detections=100>= 1· changes the output
  • cuda_graphs=true
Outputs
boxes, scores, labels
Checkpoint
stem=[16,16], mid=[16,32,64,128], out=[64,256,512,1024], blocks=[1,1,2,1], layers=3, lab=true, levels=2, enc_dim=128, dec_dim=128, enc_ffn=512, dec_ffn=512, csp_blocks=2, expansion=0.34, dec_layers=3, points=[6,6]
CUDA kernels
  • cudnn_haccconvolutions with fp16 accumulation (cuDNN)
  • fvm_convfused convolutions for image classifiers
Apple (MPS)
fp32, fp16

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.
  • deim-* variants: DEIM (Huang et al. 2025), the D-FINE network with SiLU decoder MLPs, trained with dense one-to-one matching; weights and the original in the benchmarks are from the official DEIM repository (@09d35d53).
Full reference, generated from the repository

D-FINE (N, S, M, L, X; HGNetV2, COCO) from USTC: real-time end-to-end detector in the RT-DETR style, 300 queries, deformable attention and box edges refined as distributions, no NMS. Also DEIM (N, S, M, L, X): the same network with SiLU decoder MLPs, trained with dense one-to-one matching.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
dfine-n-cocosynthetic (800x1344)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
24.3
29.1
10.4
2.48
5.43
1.08
91 / 122
92 / 126
92 / 114
94 / 118
101 / 118
104 / 128
dfine-s-cocosynthetic (800x1344)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
25.7
31.9
11.4
3.75
5.63
1.65
180 / 204
152 / 184
108 / 128
108 / 170
131 / 152
147 / 160
dfine-m-cocosynthetic (800x1344)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
30.8
38.2
13.7
5.07
6.79
2.49
231 / 264
209 / 256
129 / 142
129 / 184
149 / 166
204 / 232
dfine-l-cocosynthetic (800x1344)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
37.1
44.9
16.6
6.53
7.91
3.19
281 / 328
278 / 350
155 / 172
151 / 216
175 / 198
219 / 256
dfine-x-cocosynthetic (800x1344)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
44.9
54.6
18.6
9.59
11.0
5.64
452 / 488
476 / 536
230 / 258
231 / 298
245 / 284
342 / 374
deim-n-cocosynthetic (800x1344)original
portable
kernels
portable + torch.compile
TensorRT fp16
24.6
10.4
2.46
5.44
1.10
93 / 124
92 / 114
94 / 118
101 / 118
104 / 128
deim-s-cocosynthetic (800x1344)original
portable
kernels
portable + torch.compile
TensorRT fp16
26.4
11.3
3.73
5.63
1.68
154 / 180
108 / 128
108 / 170
131 / 152
163 / 176
deim-m-cocosynthetic (800x1344)original
portable
kernels
portable + torch.compile
TensorRT fp16
31.4
13.8
5.08
6.73
2.54
210 / 250
129 / 142
129 / 184
149 / 166
204 / 232
deim-l-cocosynthetic (800x1344)original
portable
kernels
portable + torch.compile
TensorRT fp16
36.1
16.3
6.50
7.99
3.39
264 / 322
155 / 172
151 / 216
175 / 198
229 / 266
deim-x-cocosynthetic (800x1344)original
portable
kernels
portable + torch.compile
TensorRT fp16
41.3
18.7
9.53
11.0
5.10
462 / 502
230 / 258
231 / 298
245 / 284
352 / 394
Details
  • Original code: https://github.com/Peterande/D-FINE at 956d1709314c
  • Code licence: Apache-2.0 (permissive); files: LICENSE, LICENSE-DEIM
  • Weights licence: Apache-2.0
    • deim-n-coco: Apache-2.0 (assumed from code)
    • deim-s-coco: Apache-2.0 (assumed from code)
    • deim-m-coco: Apache-2.0 (assumed from code)
    • deim-l-coco: Apache-2.0 (assumed from code)
    • deim-x-coco: Apache-2.0 (assumed from code)
  • Licence evidence: https://github.com/Peterande/D-FINE/blob/956d1709314c2c6a4df6f34de232054578a7449f/LICENSE
  • Training data: COCO 2017 (train, instance annotations), ImageNet-1k (ILSVRC 2012 classification) (COCO 2017 train; the HGNetV2 backbones start from ImageNet-1k pretraining)
  • Options: score_threshold = 0.05 (0.0 to 1.0), max_detections = 100 (>= 1), cuda_graphs = True (speed only)
  • Kernel libraries: cudnn_hacc, fvm_conv
  • Variants: dfine-n-coco, dfine-s-coco, dfine-m-coco, dfine-l-coco, dfine-x-coco, deim-n-coco, deim-s-coco, deim-m-coco, deim-l-coco, deim-x-coco
  • Outputs: boxes, scores, labels; label_set: coco-80
  • Input size: any H x W >= 32, padded to a multiple of 32
  • Tested up to (portable, fp16, RTX 5060 Ti 16 GB): 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-m-coco 3000x4000 (0.5 GiB peak allocated, 0.6 reserved); dfine-l-coco 3000x4000 (0.5 GiB peak allocated, 0.7 reserved); dfine-x-coco 3000x4000 (0.6 GiB peak allocated, 0.7 reserved); deim-n-coco 3000x4000 (0.5 GiB peak allocated, 0.5 reserved); deim-s-coco 3000x4000 (0.5 GiB peak allocated, 0.5 reserved); deim-m-coco 3000x4000 (0.5 GiB peak allocated, 0.5 reserved); deim-l-coco 3000x4000 (0.5 GiB peak allocated, 0.6 reserved); deim-x-coco 3000x4000 (0.6 GiB peak allocated, 0.6 reserved)
  • dfine-n-coco 800x1344, first call: portable + torch.compile 27 s (cold Inductor cache), TensorRT fp16 64 s (ONNX + engine).
  • dfine-s-coco 800x1344, first call: portable + torch.compile 31 s (cold Inductor cache), TensorRT fp16 51 s (ONNX + engine).
  • dfine-m-coco 800x1344, first call: portable + torch.compile 36 s (cold Inductor cache), TensorRT fp16 55 s (ONNX + engine).
  • dfine-l-coco 800x1344, first call: portable + torch.compile 46 s (cold Inductor cache), TensorRT fp16 59 s (ONNX + engine).
  • dfine-x-coco 800x1344, first call: portable + torch.compile 48 s (cold Inductor cache), TensorRT fp16 107 s (ONNX + engine).
  • deim-n-coco 800x1344, first call: portable + torch.compile 28 s (cold Inductor cache), TensorRT fp16 66 s (ONNX + engine).
  • deim-s-coco 800x1344, first call: portable + torch.compile 31 s (cold Inductor cache), TensorRT fp16 58 s (ONNX + engine).
  • deim-m-coco 800x1344, first call: portable + torch.compile 39 s (cold Inductor cache), TensorRT fp16 58 s (ONNX + engine).
  • deim-l-coco 800x1344, first call: portable + torch.compile 50 s (cold Inductor cache), TensorRT fp16 58 s (ONNX + engine).
  • deim-x-coco 800x1344, first call: portable + torch.compile 49 s (cold Inductor cache), TensorRT fp16 66 s (ONNX + engine).
  • dfine-n-coco original (fp32) 800x1344: incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir)
  • dfine-n-coco original 800x1344: torch.autocast(fp16) around the forward; incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir); fp16 differs from the reference (box max diff 65.17 px)
  • dfine-s-coco original (fp32) 800x1344: incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir)
  • dfine-s-coco original 800x1344: torch.autocast(fp16) around the forward; incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir)
  • dfine-m-coco original (fp32) 800x1344: incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir)
  • dfine-m-coco original 800x1344: torch.autocast(fp16) around the forward; incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir); fp16 differs from the reference (detections 5 vs reference 4)
  • dfine-l-coco original (fp32) 800x1344: incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir)
  • dfine-l-coco original 800x1344: torch.autocast(fp16) around the forward; incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir)
  • dfine-x-coco original (fp32) 800x1344: incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir)
  • dfine-x-coco original 800x1344: torch.autocast(fp16) around the forward; incl. CPU PIL resize + host-to-device copy of the HF-transformers pipeline (the official D-FINE .pth is not in the weights dir)
  • deim-n-coco original 800x1344: torch.autocast(float16) around the call; official DEIM deploy model; incl. CPU PIL resize + host-to-device copy, RT-DETR postprocess (all 300)
  • deim-s-coco original 800x1344: torch.autocast(float16) around the call; official DEIM deploy model; incl. CPU PIL resize + host-to-device copy, RT-DETR postprocess (all 300)
  • deim-m-coco original 800x1344: torch.autocast(float16) around the call; official DEIM deploy model; incl. CPU PIL resize + host-to-device copy, RT-DETR postprocess (all 300)
  • deim-l-coco original 800x1344: torch.autocast(float16) around the call; official DEIM deploy model; incl. CPU PIL resize + host-to-device copy, RT-DETR postprocess (all 300)
  • deim-x-coco original 800x1344: torch.autocast(float16) around the call; official DEIM deploy model; incl. CPU PIL resize + host-to-device copy, RT-DETR postprocess (all 300)
  • dfine-n-coco load / first call: original 5.24 s / 4.072 s, portable 1.25 s / 0.853 s, kernels 1.21 s / 0.621 s
  • dfine-s-coco load / first call: original 2.99 s / 1.443 s, portable 1.24 s / 0.697 s, kernels 1.39 s / 0.358 s
  • dfine-m-coco load / first call: original 3.63 s / 1.546 s, portable 1.36 s / 0.702 s, kernels 1.49 s / 0.345 s
  • dfine-l-coco load / first call: original 3.68 s / 1.406 s, portable 1.72 s / 0.665 s, kernels 1.56 s / 0.322 s
  • dfine-x-coco load / first call: original 3.88 s / 1.452 s, portable 1.65 s / 0.642 s, kernels 1.83 s / 0.294 s
  • deim-n-coco load / first call: original 2.39 s / 0.622 s, portable 1.61 s / 1.355 s, kernels 1.25 s / 0.583 s
  • deim-s-coco load / first call: original 2.08 s / 0.534 s, portable 1.29 s / 0.687 s, kernels 1.43 s / 0.352 s
  • deim-m-coco load / first call: original 2.24 s / 0.579 s, portable 1.38 s / 0.676 s, kernels 1.52 s / 0.346 s
  • deim-l-coco load / first call: original 2.34 s / 0.516 s, portable 1.51 s / 0.665 s, kernels 1.61 s / 0.321 s
  • deim-x-coco load / first call: original 2.63 s / 0.483 s, portable 1.72 s / 0.635 s, kernels 1.84 s / 0.286 s
  • Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5

Measured

pycocotools COCOeval of the top 100 detections per image. Original = the original code named under Details, same checkpoint and protocol.

variantdatasetoriginal fp32original fp16portableportable fp32kernelsnote
dfine-n-cocoCOCO val2017, every 10th image, box mAP42.9442.9142.9142.9842.97
dfine-s-cocoCOCO val2017, every 10th image, box mAP49.8449.8349.8849.8449.89
dfine-m-cocoCOCO val2017, every 10th image, box mAP51.9251.9552.0351.9252.00
dfine-l-cocoCOCO val2017, every 10th image, box mAP54.1754.1854.1454.1554.17
dfine-x-cocoCOCO val2017, every 10th image, box mAP56.4056.3856.3056.3556.32
deim-n-cocoCOCO val2017, every 10th image, box mAP44.3844.3744.4044.3644.38
deim-s-cocoCOCO val2017, every 10th image, box mAP49.4649.4549.5049.3649.52
deim-m-cocoCOCO val2017, every 10th image, box mAP52.3852.4352.4352.3852.43
deim-l-cocoCOCO val2017, every 10th image, box mAP54.6754.6554.6754.6754.67
deim-x-cocoCOCO val2017, every 10th image, box mAP56.8756.9156.8656.8856.90

Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 675d6e93 / a981ff86, 2026-11-11 to 2026-11-12; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 675d6e93 / a981ff86, 2026-11-11 to 2026-11-12.

Parity

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).

variantkernels error vs original, mean / p99GPU, torchkernels used
dfine-n-coco0.091 / 0.32514RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120
dfine-s-coco0.05359 / 0.148RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120
dfine-m-coco0.06031 / 0.24838RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120
dfine-l-coco0.03714 / 0.09859RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120
dfine-x-coco0.03798 / 0.08887RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120
deim-n-coco0.07347 / 0.36832RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120
deim-s-coco0.04567 / 0.27886RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120
deim-m-coco0.04894 / 0.17919RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120
deim-l-coco0.03909 / 0.0618RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120
deim-x-coco0.05634 / 0.13909RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120

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.
  • deim-* variants: DEIM (Huang et al. 2025), the D-FINE network with SiLU decoder MLPs, trained with dense one-to-one matching; weights and the original in the benchmarks are from the official DEIM repository (@09d35d53).

Example output

One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti).

Input
Output
  • person 0.93
  • toothbrush 0.57
Astronaut Eileen Collins, input
Input · 100%

Input: Astronaut Eileen Collins, NASA (public domain).