DOI: 10.3390/agriculture16161756 ISSN: 2077-0472

Robust Real-Time Pig Detection for Commercial Swine Barns Using an Improved MSCA-RTDETR Model

Wangli Hao, Yifan Chen, Shu’ai Xu, Meng Han, Fuzhong Li

Pig detection in intelligent livestock farming is challenging due to the difficulty of jointly capturing global context and multi-scale features in complex environments. To address this, we propose MSCA-RTDETR (Multi-scale Content-Aware Real-Time Detection Transformer), which enhances the Real-Time Detection Transformer (RTDETR) architecture with two complementary components. First, we introduce a Content-Aware Token Selection (CATS) backbone that uses content-aware weighting and Top-K sparse attention to efficiently model long-range dependencies and global context. Second, we design a Multi-scale Interaction Residual Block (MIRB) that employs parallel convolutional kernels (3×3 and 5×5) to capture fine-grained local details and broad contour information, handling scale variations due to different viewing distances and pig sizes. On a custom dataset of 8070 images (6955 training, 1115 testing) collected from a commercial pig farm, MSCA-RTDETR outperforms existing detectors, improving AP, AP50, and AP75 by 0.6%, 0.3%, and 0.9% respectively over the strong RTDETRv1 baseline. The model demonstrates effective detection on our self-built dataset, offering a practically viable and accurate solution for intelligent livestock farming.

More from our Archive