高级检索+

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

Lightweight dense sheep detection and counting method based on 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相比,PR、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 knowledge of the number of sheep is of great significance for health management, feed allocation, disease prevention, and production planning in sheep farming. Under large-scale farming conditions, sheep are densely distributed with severe target occlusion and highly similar appearances, leading to low efficiency and accuracy in traditional manual counting methods. To address these challenges, this study proposed a lightweight dense sheep detection and counting model, DMR-YOLO (Dynamic Multi-scale Residual YOLO), which integrated YOLOv8n with knowledge distillation, aiming to achieve non-contact accurate counting of large-scale dense sheep populations. To enhance the model's ability to extract individual features in dense sheep flocks, a Dynamic Multi-scale Residual attention module was designed. Unlike traditional channel attention mechanisms such as ECA that suffered from fixed single-scale convolution kernels, static weight allocation, and unidirectional gradient propagation, the proposed DMR module employed a multi-scale parallel structure. Specifically, it introduced three convolutional kernel branches of sizes 1×3, 1×5, and 1×7 to capture short-range, medium-range, and long-range channel dependencies, respectively. After global average pooling, a fully connected layer consisting of Linear and Softmax operations generated three adaptive dynamic weights to match the three convolution operations. 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 module's output, which combined the original input features with the attention-enhanced features through an adaptive weighting mechanism. This design effectively mitigated the gradient vanishing problem in deep networks and improved training stability. To maintain high detection accuracy while keeping the model lightweight and easily deployable, a knowledge distillation strategy was employed. The pre-trained YOLOv8m, which had high detection accuracy but a large parameter size, was used as the teacher network, while the proposed DMR-YOLO served as the student network. The distillation process introduced a temperature coefficient T to soften the output of the Softmax function, enabling the student network to learn the dark knowledge from the teacher network. Through parameter optimization, the optimal distillation parameters 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 these two losses with the coefficient α. All experiments were conducted on a self-built Tan sheep dataset collected from a breeding farm in Ningxia, China. The dataset contained 1,765 annotated images with a resolution of 1920 × 1080 pixels, covering six typical scenarios: daytime, nighttime, large targets (bounding box area > 0.5% of image area), small targets (bounding box area < 0.2% of image area), 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. Ablation experiments further confirmed the effectiveness of the DMR module and the knowledge distillation strategy. Moreover, compared with YOLOv11m and YOLOv12m, DMR-YOLO achieved superior detection accuracy with approximately 85.2% fewer parameters and 87.9% lower computational cost. The model demonstrates excellent counting accuracy across six typical environmental conditions, 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%, showing strong generalization in complex real-world farm settings. This study provides a theoretical basis and technical support for real-time accurate detection and deployment of large-scale dense sheep flocks.

     

/

返回文章
返回