A Study on Multi-Scale Behavior Recognition of Dairy Cows in Complex Background Based on Improved YOLOv5
Abstract
:1. Introduction
2. Materials and Methods
2.1. Data Source
2.2. Datasets and Models
2.2.1. Dataset Construction
2.2.2. Training Platform
2.2.3. Model Evaluation Index
2.3. A Cow Behavior Recognition Model Based on an Improved YOLOv5 Network
2.3.1. Add Shuffle Attention
2.3.2. Introduce Deformable Convolution DCNv3
- (1)
- Weight Sharing Mechanism: A weight-sharing mechanism reduces model complexity by splitting weights into two parts along the depth dimension. This mechanism simplifies the model structure and enhances processing efficiency. Specifically, weights along the depth dimension are regulated by the perception mechanism at the original position, while weights are shared across sampling points. This design reduces parameter count and optimizes the computational process.
- (2)
- Multiple Group Segmentation Strategy: A grouping mechanism is implemented during spatial information aggregation. By dividing the sampling process into N groups, each with its own sampling offset and adjustment scale, the model achieves diverse spatial information aggregation modes within a single layer. This strategy enables the model to capture richer and more detailed feature information, enhancing the detection accuracy of diverse cow behaviors.
- (3)
- SoftMax Normalization: To enhance training stability, the SoftMax function replaces the traditional Sigmoid function for normalization. This improvement addresses the gradient vanishing problem associated with Sigmoid, ensuring stable model training.
2.3.3. Replace Dynamic Head
3. Results
3.1. Comparison of the Results of the Cow Behavior Recognition Model
3.1.1. Comparison of the Performance of Different Models
3.1.2. Comparison of the Results of Identifying Different Types of Targets
3.2. Ablation Experiment
3.2.1. Performance Analysis of DCNv3 and DyHead
3.2.2. The Influence of Different Attention Mechanisms on the Performance of the Improved Model
3.3. Cows Behavior Recognition Results Based on Improved YOLOv5 Network
4. Discussion
4.1. Analysis of Missed and Misdiagnosed Cow Behaviors
4.2. Comparison of the Improved Model with the Results of Previous Studies
5. Conclusions
5.1. Summary
- (1)
- The proposed improved model effectively addresses the challenges of complex backgrounds and multi-scale targets by integrating three modules: SA, DyHead, and DCNv3. Specifically, SA significantly enhances the model’s focus on behavioral regions by combining channel attention and spatial attention mechanisms, while suppressing irrelevant features in complex backgrounds. DyHead optimizes multi-scale target detection by dynamically adjusting feature weights, particularly enhancing the ability to distinguish between small targets and those with similar behavioral features. DCNv3 improves the model’s robustness in occluded scenes and complex shapes by dynamically adjusting the receptive field and adaptively sampling feature regions.
- (2)
- The results indicate that the model incorporating both DCNv3 and DyHead performs best, achieving a 2.6% increase in mAP50 and a 1.8% increase in mAP50-95 compared to the original model. The model integrates DCNv3, DyHead, and an attention mechanism to address these challenges, improving accuracy and efficiency by assigning different weights to different input components. The results demonstrate that the improved model, combining SA, DCNv3, and DyHead, significantly enhances multi-scale cow behavior recognition, achieving a 3.7% increase in mAP over the original model. The recognition results indicate that the improved model excels at distinguishing and identifying cow behaviors, surpassing the accuracy of the YOLOv5 model. In tests using images from natural environments, the improved model demonstrated high-precision cow behavior recognition. This advantage significantly enhances the model’s ability to recognize multiple cow behaviors in real-world scenarios.
5.2. Prospect
- (1)
- The current focus is on optimizing model structure. Future work can further enhance model performance on edge computing devices and achieve higher execution efficiency by integrating advanced techniques such as pruning.
- (2)
- This study focuses on four basic cow behaviors: standing, lying, drinking, and eating. To comprehensively assess cow health and reproductive status, future research should expand to accurately identify complex behaviors such as ruminating, tail-wagging, and mounting, enabling more precise health predictions.
Author Contributions
Funding
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
References
- Cheng, G.; Wu, J.; Xing, L.; Zhu, M.; Zhang, J.; Han, S. Fine-grained cows’ behavior classification method based on IMU. J. China Agric. Univ. 2022, 27, 179–186. [Google Scholar]
- He, D.; Liu, D.; Zhao, K. Review of Perceiving Animal Information and Behavior in Precision Livestock Farming. Trans. Chin. Soc. Agric. Mach. 2016, 47, 231–244. [Google Scholar]
- Wang, Z.; Song, H.; Wang, Y.; Hua, Z.; Li, R.; Xu, X. Research progress and technology trend of intelligent morning of dairy cow motion behavior. Smart Agric. 2022, 4, 36–52. [Google Scholar]
- Wang, X.; Siqinbate; Turigengbaiyila. TURIGEN Baiyila.Research Progress of Dairy Cattle Lying Behavior. Mod. Anim. Husb. 2017, 5, 3–5. [Google Scholar] [CrossRef]
- Bian, S. Factors affecting the duration of lying rest in dairy cows. Chin. Dairy Cow 2017, 7, 6–9. [Google Scholar] [CrossRef]
- Teng, G. Information sensing and environment control of precision facility livestock and poultry farming. Smart Agric. 2019, 1, 3. [Google Scholar]
- Liu, J.; Jiang, B.; He, D.; Song, H. Individual Recognition of Dairy Cattle Based on Gaussian Mixture Model and CNN. Comput. Appl. Softw. 2018, 35, 159–164. [Google Scholar]
- Yongliang, Q.; He, K.; Cameron, C.; Sabrina, L.; Daobilige, S.; Stuart, E.; Salah, S. Intelligent Perception-Based Cattle Lameness Detection and Behaviour Recognition: A Review. Animals 2021, 11, 3033. [Google Scholar] [CrossRef] [PubMed]
- Chu, M.; Liu, X.; Zeng, X.; Wang, Y.; Liu, G. Research advances in the automatic detection technology for mastitis of dairy cows. Trans. Chin. Soc. Agric. Eng. 2023, 39, 1–12. [Google Scholar]
- Zhao, K.; Li, G.; He, D. Fine Segment Method of Cows’Body Parts in Depth Images Based on Machine Learning. Trans. Chin. Soc. Agric. Mach. 2017, 48, 173–179. [Google Scholar]
- Stygar, A.H.; Gómez, Y.; Berteselli, G.V.; Costa, E.D.; Canali, E.; Niemi, J.K.; Llonch, P.; Pastell, M. A Systematic Review on Commercially Available and Validated Sensor Technologies for Welfare Assessment of Dairy Cattle. Front. Vet. Sci. 2021, 8, 634338. [Google Scholar] [CrossRef] [PubMed]
- Wang, Z.; Zong, Z.; Wang, H.; Yang, J.; Liu, G.; Du, Y. Research status and development of digital detection methods for cow estrus. China Feed 2021, 1, 134–138. [Google Scholar]
- Smith, D.; Rahman, A.; Bishop-Hurley, G.J.; Hills, J.; Shahriar, S.; Henry, D.; Rawnsley, R. Behavior classification of cows fitted with motion collars: Decomposing multi-class classification into a set of binary problems. Comput. Electron. Agric. 2016, 131, 40–50. [Google Scholar] [CrossRef]
- Guo, Y.; He, D.; Chai, L. A Machine Vision-Based Method for Monitoring Scene-Interactive Behaviors of Dairy Calf. Animals 2020, 10, 190. [Google Scholar] [CrossRef]
- Song, H.; Wu, D.; Yin, X.; Jiang, B.; He, D. Detection of cow breathing behavior based on the Lucas-Kanade sparse optical flow algorithm. Trans. Chin. Soc. Agric. Eng. 2019, 35, 215–224. [Google Scholar]
- He, D.; Meng, F.; Zhao, K.; Zhang, Z. Basic behavior recognition of calves based on video analysis. Trans. Chin. Soc. Agric. Mach. 2016, 47, 294–300. [Google Scholar]
- Song, H.; Jiang, B.; Wu, Q.; Li, T.; He, D. A cow lameness detection method based on fitting the slope feature of the straight line to the contour of the head and neck. Trans. Chin. Soc. Agric. Eng. 2018, 34, 190–199. [Google Scholar]
- Zhang, S.; Tian, J.; Jian, L.; Ji, Z. A method for recognizing fighting behavior in piglets based on inter-frame difference method and single-point multi-frame detector. J. Jiangsu Agric. Sci. 2021, 37, 397–404. [Google Scholar]
- Mao, Y.; Niu, T.; Wang, P.; Song, H.; He, D. Multi-objective cow mouth tracking and rumination monitoring using Kalman filtering and Hungarian algorithm. Trans. Chin. Soc. Agric. Eng. 2021, 37, 192–201. [Google Scholar]
- Song, H.; Niu, M.; Ji, C.; Li, Z.; Zhu, Q. Multi-objective cow ruminant behavior monitoring based on video analysis. Trans. Chin. Soc. Agric. Eng. 2018, 34, 211–218. [Google Scholar]
- Gu, J.; Wang, Z.; Gao, R.; Wu, H. A method for recognizing cow behavior based on fusing images and motion quantities. Trans. Chin. Soc. Agric. Mach. 2017, 48, 145–151. [Google Scholar]
- Zhenwei, Y.; Yuehua, L.; Sufang, Y.; Ruixue, W.; Zhanhua, S.; Yinfa, Y.; Fade, L.; Zhonghua, W.; Fuyang, T. Automatic Detection Method of Dairy Cow Feeding Behaviour Based on YOLO Improved Model and Edge Computing. Sensors 2022, 22, 3271. [Google Scholar] [CrossRef] [PubMed]
- Chen, C.; Zhu, W.; Norton, T. Behaviour recognition of pigs and cattle: Journey from computer vision to deep learning. Comput. Electron. Agric. 2021, 187, 106255. [Google Scholar] [CrossRef]
- Achour, B.; Belkadi, M.; Filali, I.; Laghrouche, M.; Lahdir, M. Image analysis for individual identification and feeding behaviour monitoring of dairy cows based on Convolutional Neural Networks (CNN). Biosyst. Eng. 2020, 198, 31–49. [Google Scholar] [CrossRef]
- Wang, Z.; Wang, S.; Wang, C.; Zhang, Y.; Zong, Z.; Wang, H.; Su, L.; Du, Y. A Non-Contact Cow Estrus Monitoring Method Based on the Thermal Infrared Images of Cows. Agriculture 2023, 13, 385. [Google Scholar] [CrossRef]
- Zhang, H.; Wu, J.; Li, Y.; Li, S.; Wang, H.; Song, R. Research on the identification of the feeding behavior of multi-purpose beef cattle. Trans. Chin. Soc. Agric. Mach. 2020, 51, 259–267. [Google Scholar]
- Liu, Z.; He, D. A method for recognizing the estrus behavior of cows based on convolutional neural networks. Trans. Chin. Soc. Agric. Mach. 2019, 50, 186–193. [Google Scholar]
- Wang, S.; He, D. Research on the recognition of estrus behavior in dairy cows based on an improved YOLO v3 model. Trans. Chin. Soc. Agric. Mach. 2021, 52, 141–150. [Google Scholar]
- Yin, X.; Wu, D.; Shang, Y.; Jiang, B. Huaibo SongUsing an EfficientNet-LSTM for the recognition of single Cow’s motion behaviours in a complicated environment. Comput. Electron. Agric. 2020, 177, 105707. [Google Scholar] [CrossRef]
- Ma, S.; Zhang, Q.; Li, T.; Song, H. Basic motion behavior recognition of single dairy cow based on improved Rexnet 3D network. Comput. Electron. Agric. 2022, 194, 106772. [Google Scholar] [CrossRef]
- Zhang, Q.-L.; Yang, Y.-B. SA-Net: Shuffle Attention for Deep Convolutional Neural Networks. arXiv 2021, arXiv:2102.00240. [Google Scholar]
- Wang, G.; Li, H.; Ye, S.; Zhao, H.; Ding, H.; Xie, S. RFWNet: A Multiscale Remote Sensing Forest Wildfire Detection Network With Digital Twinning, Adaptive Spatial Aggregation, and Dynamic Sparse Features. IEEE Trans. Geosci. Remote Sens. 2024, 62, 4708523. [Google Scholar] [CrossRef]
- Luo, Z.; Wang, C.; Qi, Z.; Luo, C. LA_YOLOv8s: A lightweight-attention YOLOv8s for oil leakage detection in power transformers. Alex. Eng. J. 2024, 92, 82–91. [Google Scholar] [CrossRef]
- Bai, Q.; Gao, R.; Zhao, C.; Li, Q.; Wang, R.; Li, S. Multi-scale behavior recognition method for dairy cows based on improved YOLOV5s network. Trans. Chin. Soc. Agric. Eng. 2022, 38, 163–172. [Google Scholar]
- Wang, Z.; Xu, X.; Hua, Z.; Shang, Y.; Duan, Y.; Song, H. Lightweight recognition for the oestrus behavior of dairy cows combining YOLO v5n and channel pruning. Trans. Chin. Soc. Agric. Eng. 2022, 38, 130–140. [Google Scholar]
- Jannu, C.; Vanambathina, S.D. Shuffle Attention U-Net for Speech Enhancement in Time Domain. Int. J. Image Graph. 2023, 24, 2450043. [Google Scholar] [CrossRef]
Sequence | Weather | Period | Sparse | Dense | Interference Factors |
---|---|---|---|---|---|
01 | cloudy | sunrise | √ | - | light: weak shading: slight |
02 | sunny | morning | - | √ | light: normal shading: moderate |
03 | sunny | afternoon | - | √ | lighting: strong shade: heavy |
04 | cloudy | evening | - | √ | light: weak shading: moderate |
05 | cloudy | night | √ | - | lighting: dark shading: slight |
Category | Judgment Standard | Visual Feature | Labels |
---|---|---|---|
Stand | Limbs upright, supporting body weight; abdomen off the ground. | Legs visible; body straight or near-straight; no ground contact. | stand |
Lie | Belly or body touching the ground; limbs bent, relaxed posture. | Body close to the ground; outline horizontal; limbs bent. | lie |
Eat | Head passes over railing, in contact with or near the feed. | Head near feed; body tilted; neck passing through railing. | eat |
Drink | Standing upright; head positioned above sink, mouth touching water. | Head extended forward, contacting water source. | drink |
Parameter | Values |
---|---|
Training batch size | 16 |
Epochs | 200 |
Image_size | 640 × 640 |
Batch_size | 8 |
Initial learning rate | 0.01 |
Momentum | 0.937 |
Index Algorithms | Params (M) | FLOPs (G) | Precision (%) | Recall (%) | F1 Score (%) | mAP (%) |
---|---|---|---|---|---|---|
Faster R-CNN | 27.4 | 74.0 | 79.2 | 78.3 | 78.7 | 78.7 |
YOLOv3 | 7.3 | 20.6 | 76.0 | 77.3 | 76.4 | 79.0 |
YOLOv4 | 4.6 | 10.7 | 89.3 | 89.3 | 89.3 | 91.5 |
YOLOv5 | 1.8 | 4.8 | 93.1 | 90.0 | 91.1 | 94.0 |
YOLOv8 | 2.3 | 5.7 | 90.3 | 91.4 | 89.5 | 92.6 |
YOLOx | 12.1 | 52.78 | 87.5 | 89.9 | 87.7 | 89.2 |
YOLO11 | 2.6 | 6.3 | 92.5 | 91.3 | 91.7 | 93.2 |
Improved YOLOv5 | 3.2 | 6.8 | 93.8 | 96.7 | 95.2 | 97.7 |
Model | Params (M) | FLOPs (G) | Average Precision AP(%) | mAP (%) | |||
---|---|---|---|---|---|---|---|
Stand | Lie | Eat | Drink | ||||
Faster R-CNN | 27.4 | 74.0 | 78.7 | 81.4 | 77.6 | 77.1 | 78.7 |
YOLOv3 | 7.3 | 20.6 | 80.1 | 78.4 | 79.4 | 78.1 | 79.0 |
YOLOv4 | 4.6 | 10.7 | 91.5 | 93.0 | 90.3 | 91.2 | 91.5 |
YOLOv5 | 1.8 | 4.8 | 95.2 | 94.5 | 92.5 | 93.8 | 94.0 |
YOLOv8 | 2.3 | 5.7 | 93.7 | 92.6 | 91.3 | 92.7 | 92.6 |
YOLOx | 12.1 | 52.78 | 88.6 | 89.4 | 91.3 | 87.6 | 89.2 |
YOLO11 | 2.6 | 6.3 | 92.8 | 97.1 | 91.2 | 91.8 | 93.2 |
Improved YOLOv5 | 3.2 | 6.8 | 98.1 | 98.9 | 97.7 | 96.1 | 97.7 |
Index Algorithms | Precision (%) | Recall (%) | F1 Score (%) | mAP (%) |
---|---|---|---|---|
YOLOv5 | 93.1 | 90.0 | 91.5 | 94.0 |
YOLOv5 + DCNv3 | 94.1 | 94.5 | 94.3 | 95.8 |
YOLOv5 + DyHead | 95.2 | 92.6 | 93.9 | 96.3 |
YOLOv5 + DCNv3 + DyHead | 94.5 | 95.1 | 94.9 | 96.6 |
Index Algorithms | Precision (%) | Recall (%) | F1 Score (%) | mAP (%) |
---|---|---|---|---|
YOLOv5 | 93.1 | 90.0 | 91.5 | 94.0 |
Iattentive + DCNv3 + DyHead | 94.5 | 95.1 | 94.8 | 96.6 |
SE + DCNv3 + DyHead | 96.4 | 90.7 | 93.4 | 95.7 |
EMA + DCNv3 + DyHead | 95.4 | 92.5 | 93.9 | 97.3 |
SA + DCNv3 + DyHead | 93.8 | 96.7 | 95.2 | 97.7 |
Year | Model | Behaviors | Dataset | Sampling Rate (fps) | Environment | Cameras | mAP (%) |
---|---|---|---|---|---|---|---|
2016 | Clustering | Lie, stand, walk, run, jump | 162 videos (-) | 25 | Indoor | 1 | 97.3 |
2018 | KNN | Limp | 360 videos (30 cows) | 25 | Outdoor | 1 | 82.7 |
2019 | CNN | Estrus (mounting) | 25,000 videos (50 cows) | 30 | Outdoor | 2 | 98.2 |
2020 | YOLOv3 | Eat | 1846 images | 24 | Indoor | 1 | 83.8 |
2020 | EfficientNet-LSTM | Lie, stand, walk, drink, feed | 1009 videos (-) | 10 | Outdoor | 1 | 97.8 |
2021 | YOLOv3 | Estrus (mounting) | 3600 videos (56 cows) | 5 | Outdoor | 2 | 98.1 |
2022 | RexNet 3D | Lie, stand, walk | 10 videos (30 cows) | 5 | Outdoor | 2 | 95.0 |
2024 | Improved YOLOv5 | Lie, stand, eat, drink | 1044 videos (38 cows) | 25 | Indoor + Outdoor | 2 | 97.7 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Zong, Z.; Ban, Z.; Wang, C.; Wang, S.; Yuan, W.; Zhang, C.; Su, L.; Yuan, Z. A Study on Multi-Scale Behavior Recognition of Dairy Cows in Complex Background Based on Improved YOLOv5. Agriculture 2025, 15, 213. https://doi.org/10.3390/agriculture15020213
Zong Z, Ban Z, Wang C, Wang S, Yuan W, Zhang C, Su L, Yuan Z. A Study on Multi-Scale Behavior Recognition of Dairy Cows in Complex Background Based on Improved YOLOv5. Agriculture. 2025; 15(2):213. https://doi.org/10.3390/agriculture15020213
Chicago/Turabian StyleZong, Zheying, Zeyu Ban, Chunguang Wang, Shuai Wang, Wenbo Yuan, Chunhui Zhang, Lide Su, and Ze Yuan. 2025. "A Study on Multi-Scale Behavior Recognition of Dairy Cows in Complex Background Based on Improved YOLOv5" Agriculture 15, no. 2: 213. https://doi.org/10.3390/agriculture15020213
APA StyleZong, Z., Ban, Z., Wang, C., Wang, S., Yuan, W., Zhang, C., Su, L., & Yuan, Z. (2025). A Study on Multi-Scale Behavior Recognition of Dairy Cows in Complex Background Based on Improved YOLOv5. Agriculture, 15(2), 213. https://doi.org/10.3390/agriculture15020213