khoroos_detector_dfine_l

D-FINE-L 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-L (HGNetv2-B4 backbone), 31.2 M parameters, in the Hugging Face Transformers implementation (DFineForObjectDetection).
  • Initialization: the official COCO-trained D-FINE-L 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.859 0.972 0.918 0.490 0.862 0.930 0.889

Without NMS, as D-FINE is designed to run, AP is 0.860; D-FINE's own evaluation of the training checkpoint gave 0.860.

Khoroos runs this detector at confidence 0.65 by default (default_confidence in config.json). There, counting a detection as correct at IoU β‰₯ 0.5, precision is 0.930, recall 0.965 and F1 0.947. 0.65 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.75 (F1 0.952).

Best validation AP (research pens) was 0.940, at epoch 72. 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.65: AP 0.677, AP50 0.944, precision 0.884, recall 0.965, F1 0.923. Tracking these detections gave HOTA 0.718 (best tracker: mcbyte). 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 125.0 0.859 0.972 0.947 CUDA 25.4 / 23.9 1544.9 / 288.6
fp16 model.fp16.safetensors PyTorch (Transformers), FP16 (GPU) 62.6 0.857 0.972 0.948 CUDA 15.4 / 11.7 –
onnx-fp32 onnx/model.onnx ONNX Runtime, FP32 125.2 0.859 0.972 0.947 CUDA 25.9 / 20.5 380.1 / 211.1
onnx-fp16 onnx/model_fp16.onnx ONNX Runtime, FP16 (GPU) 63.3 0.857 0.972 0.948 CUDA 47.3 / 25.4 –
onnx-int8 onnx/model_int8.onnx ONNX Runtime, static INT8 (CPU) 59.9 0.852 0.971 0.946 CPU – 234.3 / 137.1

Khoroos's auto format uses fp16 on a GPU and onnx-int8 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 INT8 is clearly the fastest CPU format.

Preprocessing

As in D-FINE's training:

  1. Resize the frame to 640Γ—640 without keeping its aspect ratio, bilinearly with antialiasing.
  2. 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-l
khoroos analyze farm.mp4 --detector-model dfine-l --detector-format onnx-int8 --device cpu
from khoroos import analyze_video

result = analyze_video("farm.mp4", detector_model="dfine-l")

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_l").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.65
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_l_custom.yml) on one NVIDIA GB10 (8.8 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.940 at epoch 72.

The checkpoint was converted to Transformers' DFineForObjectDetection and checked against D-FINE's own network in float64 on test images (largest differences: logits 1.2e-04, boxes 3.8e-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.490).
  • 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
28
Safetensors
Model size
31.2M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support