Downloads · 30 days
86
42% of all-time downloads
Quazim0t0/Byrne-DFINE-N
Byrne-DFINE-N is a object detection model from Quazim0t0. Use it when you need objects located in an image. It is set up for tensorrt. The card lists the license as apache-2.0.
4M D-FINE object detector with the SpikeWhale HRM family trait. Pretrained on Objects365, fine-tuned on COCO (80 classes). Exports a TensorRT-compatible ONNX graph (no GridSample, explicit deformable sampling). Runs f…
Downloads · 30 days
86
42% of all-time downloads
All-time downloads
204
Public
Repo size
183 MB
Likes
0
Public
Click a slice to open those files.
.onnx16.5 MB · 47%
From the Hugging Face model README
4M D-FINE object detector with the SpikeWhale HRM family trait. Pretrained on Objects365, fine-tuned on COCO (80 classes). Exports a TensorRT-compatible ONNX graph (no GridSample, explicit deformable sampling). Runs from a laptop CPU to a Blackwell GPU.
<p align="center"> <img src="preview/test_det.png" width="70%" alt="Crowd scene - 25 detections, person @0.93 and a recovered baseball glove @0.83"> </p>Object detection, live results - TensorRT on an RTX 5060 Ti (Blackwell, sm_120), ~26 ms end-to-end.
![]() | ![]() | ![]() |
![]() | ![]() | boxes + scores are the model's raw output at conf > 0.4 |
| File | What it is |
|---|---|
model.pt | PyTorch checkpoint ({"model": state_dict}), trained with the HRM trait |
model.onnx | TensorRT-compatible ONNX (opset 16, explicit deform, gridsample_nodes: 0) |
meta.json | Full I/O + preprocessing spec and the 80 COCO class names |
src/ | Vendored model code (modified D-FINE-seg + the HRM trait) - needed to load model.pt |
preview/ | Example detections shown above |
From meta.json:
images: float32[N, 3, 640, 640], RGB, stretch-resized to 640×640, divided by 255 (mean 0 / std 1), channel layout NCHW.logits: float32[N, 300, 80] - apply sigmoid for per-class scores (the model is NMS-free; just threshold).boxes: float32[N, 300, 4] - cxcywh, normalized to [0, 1]. Convert to pixels with the original image size.The repo is gated. Authenticate first: huggingface-cli login, or pass token= / set HF_TOKEN.
model.pt)Loading the checkpoint needs the vendored model code (the HRM trait is not in upstream D-FINE-seg), which lives in src/ in this repo.
import os, sys, json
import numpy as np, torch
from PIL import Image
from huggingface_hub import snapshot_download
repo = snapshot_download("Quazim0t0/Byrne-DFINE-N") # pulls model.pt, meta.json, src/
sys.path.insert(0, repo)
os.environ["DFINE_USE_HRM"] = "1" # the checkpoint was trained with it
from src.d_fine.dfine import build_model
meta = json.load(open(f"{repo}/meta.json"))
names = meta["class_names"]; S = meta["input_h"] # 640
model = build_model("n", len(names), False, "cpu", img_size=[S, S]).eval()
model.load_state_dict(torch.load(f"{repo}/model.pt", map_location="cpu", weights_only=False)["model"])
model.cuda() # or leave on CPU
img = Image.open("your.jpg").convert("RGB"); W, H = img.size
x = np.asarray(img.resize((S, S)), np.float32) / 255.0
t = torch.from_numpy(x).permute(2, 0, 1).unsqueeze(0).cuda()
with torch.no_grad():
out = model(t)
logits, boxes = out["pred_logits"][0], out["pred_boxes"][0]
scores = logits.sigmoid(); conf, cls = scores.max(-1)
for s, c, (cx, cy, bw, bh) in zip(conf.tolist(), cls.tolist(), boxes.tolist()):
if s < 0.5: continue
x1, y1 = (cx - bw/2) * W, (cy - bh/2) * H
x2, y2 = (cx + bw/2) * W, (cy + bh/2) * H
print(f"{names[c]} {s:.2f} [{x1:.0f},{y1:.0f},{x2:.0f},{y2:.0f}]")
model.onnx, self-contained, no model code)import json, numpy as np, onnxruntime as ort
from PIL import Image
from huggingface_hub import hf_hub_download
onnx = hf_hub_download("Quazim0t0/Byrne-DFINE-N", "model.onnx")
meta = json.load(open(hf_hub_download("Quazim0t0/Byrne-DFINE-N", "meta.json")))
names = meta["class_names"]; S = meta["input_h"]
sess = ort.InferenceSession(onnx, providers=["CPUExecutionProvider"]) # or CUDAExecutionProvider
img = Image.open("your.jpg").convert("RGB"); W, H = img.size
x = np.asarray(img.resize((S, S)), np.float32) / 255.0
x = np.transpose(x, (2, 0, 1))[None] # NCHW
logits, boxes = sess.run(["logits", "boxes"], {"images": x})
scores = 1 / (1 + np.exp(-logits[0])) # sigmoid
cls = scores.argmax(1); conf = scores.max(1)
for i in np.where(conf > 0.5)[0]:
cx, cy, bw, bh = boxes[0, i]
print(names[cls[i]], round(float(conf[i]), 2),
[round((cx-bw/2)*W), round((cy-bh/2)*H), round((cx+bw/2)*W), round((cy+bh/2)*H)])
model.onnx → engine)The ONNX is already TRT-ready (explicit deformable sampling, no GridSample). Build fp32 - the D-FINE decoder is numerically sensitive and must stay FP32.
Option A - trtexec:
trtexec --onnx=model.onnx --saveEngine=byrne_dfine_n.engine \
--minShapes=images:1x3x640x640 --optShapes=images:1x3x640x640 --maxShapes=images:8x3x640x640
Option B - the dfine-cpp C++/TensorRT runtime (build engine + run detect/eval/bench). On Blackwell (RTX 50xx, sm_120) build the Docker image from nvcr.io/nvidia/tensorrt:25.08-py3 with --build-arg CUDA_ARCH=120:
# inside the dfine-cpp container
./dfine_build model.onnx byrne_dfine_n.engine # ONNX -> fp32 engine (~85 s, ~23 MiB)
./dfine_detect byrne_dfine_n.engine your.jpg # ~26 ms/frame
Apply the same preprocessing as above (RGB, stretch-resize 640, /255) and post-processing (sigmoid on logits, cxcywh-normalized boxes, no NMS).
The checkpoint is a warm-start for more detection training. Keep the HRM trait enabled (DFINE_USE_HRM=1) so the trained gate is preserved, and load model.pt with --init.
Streaming recipe (no dataset download) - the reference trainer streams detection-datasets/coco and toilaluan/object365 straight from the Hub and builds D-FINE targets on the fly (boxes normalized, category ids remapped to 0-79):
DFINE_USE_HRM=1 python train_family_dfine.py \
--init model.pt \
--dataset coco \
--model n --steps 30000 --batch-size 8 --lr 1e-4 \
--num-workers 2 --save-every 5000 \
--out runs/byrne_dfine_n_finetune
Guidelines:
--init is shape-filtered - matching tensors load, the 80-class heads reinitialize if your class count differs (Objects365→COCO reinitialized 9/686 tensors this way).--pretrained-backbone to start the HGNetV2 backbone from ImageNet (much faster convergence) when training a fresh stage; omit it to keep the current weights.eval_det_loss.py), not the augmented training loss.dfine-cpp/trt-files/scripts/export_dfine_onnx.py --deform explicit --dfine-src <this src/>. The custom RMSNorm in the HRM trait is decomposed from primitives specifically so the graph exports to ONNX opset 16 (fused aten::rms_norm has no symbolic).For a conventional (downloaded-COCO) fine-tune, the vendored src/ is a drop-in modified D-FINE-seg - use its standard training loop with DFINE_USE_HRM=1.
License: Apache-2.0.