Instructions to use amirivojdan/khoroos_detector_dfine_s with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use amirivojdan/khoroos_detector_dfine_s with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("object-detection", model="amirivojdan/khoroos_detector_dfine_s")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForObjectDetection tokenizer = AutoTokenizer.from_pretrained("amirivojdan/khoroos_detector_dfine_s") model = AutoModelForObjectDetection.from_pretrained("amirivojdan/khoroos_detector_dfine_s", device_map="auto") - Notebooks
- Google Colab
- Kaggle
khoroos_detector_dfine_s
D-FINE-S fine-tuned to detect chickens in overhead farm video. It is one of the detectors of Khoroos, a toolkit for analyzing chicken behavior in farm video, where it finds every bird in each frame before tracking and behavior recognition.
- Architecture: D-FINE-S
(HGNetv2-B0 backbone), 10.2 M parameters, in the Hugging Face Transformers
implementation (
DFineForObjectDetection). - Initialization: the official COCO-trained D-FINE-S weights (not the Objects365 ones).
- Fine-tuning data: ChickenDet from the ChickenVerse dataset: 5,222 training images, 1,067 validation images (research pens) and 250 test images from a commercial house that is not in the training or validation data.
- Input: one RGB frame of any size, resized to 640Γ640.
- Output: one box and confidence score per chicken (single class,
Chicken).
Results on the unseen commercial house
COCO box metrics on the 250 ChickenDet test images (12,620 birds), from Khoroos's detector at confidence 0.01 with its usual NMS (IoU 0.6):
| AP | AP50 | AP75 | AP small | AP medium | AP large | AR100 |
|---|---|---|---|---|---|---|
| 0.824 | 0.958 | 0.882 | 0.449 | 0.828 | 0.907 | 0.862 |
Without NMS, as D-FINE is designed to run, AP is 0.826; D-FINE's own evaluation of the training checkpoint gave 0.826.
Khoroos runs this detector at confidence 0.55 by default (default_confidence in
config.json). There, counting a detection as correct at IoU β₯ 0.5, precision is
0.894, recall 0.957 and F1
0.925. 0.55 is the best-F1 confidence on the Validation
split (research pens), rounded down to a multiple of 0.05; on this test house F1 peaks at
0.72 (F1 0.937).
Best validation AP (research pens) was 0.929, at epoch 78. Results come from one training seed.
Results on a different dataset (Big Broiler)
Without further training, on the 15 fully annotated pen videos of the public Big Broiler dataset (other farms, cameras and ages), at confidence 0.55: AP 0.628, AP50 0.930, precision 0.772, recall 0.940, F1 0.847. Tracking these detections gave HOTA 0.645 (best tracker: sort). Every frame of each video was detected; see the Khoroos repository for the benchmark.
Weight formats
Only the format you select is downloaded. Accuracy is measured on the test set in the
device column; F1 is at the default confidence. Speed is the whole Khoroos detect call
per 1280Γ720 frame (resizing, model, NMS), in milliseconds for batches of 1 / 16, on an
NVIDIA GB10 GPU and its 20-core Arm CPU.
| Format | File | Runs with | MB | AP | AP50 | F1 | Measured on | GPU ms | CPU ms |
|---|---|---|---|---|---|---|---|---|---|
fp32 |
model.safetensors |
PyTorch (Transformers), FP32 | 41.1 | 0.824 | 0.958 | 0.925 | CUDA | 11.7 / 12.2 | 883.1 / 131.3 |
fp16 |
model.fp16.safetensors |
PyTorch (Transformers), FP16 (GPU) | 20.6 | 0.822 | 0.958 | 0.925 | CUDA | 8.1 / 5.8 | β |
onnx-fp32 |
onnx/model.onnx |
ONNX Runtime, FP32 | 41.4 | 0.824 | 0.958 | 0.925 | CUDA | 17.7 / 11.3 | 178.1 / 86.1 |
onnx-fp16 |
onnx/model_fp16.onnx |
ONNX Runtime, FP16 (GPU) | 21.2 | 0.822 | 0.963 | 0.925 | CUDA | 34.0 / 16.2 | β |
onnx-int8 |
onnx/model_int8.onnx |
ONNX Runtime, static INT8 (CPU) | 26.6 | 0.815 | 0.956 | 0.926 | CPU | β | 171.5 / 81.9 |
Khoroos's auto format uses fp16 on a GPU and onnx-fp32 on a CPU with ONNX Runtime.
The INT8 model is statically quantized: per-channel INT8 convolution weights and UINT8
activations whose ranges were calibrated on the first 200 ChickenDet Train images.
Only convolutions (the backbone and the encoder's convolutional layers) are quantized;
the transformer encoder layer, the decoder and the detection heads stay in floating point. For this size the FP32 ONNX model is about as fast on a CPU and more accurate, so it is the CPU default.
Preprocessing
As in D-FINE's training:
- Resize the frame to 640Γ640 without keeping its aspect ratio, bilinearly with antialiasing.
- Pass RGB values divided by 255 (range [0, 1]), without mean/std normalization.
The model returns logits (batch, 300, 1) and pred_boxes (batch, 300, 4) (centre x,
centre y, width, height as fractions of the image). The score is sigmoid(logit);
multiply boxes by the frame's width and height. D-FINE needs no non-maximum suppression.
Usage
In Khoroos:
khoroos analyze farm.mp4 --detector-model dfine-s
khoroos analyze farm.mp4 --detector-model dfine-s --detector-format onnx-int8 --device cpu
from khoroos import analyze_video
result = analyze_video("farm.mp4", detector_model="dfine-s")
With Transformers:
import torch
from PIL import Image
from transformers import DFineForObjectDetection
from torchvision.transforms.functional import pil_to_tensor, resize
model = DFineForObjectDetection.from_pretrained("amirivojdan/khoroos_detector_dfine_s").eval()
image = Image.open("frame.jpg").convert("RGB")
x = resize(pil_to_tensor(image), [640, 640], antialias=True).float()[None] / 255
with torch.no_grad():
out = model(pixel_values=x)
scores = out.logits[0, :, 0].sigmoid()
keep = scores > 0.55
cx, cy, w, h = out.pred_boxes[0, keep].T
boxes = torch.stack([cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2], 1)
boxes *= torch.tensor([image.width, image.height] * 2)
The ONNX models run with ONNX Runtime alone (input images, outputs logits and
pred_boxes).
Training
Fine-tuned from the COCO-trained weights with the official D-FINE trainer (commit
956d170) and its custom-dataset recipe
(configs/dfine/custom/dfine_hgnetv2_s_custom.yml) on one NVIDIA GB10
(4.9 h):
- 80 epochs (the recipe's large-model schedule, used for every size), mixed precision, seed 42; strong augmentation and multi-scale training were switched off from epoch 72, as the recipe does.
- Recipe optimizer, learning rates, augmentation and exponential moving average of the weights, unchanged.
- The best checkpoint on the Validation split was kept: AP 0.929 at epoch 78.
The checkpoint was converted to Transformers' DFineForObjectDetection and checked against
D-FINE's own network in float64 on test images (largest differences: logits
4.3e-04, boxes
6.1e-07). D-FINE evaluates with an anchor
grid stored in the checkpoint, which differs from the grid it generates while training by up
to 2e-04; Transformers always
generates the grid, as in training. Test AP is unchanged (above).
Limitations
- Trained on overhead and oblique views of broiler pens and one commercial house; other housing, camera angles and lighting may need fine-tuning.
- Small birds remain the hardest case (AP small 0.449).
- One training seed; differences of about a point between models are within the range a different seed could produce.
License
Released under CC BY-NC-SA 4.0. The D-FINE code and COCO-trained weights are Apache-2.0; the ChickenVerse training data is CC BY-NC-SA 4.0. Non-commercial use only; adaptations must be shared under the same license.
Citation
@inproceedings{peng2025dfine,
title = {D-FINE: Redefine Regression Task of DETRs as Fine-grained Distribution Refinement},
author = {Peng, Yansong and Li, Hebei and Wu, Peixi and Zhang, Yueyi and Sun, Xiaoyan and Wu, Feng},
booktitle = {International Conference on Learning Representations},
year = {2025}
}
- Downloads last month
- 22