ResNet-18 and ViT-Small trained from scratch for dairy cattle behavior classification (baselines)

The two from-scratch baselines of Parameter-efficient fine-tuning of a billion-parameter vision model improves dairy cattle behavior classification under a 1:98 train-to-test ratio (arXiv:2603.17782), trained from random initialization on the same 2,160 verified crops as the adapted DINOv3 models. Code and data: PEFT-Fine-tuning-cows; all models: PEFT4COWS collection.

Files

  • resnet18_1xval.pth β€” state dict of ResNet18FromScratch: torchvision ResNet-18 with fc = Identity (backbone) and a head classifier = Dropout 0.5, Linear 512β†’256, ReLU, Dropout 0.25, Linear 256β†’9.
  • vit_small_1xval.pth β€” dictionary with model_state_dict of ViTSmallFromScratch: timm vit_small_patch16_224 with num_classes=0 (backbone) and a head classifier = LayerNorm 384, Dropout 0.5, Linear 384β†’384, GELU, Dropout 0.25, Linear 384β†’9; plus training history and config.
  • labels.json β€” class index β†’ behavior.

Inputs: 224 Γ— 224 RGB crops normalized with the ImageNet mean and standard deviation (unlike the DINOv3-based models, these networks were trained on normalized inputs).

import torch, torch.nn as nn, timm
from torchvision import models

class ResNet18FromScratch(nn.Module):
    def __init__(self):
        super().__init__()
        self.backbone = models.resnet18(weights=None); self.backbone.fc = nn.Identity()
        self.classifier = nn.Sequential(nn.Dropout(0.5), nn.Linear(512, 256), nn.ReLU(), nn.Dropout(0.25), nn.Linear(256, 9))
    def forward(self, x): return self.classifier(self.backbone(x))

class ViTSmallFromScratch(nn.Module):
    def __init__(self):
        super().__init__()
        self.backbone = timm.create_model("vit_small_patch16_224", pretrained=False, num_classes=0, img_size=224)
        self.classifier = nn.Sequential(nn.LayerNorm(384), nn.Dropout(0.5), nn.Linear(384, 384), nn.GELU(), nn.Dropout(0.25), nn.Linear(384, 9))
    def forward(self, x): return self.classifier(self.backbone(x))

resnet = ResNet18FromScratch(); resnet.load_state_dict(torch.load("resnet18_1xval.pth", map_location="cpu")); resnet.eval()
vit = ViTSmallFromScratch(); vit.load_state_dict(torch.load("vit_small_1xval.pth", map_location="cpu", weights_only=False)["model_state_dict"]); vit.eval()

Training data

Nine behaviors from two sources: six behaviors of lactating Holstein cows from MmCows (one free-stall pen, four synchronized cameras, per-cow labels each second) and three play behaviors of group-housed calves from PlayBehavior (four Dutch dairy farms; video, frames, annotations and calf tracks of the two farms that supplied 2,528 of the 2,819 calf crops are public under CC0: Calf-Play-Behavior-Dataset). For each behavior, 300 crops of single animals were verified by two annotators with veterinary training and split 240/60 into training and validation (2,160 / 540 crops). All other labeled crops of the two sources, 211,800 in total (98 times the training set), form the test set; their labels are the source annotations and were not visually verified. The split files are in data/splits.

Index Behavior Label in source dataset Source
0 Drinking Drinking MmCows (lactating cows)
1 Eating head down Feeding head down MmCows (lactating cows)
2 Eating head up Feeding head up MmCows (lactating cows)
3 Lying Lying MmCows (lactating cows)
4 Standing Standing MmCows (lactating cows)
5 Walking Walking MmCows (lactating cows)
6 Frontal pushing frontal_pushing PlayBehavior (calves)
7 Gallop gallop PlayBehavior (calves)
8 Leap leap PlayBehavior (calves)

Evaluation

Test set of 211,800 crops. Because of a checkpoint-copying error in the training loop, both released networks are those of the last epoch (ResNet-18: epoch 59, validation 80.93%, best 82.59% at epoch 44; ViT-Small: epoch 64, validation 73.70%, best 75.00% at epoch 54).

Model Test accuracy (%) Macro-F1 Balanced accuracy MmCows accuracy (%) PlayBehavior accuracy (%)
ResNet-18 72.87 0.539 0.607 72.98 60.87
ViT-Small 61.91 0.506 0.561 61.93 60.55

Licence

MIT. The models were trained partly on MmCows, which is released for non-commercial use (CC BY-NC-SA 4.0).

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}
}
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Datasets used to train Sonam5/cow-behavior-from-scratch

Collection including Sonam5/cow-behavior-from-scratch

Paper for Sonam5/cow-behavior-from-scratch