YOLOv5-VF-W3: A novel cattle body detection approach for precision livestock farming

Wangli Hao, Chao Ren, Meng Han, Fuzhong Li, Zhenyu Liu

Abstract


Accurate cattle body detection can significantly enhance the efficiency and quality of animal husbandry production. Traditional manual observation approaches are not only inefficient but also lack objectivity, while computer vision-based methods demand prolonged training periods and present challenges in implementation. To address these issues, this paper develops a novel precise cattle body detection solution, namely YOLOv5-VF-W3. By introducing the Varifocal loss, the YOLOv5-VF-W3 model can handle imbalanced samples and focus more attention on difficult-to-recognize instances. Additionally, the introduction of the WIoUv3 loss function provides the model with a wise gradient gain allocation strategy. This strategy reduces the competitiveness of high-quality anchor boxes while mitigating harmful gradients produced by low-quality anchor boxes, thereby emphasizing anchor boxes of ordinary quality. Through these enhancements, the YOLOv5-VF-W3 model can accurately detect cattle bodies, improving the efficiency and quality of animal husbandry production. Numerous experimental results have demonstrated that the proposed YOLOv5-VF-W3 model achieves superior cattle body detection results in both quantitative and qualitative evaluation criteria. Specifically, the YOLOv5-VF-W3 model achieves an mAP of 95.2% in cattle body detection, with individual cattle detection, leg detection, and head detection reaching 95.3%, 94.8%, and 95.4%, respectively. Furthermore, in complex scenarios, especially when dealing with small targets and occlusions, the model can accurately and efficiently detect individual cattle and key body parts. This brings new opportunities for the development of precision livestock farming.
Key words: cattle body detection; varifocal loss; key body parts; WIoUv3 loss
DOI: 10.25165/j.ijabe.20251802.9107

Citation: Hao W L, Ren C, Han M, Li F Z, Liu Z Y. YOLOv5-VF-W3: A novel cattle body detection approach for precision livestock farming. Int J Agric & Biol Eng, 2025; 18(2): 269–277.

Keywords


cattle body detection; varifocal loss; key body parts; WIoUv3 loss

Full Text:

PDF

References


Guo H, Ma X D, Ma Q, Wang K, Su W, Zhu D H, et al. An interactive 3D point clouds analysis software for body measurement of livestock with similar forms of cows or pigs. Computers and Electronics in Agriculture, 2017; 138: 60–68.

Mao A, Huang E D, Wang X S, Liu K. Deep learning-based animal activity recognition with wearable sensors: Overview, challenges, and future directions. Computers and Electronics in Agriculture, 2023; 211: 108043.

Awad A I. From classical methods to animal biometrics: A review on cattle identification and tracking. Computers and Electronics in Agriculture, 2016; 123: 423–435.

Roberts C M. Radio frequency identification (RFID). Computers and Security, 2006; 25(1): 18–26.

Islam M A, Lomax S, Doughty A K, Islam M R, Thomson P C, Clark C E F, et al. Revealing the diversity in cattle behavioural response to high environmental heat using accelerometer-based ear tag sensors. Computers and Electronics in Agriculture, 2021; 191: 106511.

Dutta D, Natta D, Mandal S, Ghosh N. MOOnitor: An IoT based multi-sensory intelligent device for cattle activity moni-toring. Sensors and Actuators A: Physical, 2022; 333: 113271.

Hossain M E, Kabir M A, Zheng L H, Swain D L, McGrath S, Medway J. A systematic review of machine learning techniques for cattle identification: Datasets, methods and future directions. Artificial Intelligence in Agriculture, 2022; 6: 138–155.

Bercovich A, Edan Y, Alchanatis V, Moallem U, Parmet Y, Honig H, et al. Development of an automatic cow body condition scoring using body shape signature and Fourier descriptors. Journal of Dairy Science, 2013; 96(12): 8047–8059.

Zhao K X, Jin X, Ji J T, Wang J, Ma H, Zhu X F. Individual identification of Holstein dairy cows based on detecting and matching feature points in body images. Biosystems Engineering, 2019; 181: 128–139.

Gao T. Detection and tracking cows by computer vision and image classification methods. International Journal of Security and Privacy in Pervasive Computing, 2021; 13(1): 45.

Liu D, Zhao K X, He D J. Real-time target detection for moving cows based on gaussian mixture model. Transactions of the Chinese Society for Agricultural Machinery, 2016; 47: 288–294. (in Chinese)

Kaur A, Kumar M, Jindal M K. Shi-Tomasi corner detector for cattle identification from muzzle print image pattern. Ecological Informatics, 2022; 68: 101549.

Tassinari P, Bovo M, Benni S, Franzoni S, Poggi M, Mammi L M E, et al. A computer vision approach based on deep learning for the detection of dairy cows in free stall barn. Computers and Electronics in Agriculture, 2021; 182: 106030.

Lodkaew T, Pasupa K, Loo C K. CowXNet: An automated cow estrus detection system. Expert Systems with Applications, 2023; 211: 118550.

Xiao J X, Liu G, Wang K J, Si Y S. Cow identification in free-stall barns based on an improved Mask R-CNN and an SVM. Computers and Electronics in Agriculture, 2022; 194: 106738.

Redmon J, Farhadi A. YOLOv3: An Incremental Improvement. arXiv: 1804.02767, 2018; In press. doi: 10.48550/arXiv.1804.02767.

Bochkovskiy A, Wang C Y, Liao H Y M. YOLOv4: Optimal speed and accuracy of object detection. arXiv, 2020; doi: 10.48550/arXiv.2004.10934.

He K, Kioxari G G, Dollar P, Girshick R. Mask R-CNN. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2020; 42(2): 386–397.

Shao W, Kawakami R, Yoshihashi R, You S, Kawase H, Naemura T. Cattle detection and counting in UAV images based on convolutional neural networks. International Journal of Remote Sensing, 2020; 41(1): 31–52.

Weber F d L, Weber V A d M, Moraes P H d, Matsubara E T, Paiva D M B, Gomes M d N B, et al. Counting cattle in UAV images using convolutional neural networks. Remote Sensing Applications: Society and Environment, 2023; 29: 100900.

Andrew W, Gao J, Mullan S, Campbell N W, Dowsey A W, Burghardt T, et al. Visual identification of individual Hol-stein-Friesian cattle via deep metric learning. Computers and Electronics in Agriculture, 2021; 185: 106133.

Xu B, Wang W, Falzon G, Kwan P, Schneider D. Automated cattle counting using Mask R-CNN in quadcopter vision system. Computers and Electronics in Agriculture, 2020; 171: 105300.

Redmon J, Farhadi A. YOLO9000: Better, Faster, Stronger. In proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Honolulu, HI, USA: IEEE, 2017; pp.726–727. doi: 10.1109/CVPR.2017.690.

Ren S, He K, Girshick R, Sun J. Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2017; 39(6): 1137–1149.

Soares V H A, Ponti M A, Gonçalves R A, Campello R J G B. Cattle counting in the wild with geolocated aerial images in large pasture areas. Computers and Electronics in Agriculture, 2021; 189: 106354.

Shang C, Wu F, Wang M L, Gao Q. Cattle behavior recognition based on feature fusion under a dual attention mechanism. Journal of Visual Communication and Image Representation, 2022; 85: 103524.

Wu D H, Wu Q, Yin X Q, Jiang B, Wang H, He D J, Song H b. Lameness detection of dairy cows based on the YOLOv3 deep learning algorithm and a relative step size characteristic vector. Biosystems Engineering, 2020; 189: 150–163.

Beauchemin K A. Invited review: Current perspectives on eating and rumination activity in dairy cows. Journal of Dairy Science, 2018; 101: 4762–4784.

Wang Z, Meng F S, Liu S Q, Zhang Y, Zheng Z Q, Gong C L, et al. Cattle face recognition based on a Two-Branch convolutional neural network. Computers and Electronics in Agriculture, 2022; 196: 106871.

Shen W Z, Hu H Q, Dai B S, Wei X L, Sun J, et al. Individual identification of dairy cows based on convolutional neural networks. Multimedia Tools and Applications, 2020; 75: 14711–14724.

Gladstone J. YOLOv5: Better speed and accuracy. arXiv, 2021; In press

Zhang H Y, Wang Y, Dayoub F, Sunderhauf N. VarifocalNet: An IoU-aware dense object detector. In: 2021 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). Nashville, TN, USA: IEEE, 2020; pp.8510-8519.

Tong Z J, Chen Y H, Xu Z W, Yu R. Wise-IoU: Bounding box regression loss with dynamic focusing mechanism. arXiv, 2023; In press.

Selvaraju R R, Cogswell M, Das A, Vedantam R, Parikh D, Batra D, et al. Grad-CAM: Visual explanations from deep networks via Gradient-Based localization. IEEE International Conference on Computer Vision, 2019; 128: 336–359.

Liu W, Anguelov D, Erhan D, Szegedy C, Reed S, Fu C Y, et al. SSD: Single shot MultiBox detector. In: Computer Vision - ECCV 2016, Springer, 2015. doi: 10.1007/978-3-319-46448-0_2




Copyright (c) 2025 International Journal of Agricultural and Biological Engineering

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

2023-2026 Copyright IJABE Editing and Publishing Office