Shao Xiaobao, Liu Chengcheng, Zhou Zhixuan, Xue Wenjing, Zhang Guoye, Liu Jianyu, Yan Hongwen
College of Information Science and Engineering, Shanxi Agricultural University, Jinzhong 030801, China.
Science & Technology Information and Strategy Research Center of Shanxi, Taiyuan 030024, China.
Animals (Basel). 2024 Apr 19;14(8):1227. doi: 10.3390/ani14081227.
A pig inventory is a crucial component of achieving precise and large-scale farming. In complex pigsty environments, due to pigs' stress reactions and frequent obstructions, it is challenging to count them accurately and automatically. This difficulty contrasts with most current deep learning studies, which rely on overhead views or static images for counting. This research proposes a video-based dynamic counting method, combining YOLOv7 with DeepSORT. By utilizing the YOLOv7 network structure and optimizing the second and third 3 × 3 convolution operations in the head network ELAN-W with PConv, the model reduces the computational demand and improves the inference speed without sacrificing accuracy. To ensure that the network acquires accurate position perception information at oblique angles and extracts rich semantic information, we introduce the coordinate attention (CA) mechanism before the three re-referentialization paths (REPConv) in the head network, enhancing robustness in complex scenarios. Experimental results show that, compared to the original model, the improved model increases the mAP by 3.24, 0.05, and 1.00 percentage points for oblique, overhead, and all pig counting datasets, respectively, while reducing the computational cost by 3.6 GFLOPS. The enhanced YOLOv7 outperforms YOLOv5, YOLOv4, YOLOv3, Faster RCNN, and SSD in target detection with mAP improvements of 2.07, 5.20, 2.16, 7.05, and 19.73 percentage points, respectively. In dynamic counting experiments, the improved YOLOv7 combined with DeepSORT was tested on videos with total pig counts of 144, 201, 285, and 295, yielding errors of -3, -3, -4, and -26, respectively, with an average accuracy of 96.58% and an FPS of 22. This demonstrates the model's capability of performing the real-time counting of pigs in various scenes, providing valuable data and references for automated pig counting research.
生猪存栏量统计是实现精准大规模养殖的关键环节。在复杂的猪舍环境中,由于猪的应激反应和频繁遮挡,准确自动地清点猪的数量具有挑战性。这一困难与当前大多数深度学习研究形成对比,后者依靠俯视视角或静态图像进行计数。本研究提出一种基于视频的动态计数方法,将YOLOv7与DeepSORT相结合。通过利用YOLOv7网络结构并使用PConv对头网络ELAN-W中的第二个和第三个3×3卷积操作进行优化,该模型在不牺牲准确性的情况下降低了计算需求并提高了推理速度。为确保网络在倾斜角度获取准确的位置感知信息并提取丰富的语义信息,我们在头网络的三条重参数化路径(REPConv)之前引入坐标注意力(CA)机制,增强在复杂场景中的鲁棒性。实验结果表明,与原始模型相比,改进后的模型在倾斜、俯视和所有猪计数数据集上的平均精度均值(mAP)分别提高了3.24、0.05和1.00个百分点,同时计算成本降低了3.6 GFLOPS。增强后的YOLOv7在目标检测方面优于YOLOv5、YOLOv4、YOLOv3、Faster RCNN和SSD,mAP分别提高了2.07、5.20、2.16、7.05和19.73个百分点。在动态计数实验中,改进后的YOLOv7与DeepSORT相结合,在猪总数分别为144、201、285和295头的视频上进行测试,误差分别为-3、-3、-4和-26,平均准确率为96.58%,帧率为22。这表明该模型能够在各种场景下对猪进行实时计数,为猪自动计数研究提供了有价值的数据和参考。