Multitask contrastive learning for individual dairy cow recognition across different behavior classes based on small image sets
The objectives of this study were to (1) evaluate the You Look Only Once (YOLOv7) algorithm for group-level behavior monitoring in freestall cows, (2) propose a multitask contrastive network (MTCN) for individual cow identification from limited reference data and compare its performance to a traditional convolutional neural network, and (3) dewvelop and validate a scalable 2-step computer vision framework integrating behavior detection and individual identification. Twenty-one Holstein cows housed in a single pen were monitored using ceiling-mounted red-green-blue cameras capturing images at 10-s intervals over 30 d. Behavior-labeled datasets (3,120 images) and cow-specific cropped images (1,059 images) were used to train the models, while a separate testing set (1,620 images, 8,490 annotations) was used to evaluate models' performance on unseen data. The MTCN classification performance was compared with a baseline model based on MobileNetV3 architecture. The 2 classification algorithms (YOLOv7 and MTCN) were combined to estimate the total time spent drinking (TTD), eating (TTE), resting (TTR), and standing (TTS) for each cow during 3 daily intervals: 0900 to 1000 h (morning), 1300 to 1400 h (afternoon), and 2000 to 2100 h (night). The YOLOv7 algorithm achieved high group-level classification performance, with global accuracy of 90.5% and Cohen's kappa of 0.859. Resting behavior had the highest metrics (balanced accuracy 99.1%, F1 99.1%), while eating showed the lowest balanced accuracy (88.3%). Individual identification using MTCN reached a global accuracy of 83.6% (Cohen's kappa 0.827), outperforming the baseline model, particularly for challenging resting and drinking postures. Correlations between predicted and observed values for TTD, TTE, TTR, and TTS ranged from 0.78 to 0.93, with mean absolute errors between 0.62 and 6.72 min. Prediction accuracy varied across day periods, with highest performance for TTE and TTD, and lower accuracy for TTR, particularly at night. These results demonstrate that the proposed computer vision framework can reliably classify group behaviors and identify individual cows under diverse postures, enabling continuous, automated monitoring of behavior traits in freestall dairy systems.
Authors
- Jacob M. Hooker (ORCID: https://orcid.org/0000-0002-9394-7708)
- Taisir Abdulhafed Abdulrahman
- Chanchal Saha
- Anderson Antônio Carvalho Alves (ORCID: https://orcid.org/0000-0001-8306-0487)
- Bernardo Medeiros
Institutions
- University of Georgia (US)
Publication Details
- Journal
- Journal of Dairy Science
- Published
- 2025-11-08
- DOI
- https://doi.org/10.3168/jds.2025-26731
- Primary Topic
- Animal Behavior and Welfare Studies
- Type
- article
- Field-Weighted Citation Impact
- 0.00