PigStressNet: A Real-Time Lightweight Vision System for On-Farm Heat Stress Monitoring via Attention-Guided Feature Refinement
Abstract
1. Introduction
- Improve the YOLOv12 network structure by introducing the NAM attention mechanism into the Backbone network of YOLOv12.
- Improve the YOLOv12 network structure by introducing the Rectangular Self-Calibration Module (RCM) into the Neck network of YOLOv12.
- Optimized Detection Head: The MBConv (Mobile Inverted Bottleneck Convolution) module from EfficientNet is utilized to optimize the detection head of YOLOv12, proposing a novel detection head called MBHead, which effectively reduces the computational complexity of the model.
- Powerful-IoU Loss Function: A tunable parameter is introduced to address issues such as occlusion or the presence of multiple targets.
- Dataset Construction: A comprehensive dataset for pig behavior recognition is built, categorizing pig behaviors into five classes: stand, eat, sit, lying, and stress.
- Experimental Validation: The proposed method is validated on the self-constructed dataset. Comparisons with several mainstream object-detection models are conducted, and the superiority of the method is demonstrated through comprehensive evaluation metrics, including the number of parameters, computational load, mAP (mean Average Precision), and FPS (Frames Per Second).
2. Related Work
3. Methods
3.1. YOLOv12
- Introduction of a Simple yet Effective Area-Attention Mechanism: This mechanism dynamically allocates weights to different regions of the feature map, enhancing the model’s ability to capture local key information, such as pig postures and erythema areas.
- Efficient Aggregation Network Structure (R-ELAN): Utilizing re-parameterization technology, R-ELAN (Re-parameterized Efficient Layer Aggregation Network) integrates multi-branch features, reducing computational complexity while improving cross-scale feature fusion efficiency.
- A2C2F Module (Area-Attention Cross-stage Context Fusion): Built upon R-ELAN, this module combines the area-attention mechanism with cross-stage contextual information, enhancing the detection performance of small targets (such as subtle physiological features under heat stress conditions) through adaptive feature filtering.
3.2. Our Overall Network Structure
3.3. Improvement of the Backbone
3.4. Improvement of the Neck
3.5. Improvement of the Head
3.5.1. MBConv
3.5.2. MBHead
3.6. Improvement of the Loss
4. Experiments
4.1. Datasets
4.2. Experimental Environment and Parameter Setting
4.3. Comparison of Ablation Experiments
4.4. Comparison of Detection Performance Between Different Models
5. Conclusions
Author Contributions
Funding
Conflicts of Interest
References
- Johnson, J.S. Bioenergetic consequences of pre- and post-natal heat stress on swine productivity. J. Anim. Sci. 2023, 101 (Suppl. 2), 59. [Google Scholar] [CrossRef]
- Johnson, J.S.; Stewart, K.R. Heat stress matters: Insights from United States swine producers. Transl. Anim. Sci. 2025, 9, txaf001. [Google Scholar] [CrossRef] [PubMed]
- Johnson, J.S. Heat stress: Impact on livestock well-being and productivity and mitigation strategies to alleviate the negative effects. Anim. Prod. Sci. 2018, 58, 1404–1413. [Google Scholar] [CrossRef]
- Johnson, J.S.; Brito, L.F. Genomic selection for heat stress resilience in pigs: Advancements, applications, and challenges. J. Anim. Sci. 2024, 102 (Suppl. 3), 18. [Google Scholar] [CrossRef]
- Nasirahmadi, A.; Sturm, B.; Edwards, S.; Jeppsson, K.-H.; Olsson, A.-C.; Müller, S.; Hensel, O. Deep learning and machine vision approaches for posture detection of individual pigs. Sensors 2019, 19, 3738. [Google Scholar] [CrossRef] [PubMed]
- Sa, J.; Choi, Y.; Lee, H.; Chung, Y.; Park, D.; Cho, J. Fast pig detection with a top-view camera under various illumination conditions. Symmetry 2019, 11, 266. [Google Scholar] [CrossRef]
- Zhang, L.; Gray, H.; Ye, X.; Collins, L.; Allinson, N. Automatic individual pig detection and tracking in pig farms. Sensors 2019, 19, 1188. [Google Scholar] [CrossRef] [PubMed]
- Riekert, M.; Klein, A.; Adrion, F.; Hoffmann, C.; Gallmann, E. Automatically detecting pig position and posture by 2D camera imaging and deep learning. Comput. Electron. Agric. 2020, 174, 105391. [Google Scholar] [CrossRef]
- Kang, F.L. Research on Multi-Target Pig State and Individual Behavior Recognition Based on Machine Learning. Ph.D. Thesis, Inner Mongolia Agricultural University, Hohhot, China, 2018. (In Chinese). [Google Scholar]
- Li, L. Research on Motion Feature Recognition of Quadruped Animals Based on Vision. Master’s Thesis, Kunming University of Science and Technology, Kunming, China, 2019. (In Chinese). [Google Scholar]
- Liu, Z.W.; Li, L.H. Application of acceleration sensors in livestock behavior research. Anim. Husb. Vet. Med. 2020, 52, 137–144. (In Chinese) [Google Scholar]
- Dong, L.Z.; Meng, X.B.; Pan, M. Pig behavior recognition method based on posture and time series characteristics. Trans. Chin. Soc. Agric. Eng. 2022, 38, 148–157. (In Chinese) [Google Scholar]
- Tian, Y.; Ye, Q.; Doermann, D. Yolov12: Attention-centric real-time object detectors. arXiv 2025, arXiv:2502.12524. [Google Scholar]
- Shao, Z.; Hoffmann, N. NAM: Normalization-based attention module. In Proceedings of the NeurIPS Workshop ImageNet: Past, Present, Future, Mexico City, Mexico, 13 December 2021. [Google Scholar]
- Ni, Z.; Chen, X.; Zhai, Y.; Tang, Y.; Wang, Y. Context-guided spatial feature reconstruction for efficient semantic segmentation. In Proceedings of the Computer Vision–ECCV 2024, 18th European Conference, Milan, Italy, 29 September–4 October 2024; Springer: Cham, Switzerland, 2024; pp. 239–255. [Google Scholar]
- Tan, M.; Le, Q.V. EfficientNet: Rethinking model scaling for convolutional neural networks. In Proceedings of the 36th International Conference on Machine Learning, Long Beach, CA, USA, 9–15 June 2019; pp. 6105–6114. [Google Scholar]
- Ma, S.; Xu, Y. MPDIoU: A loss for efficient and accurate bounding box regression. arXiv 2023, arXiv:2307.07662. [Google Scholar] [CrossRef]
- Ma, N.; Zhang, X.; Zheng, H.T. ShuffleNet V2: Practical guidelines for efficient CNN architecture design. In Proceedings of the European Conference on Computer Vision (ECCV), Munich, Germany, 8–14 September 2018; pp. 122–138. [Google Scholar]
- Han, K.; Wang, Y.; Tian, Q.; Guo, J.; Xu, C.; Xu, C. GhostNet: More features from cheap operations. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, Seattle, WA, USA, 14–19 June 2020; pp. 1580–1589. [Google Scholar]
- Howard, A.; Sandler, M.; Chen, B.; Wang, W.; Chen, L.-C.; Tan, M.; Chu, G.; Vasudevan, V.; Zhu, Y.; Pang, R.; et al. Searching for MobileNetV3. In Proceedings of the IEEE/CVF International Conference on Computer Vision, Seoul, Republic of Korea, 27 October–2 November 2019; pp. 1314–1324. [Google Scholar]
Category | Configuration |
---|---|
CPU | Intel(R)Core(TM)i5-12400F |
GPU | NVIDIA GeForce RTX 4060 |
System environment | Windows 11 |
Framework | PyTorch 2.6.0 |
Programming language | Python 3.11 |
Cuda version | 12.4.0 |
Network | mAP | Params (M) | GFLOPs | ||||
---|---|---|---|---|---|---|---|
Stress | Eat | Stand | Sit | Lying | |||
YOLOv12n | 0.971 | 0.894 | 0.870 | 0.808 | 0.863 | 2,557,703 | 6.3 |
YOLOv12n+NAM | 0.978 | 0.915 | 0.876 | 0.809 | 0.891 | 2,558,215 | 6.3 |
YOLOv12n+RCM | 0.978 | 0.91 | 0.895 | 0.849 | 0.912 | 2,576,775 | 6.6 |
YOLOv12n+NAM+RCM | 0.980 | 0.917 | 0.897 | 0.855 | 0.905 | 2,589,375 | 6.7 |
YOLOv12n+MBHead | 0.969 | 0.891 | 0.869 | 0.806 | 0.861 | 2,237,831 | 5.1 |
YOLOv12n+MPDIou | 0.972 | 0.899 | 0.871 | 0.822 | 0.864 | 2,557,703 | 6.3 |
PigStressNet | 0.979 | 0.915 | 0.896 | 0.853 | 0.897 | 2,257,415 | 5.3 |
Features | Stress mAP | Misrate (Normal Lying→Stress) | Misrate (Standing Erythema→Stress) |
---|---|---|---|
Posture Only | 0.75 | 35% | 5% |
Erythema Only | 0.68 | 8% | 42% |
Both | 0.979 | 2% | 3% |
Network | mAP | Params (M) | GFLOPs | ||||
---|---|---|---|---|---|---|---|
Stress | Eat | Stand | Sit | Lying | |||
ShuffleNetV2 [18] | 0.958 | 0.8 | 0.799 | 0.778 | 0.84 | 1,711,199 | 5.0 |
EfficientNet [16] | 0.957 | 0.842 | 0.831 | 0.785 | 0.822 | 1,907,451 | 5.6 |
GhostNet [19] | 0.965 | 0.85 | 0.835 | 0.783 | 0.889 | 3,350,159 | 6.9 |
MobileNetV3 [20] | 0.941 | 0.873 | 0.833 | 0.787 | 0.85 | 2,352,241 | 5.7 |
PigStressNet | 0.979 | 0.915 | 0.896 | 0.853 | 0.897 | 2,257,415 | 5.3 |
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
Cao, S.; Li, F.; Luo, X.; Ni, J.; Li, L. PigStressNet: A Real-Time Lightweight Vision System for On-Farm Heat Stress Monitoring via Attention-Guided Feature Refinement. Sensors 2025, 25, 5534. https://doi.org/10.3390/s25175534
Cao S, Li F, Luo X, Ni J, Li L. PigStressNet: A Real-Time Lightweight Vision System for On-Farm Heat Stress Monitoring via Attention-Guided Feature Refinement. Sensors. 2025; 25(17):5534. https://doi.org/10.3390/s25175534
Chicago/Turabian StyleCao, Shuai, Fang Li, Xiaonan Luo, Jiacheng Ni, and Linsong Li. 2025. "PigStressNet: A Real-Time Lightweight Vision System for On-Farm Heat Stress Monitoring via Attention-Guided Feature Refinement" Sensors 25, no. 17: 5534. https://doi.org/10.3390/s25175534
APA StyleCao, S., Li, F., Luo, X., Ni, J., & Li, L. (2025). PigStressNet: A Real-Time Lightweight Vision System for On-Farm Heat Stress Monitoring via Attention-Guided Feature Refinement. Sensors, 25(17), 5534. https://doi.org/10.3390/s25175534