PEFT for cattle behavior

Preprint · arXiv:2603.17782

Adapting a billion-parameter vision model with few labels

Parameter-efficient fine-tuning of a billion-parameter vision model improves dairy cattle behavior classification under a 1:98 train-to-test ratio

Haiyu Yang, Sumit Sharma, Enhong Liu and Miel Hostens · Department of Animal Science, Cornell University

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.

83.2%
test accuracy of the best adapted model (QLoRA, all-linear, r = 64)
76.6%
the same foundation model, frozen, with a trained classifier
72.9%
the best network trained from scratch (ResNet-18)
5 h 46 min
to train the best adapted model on one 16 GB GPU, about a third of the baselines' time

Why we did this study

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 offer a way around this. DINOv3, with 6.7 billion parameters, learned general-purpose visual features from 1.7 billion unlabeled images. But updating all of its weights needs far more memory than a single 16 GB graphics card has, and can overfit a few thousand labels. The usual alternatives are to keep the model frozen and train only a classifier on its features, or to use parameter-efficient fine-tuning, which inserts a small number of trainable parameters into the frozen network. QLoRA, for example, compresses the frozen weights to 4 bits and trains small low-rank adapters, so a billion-parameter model fits on one card.

How these routes compare when labels are scarce, and how much adapter capacity to give, is poorly documented at this scale. Most vision benchmarks also test on small held-out splits from the same curated pool, which hides class imbalance and label errors. We asked:

  1. How much does a billion-parameter model gain from parameter-efficient adaptation, compared with networks trained from scratch on the same images and with the same model kept frozen?
  2. How do the size and placement of the adapters affect accuracy and training cost?
  3. What limits the accuracy that can be measured when the test set is large and its labels unverified?
Each square stands for 2,160 images. The models never saw the test images during training or model selection; 540 further verified images (60 per behavior) were used for validation.

How we did it

Eleven models, three routes, one protocol: the same 2,160 training images, the same 540 validation images for early stopping, the same 211,800 test images and one Tesla V100 16 GB GPU.

The 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 come from the public MmCows dataset; three play behaviors of group-housed calves come 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 against written criteria, deliberately keeping difficult examples (occlusion, unusual viewpoints, blur). The test labels are the source annotations, not verified by eye, and the test set is strongly imbalanced: lying and standing make up 72.4% of it, the three calf behaviors 0.9%.

Images per behavior

Three routes to a classifier

Route 1

Self-customized networks, trained from scratch

Compact networks whose every weight is learned from the 2,160 training images.

  • ResNet-18 (11.3 million parameters)
  • ViT-Small (21.8 million parameters)

No pre-training · all weights trained

Route 2

Foundation model, frozen

DINOv3 ViT-7B/16 kept unchanged; only a three-layer classifier is trained on its 4,096-dimensional features.

  • Backbone in 16-bit precision, frozen
  • Classifier: 4.7 million parameters

0.07% of the backbone's size trained

Route 3

Foundation model + parameter-efficient fine-tuning

DINOv3 compressed to 4 bits and adapted with small low-rank adapters, trained together with the same classifier.

  • QLoRA, or its weight-decomposed variant DoRA
  • Rank 8, 16 or 64; adapters on the query projections or on all linear layers

Eight configurations · 0.11–2.75% of the backbone's size trained

Where the adapters go

Each of DINOv3's 40 transformer blocks has seven linear layers: four in the attention and three in the gated feed-forward network. The two placements differ in how many of them carry an adapter.

Placement
Attentionq_projk_projv_projo_proj
Feed-forwardgate_projup_projdown_proj

How we evaluated

Every model trained with early stopping on validation accuracy and was scored on all 211,800 test images: accuracy with 95% confidence intervals, macro-F1 (the unweighted mean of the per-behavior F1 scores), per-behavior precision and recall, and training and inference time. Each configuration was trained once with the same random seed. Finally, two annotators reviewed 200 test images on which the best model disagreed with the label, to see whether the model or the label was at fault.

What we found

Adapting the foundation model beat both alternatives

Test and validation accuracy of the eleven models

Table view
All eight adapted configurations scored above the frozen model (by 0.6 to 6.6 percentage points), and the frozen model scored above both networks trained from scratch. Filled circles: test accuracy (211,800 images); open circles: validation accuracy (540 images) of the weights that were tested. The 95% confidence intervals are at most ±0.21 points, narrower than the markers, but they treat images as independent and each model was trained once, so differences below about 2 points are indicative only. The three baselines were tested with their last-epoch weights, 1.3 to 2.2 points below their best validation accuracy.

…and was the cheapest to train

Test accuracy against end-to-end training time

Table view
The all-linear QLoRA runs stopped earliest (after 10 and 12 epochs) and trained in 4 h 43 min and 5 h 46 min, forming the frontier of training time against accuracy (line). DoRA took 10 h 27 min to 11 h 51 min, the frozen model 17 h 27 min (its features were recomputed for every augmented image) and the networks trained from scratch 16 h 45 min to 18 h 39 min. At inference the order reverses: the small networks classified 13–14 images per second, the DINOv3-based models 6–7, and the all-linear DoRA models about 3.

More adapter capacity, higher accuracy

Test accuracy by adapter configuration

Table view
Configurations ordered by the number of adapter parameters (QLoRA values shown). With QLoRA, accuracy rose from 77.2% to 83.2% as capacity grew, and both ways of adding capacity helped: moving the adapters from the query projections to all linear layers, and raising the rank. Validation accuracy barely moved, so the gap between validation and test accuracy narrowed from 13.4 to 8.1 points, the opposite of overfitting. DoRA's advantage over QLoRA was largest for the smallest adapters (+4.4 points) and vanished for the largest (−0.02), while it took 1.2–2.5 times as long per epoch.

Where the errors are

Confusion matrix, as percentages of each annotated behavior

Table view (counts)
Rows: annotated behavior; columns: predicted behavior; darker cells hold a larger share of the row. For the best model, 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, two postures that differ only in the phase of a stride. Both eating behaviors lost about a quarter of their images to standing. Hover a cell for counts.

F1 score per behavior

Table view
Relative to the frozen model, adaptation raised the F1 score of the two eating behaviors most (0.44 to 0.68 and 0.53 to 0.66), then walking and standing; drinking barely changed. Accuracy is dominated by lying and standing, so the class-averaged macro-F1 (0.66 for the best model) sits well below the accuracy (83.2%).

Most remaining disagreements were label problems

200 test images where the best model disagreed with the label, reviewed by two annotators

Only 16 were genuine model errors. In 64 the label contradicted what the image shows, for example a cow with its muzzle in the water trough labeled standing; in 120 the behavior could not be determined from a single image, for example when only the hindquarters were visible. The images were sampled from the most frequently confused pairs of behaviors, and images on which model and label agreed were not reviewed, so the audit shows that label quality caps the accuracy that can be measured, not how often the model agreed with a wrong label.

What it means

The contribution is evidence about approaches, not a new algorithm: for a specialized task with scarce labels, how to use a very large pre-trained vision model on ordinary hardware.

Reuse and adapt, rather than train from scratch

Adapting a pre-trained foundation model with PEFT was more accurate than training a self-customized network on the same images and more accurate than using the foundation model frozen, on a single 16 GB graphics card.

Give the adapters room

Small adapters underfit the shift from web images to barn video. Adapters on all linear layers at a rank of several tens were the most accurate and, here, also the cheapest to train; capacity can be reduced if overfitting appears.

QLoRA first, DoRA when the adapter budget is tight

DoRA helped only the smallest adapters, took 1.2–2.5 times as long per epoch, and halved inference throughput with adapters on all linear layers. At rank 64, QLoRA matched it in about half the training time.

Test at deployment scale, and audit the labels

Scoring every labeled image exposed the class imbalance and failure modes that a small balanced split hides, and the audit showed that label quality, not model capacity, limited the accuracy that could be measured.

Limits. Each configuration was trained once, so differences below about 2 points are indicative only. 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, and 3–7 images per second suits batch analysis rather than real-time monitoring.

Models & data

Trained models

ModelContentsHugging Face
QLoRA, all-linear, r = 64adapters and classifier of the best modelcow-behavior-dinov3-qlora-r64
DoRA, all-linear, r = 64adapters and classifiercow-behavior-dinov3-dora-r64
DINOv3, frozenclassifier on the frozen backbonecow-behavior-dinov3-Frozen
ResNet-18, ViT-Smallnetworks trained from scratchcow-behavior-from-scratch

The adapters need the gated DINOv3 ViT-7B/16 backbone and expect 224 × 224 RGB images with pixel values in [0, 1]; each model card has a working inference example.

Data

SourceBehaviorsAccess
MmCows (Vu et al., NeurIPS 2024)drinking, eating head down, eating head up, lying, standing, walkingpublic, CC BY-NC-SA 4.0
Calf Play Behavior Dataset, version 1.2frontal pushing, gallop, leap (2,528 of 2,819 calf images)public, CC0 · doi:10.57967/hf/11689 · dataset paper
PlayBehavior, two further farms291 calf imageson reasonable request

The split files list every image with its split and label, and link each public calf image to its session, frame and calf in the public dataset. The repository also holds the confusion matrices, per-image test predictions and training curves of the models.

Citation

@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:

@misc{calfplay_dataset_2026,
  author    = {Yang, Haiyu and Lesscher, Heidi and Liu, Enhong and Hostens, Miel},
  title     = {Video recordings and play behaviour annotations of group-housed dairy calves on two Dutch farms},
  year      = {2026},
  publisher = {Hugging Face},
  version   = {1.2},
  doi       = {10.57967/hf/11689}
}