Parameter-efficient fine-tuning of a billion-parameter vision model improves dairy cattle behavior classification under a 1:98 train-to-test ratio
Why · How · Results · Implications · Models · Data · Repository · Reproduce · Citation
Specialized image-recognition tasks rarely come with large labeled datasets. Should you train a compact model of your own from scratch, or reuse a large pre-trained foundation model, either frozen or adapted with parameter-efficient fine-tuning (PEFT)? We compared these routes on one task with few labels and a very large test set: classifying nine dairy cattle behaviors from 2,160 expert-verified images, then testing on 211,800 images, 98 times the training set, all on one 16 GB GPU.
Adapting the 6.7-billion-parameter DINOv3 with QLoRA reached 83.2% test accuracy, against 76.6% for the same model frozen and 72.9% for the best network trained from scratch. It trained in 5 h 46 min, about a third of the baselines’ time, with new parameters equal to 2.7% of the backbone’s size.
Haiyu Yang, Sumit Sharma, Enhong Liu and Miel Hostens · Department of Animal Science, Cornell University
Cameras can watch every animal on a farm, and deep learning can recognize behavior in images. The bottleneck is labels: fine-grained behaviors differ by subtle posture, the images are often occluded, low in resolution and unevenly lit, and expert annotation is slow, so labeled datasets stay small.
Vision foundation models such as DINOv3 learn general-purpose features from billions of unlabeled images. Updating all 6.7 billion of its weights, however, needs far more memory than one graphics card has and can overfit a few thousand labels. The two cheaper options are to keep the model frozen and train only a classifier on its features, or to use PEFT, which inserts a small number of trainable parameters into the frozen network. How these routes compare when labels are scarce is poorly documented at this scale, so we asked:

Data. Each image is a crop of one animal from a video frame, labeled with that animal’s behavior at that time: six behaviors of lactating Holstein cows from the public MmCows dataset and three play behaviors of group-housed calves from PlayBehavior, whose recordings of two of the four farms are public as the Calf Play Behavior Dataset. Two annotators with veterinary training verified 300 crops per behavior (240 for training, 60 for validation). Every other labeled crop, 211,800 in all, formed the test set; its labels are the source annotations, not verified by eye.
Three routes, eleven models, one protocol. Every model used the same images, early stopping on the same validation set and one Tesla V100 16 GB GPU.
| Route | Models | Trained parameters |
|---|---|---|
| 1. Self-customized networks, trained from scratch | ResNet-18, ViT-Small | 11.3 M, 21.8 M (all weights) |
| 2. Foundation model, frozen | DINOv3 ViT-7B/16 (16-bit) + three-layer classifier | 4.7 M (0.07% of the backbone’s size) |
| 3. Foundation model + PEFT | DINOv3 compressed to 4 bits + QLoRA or DoRA adapters, rank 8, 16 or 64, on the query projections (q_proj) or on all seven linear layers of each block (all-linear), + the same classifier |
7.3–184.5 M (0.11–2.75%) |
Evaluation. All 211,800 test images: accuracy with 95% confidence intervals, macro-F1, per-behavior precision and recall, training and inference time. Two annotators then reviewed 200 test images on which the best model disagreed with the label.
q_proj, r = 8; −0.02 at all-linear, r = 64) and took 1.2–2.5 times as long per epoch.
| Model | Trained parameters | Training time | Validation (%) | Test (%) | Macro-F1 |
|---|---|---|---|---|---|
| ResNet-18 (from scratch) | 11.3 M | 16 h 45 min | 80.93 | 72.87 | 0.539 |
| ViT-Small (from scratch) | 21.8 M | 18 h 39 min | 73.70 | 61.91 | 0.506 |
| DINOv3, frozen | 4.7 M | 17 h 27 min | 86.30 | 76.56 | 0.599 |
| QLoRA, q_proj, r = 8 | 7.3 M | 6 h 32 min | 90.56 | 77.17 | 0.579 |
| QLoRA, q_proj, r = 16 | 10.0 M | 7 h 16 min | 90.74 | 78.38 | 0.605 |
| QLoRA, all-linear, r = 16 | 49.3 M | 4 h 43 min | 90.37 | 80.40 | 0.637 |
| QLoRA, all-linear, r = 64 | 183.0 M | 5 h 46 min | 91.30 | 83.16 | 0.662 |
| DoRA, q_proj, r = 8 | 7.5 M | 11 h 31 min | 90.19 | 81.53 | 0.639 |
| DoRA, q_proj, r = 16 | 10.1 M | 10 h 27 min | 91.67 | 81.03 | 0.634 |
| DoRA, all-linear, r = 16 | 50.8 M | 11 h 51 min | 90.56 | 81.23 | 0.637 |
| DoRA, all-linear, r = 64 | 184.5 M | 10 h 59 min | 92.04 | 83.14 | 0.670 |
Test: 211,800 images (95% confidence intervals at most ±0.21 points; each model was trained once, so differences below about 2 points are indicative only). Validation: 540 images, for the weights that were tested; the three baselines were tested at their last epoch. All numbers are recomputed from the released confusion matrices by analysis/compute_metrics.py.


Lying (F1 0.99) and standing (0.82) were easy; walking (0.26) was hardest, because 8.6% of standing images were predicted as walking and 40.1% of walking images as standing. Both eating behaviors lost about a quarter of their images to standing.
Limits. Each configuration was trained once. The test images come from the same pens, cameras and recording periods as the training images, so the results describe in-domain performance at scale, not transfer to new farms. Each behavior comes from one source. Compact pre-trained networks, smaller DINOv3 models and unquantized LoRA were not evaluated. Classification was per image, although walking and play are defined by motion.
The study does not propose a new algorithm; its contribution is evidence about approaches. The project page shows all results as interactive charts.
| Model | Contents | Hugging Face |
|---|---|---|
| QLoRA, all-linear, r = 64 | adapters and classifier of the best model | Sonam5/cow-behavior-dinov3-qlora-r64 |
| DoRA, all-linear, r = 64 | adapters and classifier | Sonam5/cow-behavior-dinov3-dora-r64 |
| DINOv3, frozen | classifier on the frozen backbone | Sonam5/cow-behavior-dinov3-Frozen |
| ResNet-18, ViT-Small | networks trained from scratch | Sonam5/cow-behavior-from-scratch |
The adapters need the gated facebook/dinov3-vit7b16-pretrain-lvd1689m backbone, downloaded under its own licence. They expect 224 × 224 RGB images with pixel values in [0, 1] (no ImageNet normalization); each model card has a working inference example.
| Source | Behaviors | Access |
|---|---|---|
| MmCows (Vu et al., NeurIPS 2024 Datasets and Benchmarks) | drinking, eating head down, eating head up, lying, standing, walking | public, CC BY-NC-SA 4.0 |
| Calf Play Behavior Dataset, version 1.2 (doi:10.57967/hf/11689; dataset paper arXiv:2611.21706) | frontal pushing, gallop, leap: 2,528 of the 2,819 calf images | public, CC0 1.0 |
| PlayBehavior (Yang et al., arXiv:2602.00111), two further farms | 291 calf images | on reasonable request |
data/splits lists all 214,500 images with their split and label. MmCows rows keep the public identifiers (cow, camera, Unix time); public calf rows give the session, frame, shard and calf in the Calf Play Behavior Dataset, so every image can be traced to its source frame. See data/README.md.
| Path | What it holds |
|---|---|
data/ |
split files for training, validation and test, with column definitions and sources |
notebooks/ |
training and evaluation of all eleven models, as run (Databricks); see the table below |
notebooks/corrected_testing/ |
stand-alone notebooks that re-evaluate the adapted models (see Notes) |
results/original_evaluation/ |
confusion matrices, per-image test predictions and the run summary behind the paper |
results/training_curves/ |
validation accuracy and training loss per epoch for every run |
results/preprocessing_check/ |
re-evaluation of two adapted models on 2,000 test images |
analysis/compute_metrics.py |
recomputes every reported metric from the confusion matrices |
figures/ |
figures of this README and the script that draws the banner |
docs/ |
the project page (build_data.py regenerates its numbers from results/) |
| Notebook | Models |
|---|---|
TrainFromScatch_Preprocesing Pipeline Val = 1.ipynb |
ResNet-18 and ViT-Small, trained from scratch |
UsingPretrainedModel_DinoV3 Embeddings Val = 1.ipynb |
DINOv3, frozen, with a trained classifier |
Q-lora Fewer Layers R = 8.ipynb, … R = 16.ipynb |
QLoRA, q_proj, r = 8 and 16 |
Q-lora More Layers Rank = 16.ipynb, … Rank = 64.ipynb |
QLoRA, all-linear, r = 16 and 64 |
DoRA Fewer Layers R=8.ipynb, … R=16.ipynb |
DoRA, q_proj, r = 8 and 16 |
DoRA More Layers R=16.ipynb, … R=64.ipynb |
DoRA, all-linear, r = 16 and 64 |
requirements.txt or environment.yml. The paper’s runs used Databricks GPU runtimes with PyTorch 2.3.1 or 2.6.0, Transformers 4.57.1, PEFT 0.13.2 and bitsandbytes 0.48.0 on one Tesla V100-PCIE-16GB.notebooks/: Module 0 builds the splits, Modules 5–10 train, Module 11 evaluates. Every run uses the random seed 42.python analysis/compute_metrics.py results/original_evaluation/confusion_matrices.json prints accuracy with Wilson 95% intervals, weighted and macro-F1, balanced accuracy, per-class precision, recall and F1, and per-source accuracy.python docs/build_data.py regenerates the numbers of the project page from results/.Test-time preprocessing. During training and validation, the DINOv3 model wrapper converted the ImageNet-normalized input back to pixel values in [0, 1] before the backbone. The original test cells (Module 11) of the eight QLoRA/DoRA notebooks passed the normalized tensor directly; the DoRA cells also ran without fp16 autocast, and the two QLoRA q_proj notebooks merged the adapters into the 4-bit weights before testing. The frozen and from-scratch baselines were evaluated consistently. Two configurations re-evaluated with the training-time preprocessing on 2,000 random test images changed 2.8% and 4.0% of their predictions and their accuracy by +0.35 and +0.10 points (results/preprocessing_check); the other six were not re-evaluated. The results reported in the paper and in results/original_evaluation are those of the original evaluation. The evaluation cells in notebooks/ have been corrected (changed lines are marked FIX; the stored outputs are from the original run), and notebooks/corrected_testing evaluates the test set either way (preprocessing = corrected or legacy).
Baseline checkpoints. The three baselines were tested with their last-epoch weights rather than their best-validation weights (a shallow state_dict().copy() in their training loop), 1.3–2.2 points below their best validation accuracy. This is stated in the paper.
| Item | Terms |
|---|---|
| Code in this repository | MIT, see LICENSE |
Files in data/ and results/ that describe MmCows images |
CC BY-NC-SA 4.0, derived from MmCows; please also cite MmCows |
| Calf Play Behavior Dataset | CC0 1.0 |
| Released weights | MIT; they need the DINOv3 backbone under the DINOv3 License |
@article{yang2026peftcows,
title = {Parameter-efficient fine-tuning of a billion-parameter vision model improves dairy cattle behavior classification under a 1:98 train-to-test ratio},
author = {Yang, Haiyu and Sharma, Sumit and Liu, Enhong and Hostens, Miel},
journal = {arXiv preprint arXiv:2603.17782},
year = {2026}
}
If you use the calf images, please also cite the dataset (doi:10.57967/hf/11689) and its dataset paper (arXiv:2611.21706).