高级检索+

融合DMR-YOLO与知识蒸馏的轻量化密集羊群检测方法

Detecting and counting dense sheep using Lightweight DMR-YOLO and knowledge distillation

  • 摘要: 及时、准确地掌握羊群数量,对羊群健康管理、饲料投喂、疾病防控以及生产计划的制定具有重要意义。大规模养殖条件下,羊群分布密集,目标遮挡严重且外观高度相似,传统人工计数效率和准确率低。为实现大规模密集羊群的非接触精确计数,该研究提出了一种融合YOLOv8n与知识蒸馏的轻量化密集羊群检测计数模型DMR-YOLO,为增强模型在密集羊群下的个体特征提取能力,设计了动态多尺度残差(dynamic multi-scale residual,DMR)注意力模块。该模块利用多尺度卷积提取不同感受野下的通道特征,通过自适应动态权重融合特征,并在输出端引入残差连接结构,有效缓解模块在深层网络中的梯度衰减问题。为使模型在参数量低、易于部署的前提下,仍保持较高的检测精度,研究以YOLOv8m为教师网络,采用知识蒸馏优化学生模型性能。试验结果表明,DMR-YOLO经过知识蒸馏后,mAP@0.5和mAP@0.5-0.95分别为98.10%和92.10%,精确率(P)和召回率(R)分别为95.80%和95.10%,参数量为3.04 M,浮点计算量为8.26 G。与基准模型YOLOv8n相比,P、R、mAP@0.5与mAP@0.5-0.95分别提高了1.70、1.80、0.20、5.60个百分点;与教师模型YOLOv8m相比,浮点计算量和参数量分别降低了89.6%和88.2%,其他指标与教师模型水平相近。模型在6类典型环境中均表现出良好的计数准确度,平均计数误差值为1.96只,平均计数错误率为3.82%,平均计数准确率为96.31%,在复杂牧场实际环境下表现出良好的泛化性,该研究可为大规模密集羊群的实时精确检测与部署提供理论依据与技术支持。

     

    Abstract: Timely and accurate detection and counting of dense sheep are often required for health management, feed allocation, disease prevention, and production planning in livestock farming. However, conventional manual counting cannot fully meet the requirements of large-scale farming in recent years. Particularly, sheep can be densely distributed, with severe target occlusion and highly similar appearances, leading to low efficiency and accuracy. In this study, a lightweight model, DMR-YOLO (Dynamic Multi-scale Residual YOLO), was proposed for the detection and counting of dense sheep. YOLOv8n was also integrated with knowledge distillation. Non-contact accurate counting was performed on large-scale populations of closely packed sheep. A Dynamic Multi-Scale Residual (DMR) attention was designed to extract individual features from dense sheep flocks. A multi-scale parallel structure was employed to reduce the issues from fixed single-scale convolution kernels, static weight allocation, and unidirectional gradient propagation in conventional channel attention mechanisms, such as Efficient Channel Attention (ECA). Specifically, three convolutional kernel branches were introduced with the sizes 1×3, 1×5, and 1×7 to capture short-, medium- and long-range channel dependencies, respectively. Three adaptive dynamic weights were generated to match the three convolution operations after global average pooling. A fully connected layer consisted of Linear and Softmax functions. The outputs of the multi-scale convolution group were then weighted and fused, followed by Sigmoid reconstruction. Furthermore, a residual connection was introduced at the output. The original input features were combined with the attention-enhanced features using an adaptive weighting mechanism. The training stability was improved to mitigate gradient vanishing in deep networks. Knowledge distillation was employed to maintain high detection accuracy for the lightweight and easily deployable model. The teacher network was taken as the pre-trained YOLOv8m with high detection accuracy but a large parameter size. The DMR-YOLO served as the student network. A temperature coefficient was introduced to soften the output of the softmax function during distillation. The student network was implemented to learn the dark knowledge from the teacher network. The optimal parameters of distillation were determined as T = 7 and α = 0.6. The soft loss was calculated using Kullback-Leibler divergence, while the hard loss was calculated using the cross-entropy loss function. The final distillation loss function combined the two losses with the coefficient α. All experiments were conducted on a self-built tan sheep dataset from a breeding farm in Ningxia, China. The dataset contained 1,765 annotated images with a resolution of 1920 × 1080 pixels. Six typical scenarios included daytime, nighttime, large targets (bounding box area > 0.5% of image area), small targets (bounding box area < 0.2% of image area), and indoor and outdoor environments. The dataset was divided into training, validation, and test sets at a ratio of 8:1:1. Experimental results demonstrated that after knowledge distillation, DMR-YOLO achieved a mAP@0.5 of 98.10% and a mAP@0.5-0.95 of 92.10%, a precision of 95.80% and a recall of 95.10%, with only 3.04 million parameters and 8.26 GFLOPs. Compared with the baseline YOLOv8n model, precision, recall, mAP@0.5, and mAP@0.5-0.95 increased by 1.70, 1.80, 0.20, and 5.60 percentage points, respectively. Compared with the teacher model YOLOv8m, the computational cost and parameters were reduced by 89.6% and 88.2%, respectively, while other performance metrics nearly reached the teacher model's level. Furthermore, ablation experiments confirmed that better performance was achieved with the DMR module and knowledge distillation, with superior accuracy of 85.2% and 87.9% and lower computational cost, compared with YOLOv11m and YOLOv12m. The excellent counting accuracy was also obtained under six typical scenarios, with an average counting error of 1.96 sheep, an average counting error rate of 3.82%, and an average counting accuracy of 96.31%, indicating strong generalization in complex real-world farm settings. This finding can provide a theoretical basis and technical support for real-time accurate detection and deployment of large-scale dense sheep flocks.

     

/

返回文章
返回