khoroos_action_videomae_small
VideoMAE Small fine-tuned to classify the behavior of an individual chicken in a short video clip. It is one of the action models trained for Khoroos, a toolkit for analyzing chicken behavior in farm video.
- Base model:
MCG-NJU/videomae-small-finetuned-kinetics(revision1bf2b82), VideoMAE pretrained with masked autoencoding and fine-tuned on Kinetics-400. - Fine-tuning data: the ChickenAct dataset, 15,250 single-bird clips covering 15 behaviors on 5 farms.
- Input: 16 RGB frames at 224×224 pixels.
- Output: probabilities for the 15 behaviors below.
Results
Unseen farms (leave one farm out)
Each row is a separate model trained with one farm held out entirely and tested on that farm. This is the best estimate of performance on a farm the model has never seen. These checkpoints are not this export; this export is trained on all five farms. Farm IDs are those of the ChickenVerse paper (the released clip file names use different prefixes). F01 and F05 are research pens, F02 a commercial-scale research house, F03 a commercial broiler breeder farm and F04 a commercial broiler house. Macro-F1 averages the behaviors present on the held-out farm (F02 has no feeding clips). Pooled scores all held-out clips together.
| Held-out farm | Macro-F1 | Accuracy | Balanced accuracy |
|---|---|---|---|
| F01 | 0.679 | 0.756 | 0.698 |
| F02 | 0.623 | 0.718 | 0.657 |
| F03 | 0.510 | 0.605 | 0.590 |
| F04 | 0.630 | 0.704 | 0.664 |
| F05 | 0.636 | 0.726 | 0.711 |
| Mean ± SD | 0.616 ± 0.063 | 0.702 | |
| Pooled | 0.664 | 0.703 |
All-farm test set
This model was trained on about 80% of the clips from all five farms, selected on a 10% validation split (best validation macro-F1 0.867 at epoch 13), and tested on the remaining 10% (1529 clips).
| Accuracy | Macro-F1 | Balanced accuracy | Weighted F1 |
|---|---|---|---|
| 0.899 | 0.864 | 0.862 | 0.898 |
| Behavior | Precision | Recall | F1 | Test clips |
|---|---|---|---|---|
body_shaking | 0.857 | 0.857 | 0.857 | 35 |
drinking | 0.911 | 0.898 | 0.904 | 137 |
dust_bathing | 0.944 | 0.944 | 0.944 | 54 |
feeding | 0.941 | 0.984 | 0.962 | 193 |
head_scratching | 0.854 | 0.820 | 0.837 | 50 |
litter_pecking | 0.833 | 0.756 | 0.793 | 86 |
litter_scratching | 0.869 | 0.898 | 0.883 | 59 |
pooping | 0.682 | 0.556 | 0.612 | 27 |
preening | 0.952 | 0.932 | 0.942 | 192 |
resting | 0.942 | 0.946 | 0.944 | 242 |
running | 0.877 | 0.794 | 0.833 | 63 |
standing | 0.753 | 0.727 | 0.740 | 88 |
stretching | 0.920 | 0.958 | 0.939 | 120 |
walking | 0.881 | 0.927 | 0.903 | 151 |
wing_flapping | 0.811 | 0.938 | 0.870 | 32 |
These scores may be slightly optimistic: the dataset contains some near-duplicate clips that were not removed before splitting. Use the unseen-farm scores to judge deployment on a new farm.
Available formats
Every format was evaluated on the same 1,529-clip all-farm test set. Agreement is the share of clips whose predicted behavior matches the FP32 PyTorch model. Times are model-only on an NVIDIA GB10 (DGX Spark; GPU, and its 20-core Arm CPU), excluding video decoding and preprocessing.
| File | Format | Size (MB) | Macro-F1 | Accuracy | Agreement | GPU ms/clip (batch 1) | CPU ms/clip (batch 1) |
|---|---|---|---|---|---|---|---|
model.safetensors | FP32 weights, FP32 compute (TF32 disabled) | 88 | 0.865 | 0.901 | 100.0% | 18 | – |
model.safetensors | FP32 weights, BF16 autocast (Khoroos default) | 88 | 0.865 | 0.901 | 99.9% | 6.7 | – |
model.fp16.safetensors | FP16 weights and compute | 44 | 0.865 | 0.901 | 100.0% | 6.0 | – |
onnx/model.onnx | ONNX FP32 | 92 | 0.865 | 0.901 | 100.0% | 61 | 378 |
onnx/model_fp16.onnx | ONNX FP16 weights and compute, FP32 inputs/outputs | 47 | 0.865 | 0.901 | 100.0% | 24 | 798 |
onnx/model_int8.onnx | ONNX dynamic INT8 quantization (per-channel weights, MatMul) | 25 | 0.868 | 0.901 | 98.7% | 161 | 290 |
onnx/model_q4.onnx | ONNX 4-bit weight-only quantization (MatMulNBits, block 32, symmetric) | 20 | 0.854 | 0.890 | 96.4% | 61 | 380 |
Download only the files you need, for example:
hf download amirivojdan/khoroos_action_videomae_small config.json video_preprocessor_config.json onnx/model_int8.onnx
PyTorch FP16 on a GPU:
model = AutoModelForVideoClassification.from_pretrained(
repo_id, variant="fp16", dtype=torch.float16
).to("cuda").eval()
inputs = processor([sample(video)], return_tensors="pt").to("cuda", torch.float16)
ONNX Runtime; the graph takes preprocessed pixel_values shaped
(batch, 16, 3, 224, 224):
import onnxruntime as ort
from huggingface_hub import hf_hub_download
session = ort.InferenceSession(hf_hub_download(repo_id, "onnx/model_int8.onnx"))
pixel_values = processor([sample(video)], return_tensors="pt")["pixel_values"].numpy()
logits = session.run(None, {"pixel_values": pixel_values})[0]
Which file to use: on a GPU, model.fp16.safetensors with PyTorch is the fastest and
matches FP32 accuracy; with ONNX Runtime, use onnx/model_fp16.onnx. On a CPU, use
onnx/model_int8.onnx, or onnx/model_q4.onnx for the smallest download. The INT8
and 4-bit files are slow on GPUs, and the FP16 ONNX file is slow on CPUs.
Classes in output order
body_shakingdrinkingdust_bathingfeedinghead_scratchinglitter_peckinglitter_scratchingpoopingpreeningrestingrunningstandingstretchingwalkingwing_flapping
Preprocessing
Inference must match training:
- Sample 16 frame indices uniformly across the clip, rounding
numpy.linspace(0, n - 1, 16). If the clip has fewer than 16 frames, use every frame and repeat the last one. - Resize the shorter side to 256 pixels, center-crop 224×224, scale to [0, 1] and normalize with ImageNet mean and standard deviation. The saved video processor does this step.
Usage
import numpy as np
import torch
from transformers import AutoModelForVideoClassification, AutoVideoProcessor
repo_id = "amirivojdan/khoroos_action_videomae_small"
processor = AutoVideoProcessor.from_pretrained(repo_id)
model = AutoModelForVideoClassification.from_pretrained(repo_id).eval()
def sample(video, num_frames=model.config.frames_per_clip):
# video: uint8 tensor of shape (T, C, H, W)
t = video.shape[0]
if t >= num_frames:
idx = np.round(np.linspace(0, t - 1, num_frames)).astype(int)
else:
idx = np.concatenate([np.arange(t), np.full(num_frames - t, t - 1)])
return video[torch.as_tensor(idx)]
inputs = processor([sample(video)], return_tensors="pt")
with torch.inference_mode():
probs = model(**inputs).logits.softmax(-1)[0]
print(model.config.id2label[int(probs.argmax())])
In Khoroos, select this model with --action-model videomae-small or
KHOROOS_ACTION_MODEL=videomae-small; --action-format chooses the weight format. Khoroos
downloads only that format and handles frame sampling and preprocessing.
Training
Full fine-tuning in BF16 on one NVIDIA GB10: AdamW, backbone learning rate 3e-05 (classifier ×10), weight decay 0.05, effective batch size 32, 15 epochs with 3 warmup epochs and cosine decay, gradient clipping at 1, seed 42. Augmentation: temporal jitter around the inference frame positions, random scale (about ±12.5%), random crop, horizontal flip and color jitter, applied identically across frames. No class weighting. The checkpoint with the best validation macro-F1 was kept. Data: 12,192 training, 1,529 validation and 1,529 test clips, stratified by farm and behavior. Activation checkpointing at 2 clips per step (16 accumulation steps); peak GPU memory 0.5 GiB. This fit took 2.0 h; the six fits of this size (all farms and five leave-one-farm-out) averaged 1.8 h.
Limitations
- Trained on single-bird clips from five farms. Accuracy drops on farms not seen in training, by about 25 macro-F1 points on average in the leave-one-farm-out results.
- Results come from one training seed.
- Predictions describe behavior only. They are not welfare assessments.
License
Released under CC BY-NC-SA 4.0. The base VideoMAE checkpoint is CC BY-NC 4.0 and 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{tong2022videomae,
title = {VideoMAE: Masked Autoencoders are Data-Efficient Learners for
Self-Supervised Video Pre-Training},
author = {Tong, Zhan and Song, Yibing and Wang, Jue and Wang, Limin},
booktitle = {Advances in Neural Information Processing Systems},
year = {2022}
}