Pig Passage Counting Based on Improved YOLO and HMTC Strategy
Lu Yang, Saisai Wu, Shuqing Han, Xin Chai, Yali Wang, Hongyu Zhang, Guodong ChengAccurate pig counting during herd transfers is fundamental to effective livestock management in large-scale swine production, yet existing methods struggle with bidirectional passages, boundary oscillations, and occlusion in real corridor environments. This study proposes an integrated system combining an improved YOLO-based detection model with a Hysteresis-based Multi-frame Temporal Confirmation Counting Strategy (HMTC). The YOLO11s baseline was enhanced using lightweight RepViT blocks, dynamic upsampling (DySample), and shape-aware bounding box regression (Shape-IoU). The resulting model achieves a mAP50 of 0.982 with a compact architecture of 8.28M parameters, representing a 12.3% reduction relative to the baseline while improving detection accuracy. To address bidirectional counting challenges, the HMTC strategy utilizes hysteresis-based region classification, temporal confirmation, and trajectory verification to suppress boundary jitter and ensure directional correctness. Evaluated on nine videos from a single transfer corridor, the proposed system achieves an overall counting accuracy of 99.21% on this test set and runs in real time on an embedded edge device at over 30 FPS without loss of counting accuracy. Together, the improved detection model and HMTC counting strategy provide a cohesive approach to pig passage counting, validated here under a single transfer-corridor condition; these results offer a promising basis for automated animal inventory management, pending further validation across more diverse farm environments.