Abstract:
To solve the problems of high labor costs, low efficiency, and large errors associated with manual egg counting in layer hen farming, this study proposes an innovative egg counting method based on an improved YOLOv11n model and the DeepSORT multi-object tracking algorithm. The proposed method is systematically organized into three main functional modules: detection, tracking, and counting.In the detection module, the original YOLOv11n model often suffers from insufficient detection performance under complex farming environments where eggs are frequently occluded, adhered to one another, or exhibit only subtle phenotypic differences between normal and abnormal eggs. To address these issues, an enhanced detection model named YOLO-SR is developed. Specifically, a spatial and channel synergistic attention (SCSA) mechanism is integrated into the C2PSA module of the backbone network. This attention mechanism adaptively recalibrates feature responses along both spatial and channel dimensions, allowing the network to focus on the most discriminative regions of eggs while suppressing irrelevant background information. Additionally, a reparameterized generalized feature pyramid network (RepGFPN) is introduced into the neck network of YOLOv11n. The RepGFPN improves multi-scale feature fusion by leveraging reparameterization techniques that enhance inference speed without sacrificing representation power. These two improvements collectively boost the model’s ability to extract fine-grained features and handle scale variations, leading to a significant increase in detection accuracy for both normal and abnormal eggs under challenging conditions.In the tracking module, to alleviate identity switching that frequently occur during re-identification when eggs are temporarily occluded, the DeepSORT tracking algorithm is employed. Unlike traditional tracking methods that rely solely on motion cues, DeepSORT integrates deep appearance features extracted from a pre-trained convolutional neural network with Kalman filter-based motion estimation. This combination enables robust association of egg detections across consecutive frames, effectively maintaining the continuity of target identities even under prolonged occlusions or rapid movements. The deep appearance feature extractor is fine-tuned on egg image data to ensure discriminative capability for individual eggs.In the counting module, a virtual line-crossing counting mechanism is designed to prevent duplicate counting. Specifically, a counting line is placed at a designated position in the video frame, and an egg is counted only once when its tracked centroid crosses this line from one side to the other. This mechanism works in conjunction with the tracking module to ensure that each egg is counted exactly once, eliminating both false positives and missed counts.Experimental results demonstrate the effectiveness of the proposed approach. The YOLO-SR detector achieves an average precision of 95.4% and an F1 score of 89.0%, which are 1.9 and 0.6 percentage points higher than those of the original YOLOv11n, respectively. The DeepSORT algorithm yields a higher-order tracking accuracy (HOTA) of 93.6%, a multi-object tracking accuracy (MOTA) of 96.4%, and an ID F1 score (IDF1) of 98.2%. Notably, the number of identity switches (IDS) is zero when using DeepSORT, highlighting its robustness in handling occlusions. The overall egg counting system achieves an average counting accuracy of 89.46%, which is 6.66 percentage points higher than that of manual counting, with a root mean square error (RMSE) of 2.37. In conclusion, the method proposed in this study exhibits excellent application potential for real-time egg tracking and counting tasks. It provides effective technical support for automated counting of both normal and abnormal eggs and lays a solid foundation for future research in egg health monitoring and smart poultry management.