Enhanced YOLOv8 for Robust Pig Detection and Counting in Complex Agricultural Environments

Accurate pig counting is crucial for precision livestock farming, enabling optimized feeding management and health monitoring. Detection-based counting methods face significant challenges due to mutual occlusion, varying illumination conditions, diverse pen configurations, and substantial variations...

Full description

Saved in:
Bibliographic Details
Main Authors: Jian Li, Wenkai Ma, Yanan Wei, Tan Wang
Format: Article
Language:English
Published: MDPI AG 2025-07-01
Series:Animals
Subjects:
Online Access:https://www.mdpi.com/2076-2615/15/14/2149
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1849304313365528576
author Jian Li
Wenkai Ma
Yanan Wei
Tan Wang
author_facet Jian Li
Wenkai Ma
Yanan Wei
Tan Wang
author_sort Jian Li
collection DOAJ
description Accurate pig counting is crucial for precision livestock farming, enabling optimized feeding management and health monitoring. Detection-based counting methods face significant challenges due to mutual occlusion, varying illumination conditions, diverse pen configurations, and substantial variations in pig densities. Previous approaches often struggle with complex agricultural environments where lighting conditions, pig postures, and crowding levels create challenging detection scenarios. To address these limitations, we propose EAPC-YOLO (enhanced adaptive pig counting YOLO), a robust architecture integrating density-aware processing with advanced detection optimizations. The method consists of (1) an enhanced YOLOv8 network incorporating multiple architectural improvements for better feature extraction and object localization. These improvements include DCNv4 deformable convolutions for irregular pig postures, BiFPN bidirectional feature fusion for multi-scale information integration, EfficientViT linear attention for computational efficiency, and PIoU v2 loss for improved overlap handling. (2) A density-aware post-processing module with intelligent NMS strategies that adapt to different crowding scenarios. Experimental results on a comprehensive dataset spanning diverse agricultural scenarios (nighttime, controlled indoor, and natural daylight environments with density variations from 4 to 30 pigs) demonstrate our method achieves 94.2% mAP@0.5 for detection performance and 96.8% counting accuracy, representing 12.3% and 15.7% improvements compared to the strongest baseline, YOLOv11n. This work enables robust, accurate pig counting across challenging agricultural environments, supporting precision livestock management.
format Article
id doaj-art-31652897652e4af987fe10ea0e5a94d0
institution Kabale University
issn 2076-2615
language English
publishDate 2025-07-01
publisher MDPI AG
record_format Article
series Animals
spelling doaj-art-31652897652e4af987fe10ea0e5a94d02025-08-20T03:55:48ZengMDPI AGAnimals2076-26152025-07-011514214910.3390/ani15142149Enhanced YOLOv8 for Robust Pig Detection and Counting in Complex Agricultural EnvironmentsJian Li0Wenkai Ma1Yanan Wei2Tan Wang3School of Biology and Food Engineering, Fuyang Normal University, Fuyang 236037, ChinaSchool of Information and Artificial Intelligence, Anhui Agricultural University, Hefei 230036, ChinaAnhui Provincial Key Laboratory of Embryo Development and Reproductive Regulation, Fuyang 236037, ChinaSchool of Information and Artificial Intelligence, Anhui Agricultural University, Hefei 230036, ChinaAccurate pig counting is crucial for precision livestock farming, enabling optimized feeding management and health monitoring. Detection-based counting methods face significant challenges due to mutual occlusion, varying illumination conditions, diverse pen configurations, and substantial variations in pig densities. Previous approaches often struggle with complex agricultural environments where lighting conditions, pig postures, and crowding levels create challenging detection scenarios. To address these limitations, we propose EAPC-YOLO (enhanced adaptive pig counting YOLO), a robust architecture integrating density-aware processing with advanced detection optimizations. The method consists of (1) an enhanced YOLOv8 network incorporating multiple architectural improvements for better feature extraction and object localization. These improvements include DCNv4 deformable convolutions for irregular pig postures, BiFPN bidirectional feature fusion for multi-scale information integration, EfficientViT linear attention for computational efficiency, and PIoU v2 loss for improved overlap handling. (2) A density-aware post-processing module with intelligent NMS strategies that adapt to different crowding scenarios. Experimental results on a comprehensive dataset spanning diverse agricultural scenarios (nighttime, controlled indoor, and natural daylight environments with density variations from 4 to 30 pigs) demonstrate our method achieves 94.2% mAP@0.5 for detection performance and 96.8% counting accuracy, representing 12.3% and 15.7% improvements compared to the strongest baseline, YOLOv11n. This work enables robust, accurate pig counting across challenging agricultural environments, supporting precision livestock management.https://www.mdpi.com/2076-2615/15/14/2149pig detectiondensity-aware countingYOLOv8precision livestock farmingcomputer vision
spellingShingle Jian Li
Wenkai Ma
Yanan Wei
Tan Wang
Enhanced YOLOv8 for Robust Pig Detection and Counting in Complex Agricultural Environments
Animals
pig detection
density-aware counting
YOLOv8
precision livestock farming
computer vision
title Enhanced YOLOv8 for Robust Pig Detection and Counting in Complex Agricultural Environments
title_full Enhanced YOLOv8 for Robust Pig Detection and Counting in Complex Agricultural Environments
title_fullStr Enhanced YOLOv8 for Robust Pig Detection and Counting in Complex Agricultural Environments
title_full_unstemmed Enhanced YOLOv8 for Robust Pig Detection and Counting in Complex Agricultural Environments
title_short Enhanced YOLOv8 for Robust Pig Detection and Counting in Complex Agricultural Environments
title_sort enhanced yolov8 for robust pig detection and counting in complex agricultural environments
topic pig detection
density-aware counting
YOLOv8
precision livestock farming
computer vision
url https://www.mdpi.com/2076-2615/15/14/2149
work_keys_str_mv AT jianli enhancedyolov8forrobustpigdetectionandcountingincomplexagriculturalenvironments
AT wenkaima enhancedyolov8forrobustpigdetectionandcountingincomplexagriculturalenvironments
AT yananwei enhancedyolov8forrobustpigdetectionandcountingincomplexagriculturalenvironments
AT tanwang enhancedyolov8forrobustpigdetectionandcountingincomplexagriculturalenvironments