khoroos_detector_yolox_m
YOLOX-M 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: YOLOX-M (depth 0.67, width 0.75), 25.3 M parameters, 73 GFLOPs at 640×640.
- Initialization: the official COCO-pretrained YOLOX-M weights.
- 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, scaled to fit 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 and NMS IoU 0.65:
| AP | AP50 | AP75 | AP small | AP medium | AP large | AR100 |
|---|---|---|---|---|---|---|
| 0.802 | 0.967 | 0.889 | 0.422 | 0.806 | 0.915 | 0.839 |
Khoroos runs this detector at confidence 0.7 by default (default_confidence
in config.json), with NMS IoU 0.6. There, counting a detection as correct at
IoU ≥ 0.5, precision is 0.941, recall
0.942 and F1 0.941.
YOLOX's score (objectness × class probability) runs low. At a generic threshold of
0.3 it keeps many marginal boxes (precision
0.859, recall 0.970),
which become spurious tracks. 0.7 was chosen on the Validation split, where every
YOLOX size reaches its best F1 between 0.7 and 0.8; on this test house F1 peaks at
0.71 (F1 0.942). Lower it with
--detection-confidence when missing a bird matters more than an occasional false box.
Best validation AP (research pens) was 0.913, at epoch 80. Results come from one training seed.
Weight formats
Only the format you select is downloaded. Accuracy is measured on the test set in the
device column. Speed is the whole Khoroos detect call per 1280×720 frame (scaling,
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 | Measured on | GPU ms | CPU ms |
|---|---|---|---|---|---|---|---|---|
fp32 |
model.safetensors |
PyTorch, FP32 | 101.4 | 0.802 | 0.967 | CUDA | 9.1 / 12.7 | 639.6 / 168.9 |
fp16 |
model.fp16.safetensors |
PyTorch, FP16 (GPU) | 50.7 | 0.802 | 0.967 | CUDA | 4.7 / 5.8 | – |
onnx-fp32 |
onnx/model.onnx |
ONNX Runtime, FP32 | 102.0 | 0.802 | 0.967 | CUDA | 16.2 / 12.5 | 252.3 / 146.6 |
onnx-fp16 |
onnx/model_fp16.onnx |
ONNX Runtime, FP16 (GPU) | 51.4 | 0.802 | 0.967 | CUDA | 12.8 / 8.0 | – |
onnx-int8 |
onnx/model_int8.onnx |
ONNX Runtime, static INT8 (CPU) | 26.0 | 0.799 | 0.967 | CPU | – | 157.3 / 83.1 |
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. The prediction convolutions and box decoding stay in floating point. There is no 4-bit model: 4-bit weight-only quantization applies to matrix multiplications, and YOLOX is a convolutional network.
Preprocessing
YOLOX was trained on images read with OpenCV, so inference must:
- Scale the frame by
r = min(640 / height, 640 / width)toint(width·r) × int(height·r)with bilinear interpolation (half-pixel centres, ascv2.INTER_LINEAR). - Paste it at the top-left of a 640×640 canvas filled with 114.
- Convert RGB to BGR and pass values in [0, 255] as float, without normalization.
The model returns (batch, 8400, 6): box centre x, centre y, width and height in input
pixels, objectness, and class probability. The score is objectness × class probability.
Divide boxes by r to return to frame pixels, then apply NMS.
Usage
In Khoroos:
khoroos analyze farm.mp4 --detector-model yolox-m
khoroos analyze farm.mp4 --detector-model yolox-m --detector-format onnx-int8 --device cpu
from khoroos import analyze_video
result = analyze_video("farm.mp4", detector_model="yolox-m")
The ONNX models run with ONNX Runtime alone:
import cv2, numpy as np, onnxruntime as ort
from huggingface_hub import hf_hub_download
path = hf_hub_download("amirivojdan/khoroos_detector_yolox_m", "onnx/model.onnx")
session = ort.InferenceSession(path)
frame = cv2.imread("frame.jpg") # BGR
r = min(640 / frame.shape[0], 640 / frame.shape[1])
resized = cv2.resize(frame, (int(frame.shape[1] * r), int(frame.shape[0] * r)))
canvas = np.full((640, 640, 3), 114, np.uint8)
canvas[: resized.shape[0], : resized.shape[1]] = resized
x = canvas.transpose(2, 0, 1)[None].astype(np.float32)
out = session.run(None, {"images": x})[0][0]
scores = out[:, 4] * out[:, 5]
keep = scores > 0.3
cx, cy, w, h = (out[keep, :4] / r).T
boxes = np.stack([cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2], axis=1)
# then non-maximum suppression, for example cv2.dnn.NMSBoxes
model.safetensors uses the upstream YOLOX parameter names, so it also loads into
yolox.exp.get_exp("yolox_m") models with num_classes = 1.
Training
Fine-tuned from the COCO-pretrained weights with the official YOLOX trainer (commit
6ddff48) and its default recipe on one NVIDIA GB10, in
3.2 h:
- 80 epochs at batch size 16, mixed precision, seed 42.
- SGD with momentum 0.9 (Nesterov) and weight decay 5e-4; learning rate 0.0025 (16 images × 0.01/64), 3 warm-up epochs, then cosine decay to 5% of it; exponential moving average of the weights.
- Augmentation: mosaic and mixup, random rotation (±10°), translation (±10%), shear (±2°), scaling (0.1–2× in mosaic), HSV color changes and horizontal flips; multi-scale training at 480–800 px. Mosaic and mixup were switched off for the final 10 epochs.
- Up to 500 boxes per image (YOLOX's default of 50, 120 after mosaic, would
drop birds in dense images). The ChickenDet annotation files with
iscrowdreset to 0 were used; the original files mark every box as a crowd region, which the loader and the COCO evaluator would ignore. - Validation AP was measured every 5 epochs and the best checkpoint kept: 0.913 at epoch 80.
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.422).
- 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 YOLOX code and COCO-pretrained 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
@article{ge2021yolox,
title = {YOLOX: Exceeding YOLO Series in 2021},
author = {Ge, Zheng and Liu, Songtao and Wang, Feng and Li, Zeming and Sun, Jian},
journal = {arXiv preprint arXiv:2107.08430},
year = {2021}
}
- Downloads last month
- 8