基于改进的YOLOv5的带式磨削表面缺陷检测
Surface Defect Detection of Belt Grinding Based on Improved YOLOv5
DOI: 10.12677/MOS.2023.125387, PDF, HTML, XML, 下载: 363  浏览: 579 
作者: 赵霆霆, 周 骅, 赵 麒:贵州大学大数据与信息工程学院,贵州 贵阳
关键词: 深度学习表面缺陷检测定量特征带式磨削Deep Learning Surface Defect Detection Quantitative Feature Belt Grinding
摘要: 由于带式磨削表面缺陷的复杂性和多样性,表面缺陷的自动识别和定量表征仍然是一个需要解决的问题。为了对带式磨削中的表面缺陷进行检测,提出了一种多分类识别与量化的方法。利用YOLOv5算法进行缺陷检测,得到缺陷的分类和位置信息。首先在模型中引入CBAM注意力机制提升模型对细小缺陷的感知能力,其次对主干网络中的标准卷积替换成深度可分离卷积以降低模型参数量,最后引入SiOU边界损失函数加速模型收敛和提升准确率。最终改进后模型的mAP@0.5达到90.7%。其检测效率高达158.4 FPS,可进行后续实时监控。结果表明,本文提出改进的YOLOv5模型在带式磨削表面缺陷检测上具有可靠性和实时准确性。
Abstract: Due to the complexity and diversity of surface defects in belt grinding, the automatic identification and quantitative characterization of surface defects are still a problem to be solved. In order to de-tect surface defects in belt grinding, a multi-classification recognition and quantification method is proposed. YOLOv5 algorithm is used for defect detection to obtain the classification and location in-formation of defects. Firstly, the CBAM attention mechanism is introduced into the model to im-prove the perception ability of the model for small defects. Secondly, the standard convolution in the backbone network was replaced by the depthwise separable convolution to reduce the amount of model parameters. Finally, the SiOU boundary loss function was introduced to accelerate model convergence and improve accuracy. Finally, the mAP@0.5 of the improved model reaches 90.7%. The detection efficiency is up to 158.4 FPS, which can be used for subsequent real-time monitoring. The results show that the improved YOLOv5 model proposed in this paper has reliability and re-al-time accuracy in belt grinding surface defect detection.
文章引用:赵霆霆, 周骅, 赵麒. 基于改进的YOLOv5的带式磨削表面缺陷检测[J]. 建模与仿真, 2023, 12(5): 4247-4256. https://doi.org/10.12677/MOS.2023.125387

1. 引言

砂带磨削由于其灵活、低温的加工特点,逐渐被应用于制造高精度设备,如航空发动机叶片、燃烧室等 [1] [2] [3] 。工作条件下砂带的磨损、脱落及不合理工艺因素的存在,不可避免地导致磨削表面出现各种缺陷 [4] 。表面缺陷会严重影响工件的表面质量和执行其预期功能的能力 [5] 。工件表面纹理图像为加工过程提供了丰富的工艺信息,对其表面缺陷进行识别和定量分析有利于进一步改进砂带磨削工艺 [6] 。

从缺陷识别和分类的角度来看,传统方法倾向于将人工特征与机器学习相结合。这些方法大多存在鲁棒性不足、计算量大、检测结果准确率低等问题 [7] [8] [9] 。近年来,基于深度学习理论的目标检测模型在工业缺陷识别中得到了广泛应用,有效地解决了传统方法的不足 [10] 。在目标检测效果方面,YOLOv5是本研究中用于磨带表面缺陷多分类识别的YOLO系列中最先进的方法,优于许多复杂的目标检测模型。然而,定量缺陷特征也是缺陷分析的重点。通过对缺陷的定量描述,可以进一步建立表面缺陷、加工工艺、使用性能之间的关系,进行更深入的分析 [11] [12] [13] [14] 。

文献 [15] 中结合长度、深度等几何特征对疲劳缺陷进行定量评价。文献 [16] 为了有效控制合金铸坯各种类型的表面缺陷,采用裂纹长度、裂纹深度和覆盖裂纹的外矩形的最小面积来定量表征缺陷。文献 [17] 描述了利用工件表面烧伤的CCD图像定量评估烧伤的可行性。文献 [18] 提出了一种实用的评价方法,使用色调、饱和度和值(HSV)颜色模型对磨削烧伤样品的颜色图像进行比较。

2. 基于改进的YOLOv5检测模型

2.1. 缺陷和数据集的描述

本研究中讨论的缺陷类别如图1所示。由于磨砂带表面的磨粒磨损脱落,磨砂带上的磨粒在磨削过程中以不同的深度进入工件,在某些地方留下较深的磨痕,如图1(b)所示。深磨痕缺陷加剧了工件的疲劳损伤和腐蚀。

在磨料磨损严重且冷却不足的情况下,不能排出磨削过程中产生的能量,这会使磨削材料软化并与材料表面粘附,影响工件表面粗糙度(图1(e))。如图1(f)所示,磨料颗粒位移会在磨削过程中产生非磨削方向划痕。如果磨削的热量过高,磨削表面也会产生严重的烧伤,如图1(f)和图1(g)所示。表面烧伤破坏工件的表面组织,导致氧化变质。此外,它很容易引起表面腐蚀,并显着降低工件的使用能力和寿命。根据不同烧伤程度的颜色差异,烧伤缺陷分为重度烧伤(蓝黑色)、中度烧伤(蓝色和浅蓝色)和轻度烧伤(浅黄色和棕色)。

此外,磨削表面还存在凸起(图1(c))、凹坑(图1(d))等缺陷,从不同方面影响工件的性能。在此基础上,建立了带式磨削表面缺陷数据集,对磨削表面缺陷进行分析。本文数据集共包含2114张不同缺陷的样本图像,数据集参数如表1所示。

Figure 1. Surface defects of abrasive belt grinding. (a) Normal grinding marks, (b) Deep grinding marks, (c) Bumps, (d) Pits, (e) Adhesion, (f) Scratches, and (g) Burns (severe, moderate, and mild burns)

图1. 砂带磨削的表面缺陷。(a) 正常磨痕,(b) 深磨痕,(c) 凸起,(d) 凹坑,(e) 粘连,(f) 划痕,(g) 烧伤(重度、中度、轻度烧伤)

Table 1. Parameters of the dataset

表1. 数据集参数

2.2. YOLOv5目标检测模型

YOLOv5s网络结构包含Backbone、Neck以及预测头三个部分,具体结构如图2所示。Backbone是检测网络的主干部分,由Conv、C3层以及基于SPP改进的SPPF组成。在最新版本的YOLOv5中,原有的Focus层被替换成6 × 6的卷积层,二者的计算量是等价的。但在一些GPU设备中,6 × 6的卷积层会更高效。C3层则包含两种结构,二者的区别在于BottleNeck的连接方式不同。C3_1中BottleNeck连接使用了残差结构,C3_2中BottleNeck则没有使用残差结构。SPPF模块使用四个不同尺寸的最大池化层进行串行下采样,进行多尺度特征融合,增大感受野。相比于SPP模块的并行最大池化操作,SPPF的串行操作效率更高。

Neck网络包含FPN [19] 和PAN [20] 两种结构。FPN结构能够获得更加鲁棒的语义信息,并使强语义特征信息从高维度映射至低维度。FPN分别利用浅层特征和深层特征区分简单目标和复杂目标。PAN则是将低层特征信息自低维度向高维度进行映射,提高模型的定位信息感知能力。二者组合生成特征金字塔,增强模型对于不同大小和缩放尺度目标的检测能力。

预测头部分输出包含三个检测层,以检测不同尺寸的检测对象。每个检测层输出检测对象的类别概率,对象得分,以及检测目标的边界框位置信息。其中边界框的损失函数为CIoU_Loss。通过采用不同的权重,能够平衡不同尺度的损失。最终生检测对象的预测边界框,并在原始图像中进行标记。

Figure 2. Structure diagram of YOLOv5

图2. YOLOv5结构图

2.3. 注意力机制

注意力机制(Convolutional Block Attention Module, CBAM)是模仿人类在浏览时专注感兴趣的事物而忽视无关事物的特性。CBAM注意力机制由通道注意力与空间注意力串联组成,结构示意图如图3所示。其中通道注意力捕获有意义的输入特征,空间注意力捕获最具信息量的特征。注意力机制就是聚焦图像的局部信息,使算法模型更加关注图像的特定区域,更有可能识别出目标的细节。本文在主干网络中引入混合注意力机制CBAM模块,使模型专注于提取瑕疵特征,降低背景颜色和纹理信息对检测结果的影响。

Figure 3. Schematic diagram of CBAM attention mechanism

图3. CBAM注意力机制示意图

通道注意力模块中,输入的特征F大小为H × W × C,分别为输入特征的长、宽以及通道数。输入特征分别进行最大池化和平均池化操作,然后分别输入共享权值的多层感知机(Muti-Layer Perception, MLP),MLP使模型能够处理更普遍的函数关系,其中隐藏层的激活函数为ReLU。此后将MLP的输出通过Sigmoid激活函数进行计算加权和并加上偏置来确定神经元是否应该被激活,最后将输出的权重系数Mc与输入特征进行乘法操作,得到通道注意力的新特征,其具体结构图如图4所示。

Figure 4. Channel attention module

图4. 通道注意力模块

空间注意力模块如图5所示,将上一步操作得到的结果作为空间注意力模块的输入特征,输入特征在经过最大池化和平均池化后,在维度上进行拼接操作,得到H × W × 2的特征图,之后与卷积核为7 × 7,Sigmoid激活函数的卷积层进行卷积,得到权重系数Ms,最后将输出的权重系数Ms与空间注意力模块的输入特征进行相乘,得到新的空间注意力特征。

Figure 5. Spatial attention module

图5. 空间注意力模块

基于上述原因,本文在backbone部分中第二、三和四个C3模块后分别引入CBAM注意力机制模块,以此增强网络对细小纹理的感受能力。

2.4. 深度可分离卷积

谷歌的Xception和MobileNet论文中描述了深度可分离卷积。其核心思想是将一个完整的卷积操作分解为两个步骤,即深度卷积和逐点卷积。深度可分离卷积的结构如图6所示。在卷积步骤中,标准卷积对输入进行滤波,并将其组合为一组新的输出。但深度可分离卷积将其分为两层。深度卷积对每个输入通道应用单个滤波器,而逐点卷积使用1 × 1卷积来组合不同深度卷积的输出。这种分解过程可以大大减少计算量和模型大小。因此,为了有效降低模型参数量和计算量,本文将深度可分离卷积替换掉backbone中的标准卷块。

Figure 6. Schematic of the depthwise separable convolutional structure

图6. 深度可分离卷积结构示意图

2.5. 损失函数改进

CIoU_Loss作为YOLOv5模型中边界框的损失函数,引入了重叠面积、中心点距离和纵横比等度量。解决了预测框在目标框内以及二者面积相等时的问题。CIoU_Loss的定义如下:

L CIou = 1 IoU + R CIoU (1)

R CIoU 作为预测框与目标框的惩罚项,能够进一步提高性能, R CIoU 定义如公式5所示:

R CIoU = ρ 2 ( b , b g t ) c 2 + a v v = 4 π 2 ( arctan w g t h g t arctan w h ) 2 a = v ( 1 IoU ) + v (2)

其中 ( b , b g t ) 分别为预测框和目标框的中心位置,v是测量纵横比的一致性参数,a是一个积极的权衡参数, ρ ( ) 是欧几里得距离,c是覆盖预测框和目标框的最小检测框的对角线长度。

CIoU_Loss仅考虑了重叠面积、中心点距离和纵横比等度量,并没有从角度回归的方向考虑。但在实际训练过程中,由于预测框的震荡幅度较大,最终导致预测框回归收敛较慢。为解决这一问题,SIoU_Loss通过引入期望回归之间的向量角度,重新定义了惩罚度量。SIoU_Loss使得神经网络在回归收敛速度以及推理精度上显著提升。SIoU_Loss的定义如下:

L b o x = 1 IoU + Δ + Ω 2 (3)

由于引入角度回归, Δ 为重新定义的distancecost,详细定义公式如下:

Δ = t = x , y ( 1 e γ ρ t ) ρ x = ( b c x g t b c x c w ) 2 , ρ y = ( b c y g t b c y c h ) 2 γ = 2 Λ Λ = 1 2 sin 2 ( arcsin ( x ) π 4 ) (4)

其中 Λ 为angle cost, Ω 为Shape cost,x是预测框与目标框y轴坐标的差值和两点之间的距离的比值。因此,我们将SIoU_Loss添加至YOLOv5s预测头部分,以替换原始的边界框损失函数。

3. 评价指标

在本文中,为了验证模型能够精确的检测出带式磨削表面缺陷和评估模型性能,本文使用了一些评价指标,包括精度,召回率,平均检测精度mAP。其定义分别如下:

Precision = TP TP + FP × 100 % (5)

Recall = TP TP + FN × 100 % (6)

AP = 0 1 P ( R ) d R (7)

m AP = i = 1 N AP i N (8)

在上述公式中,TP表示正确分类的正例数,TN表示正确分类的反例数,FP表示错误分类的正例数,FN表示错误分类的反例数。公式中AP代表单个类别缺陷的检测准确率。mAP@0.5" target="_self">mAP@0.5代表交并比(Intersection over Union, IoU)设置为0.5时,所有缺陷类别的平均检测准确率。mAP@0.5" target="_self">mAP@0.5:0.95则代表IoU设置在不同的阈值下(0.5~0.95,步长为0.05)所有缺陷类别的平均检测准确率。

4. 实验结果与分析

4.1. 消融实验

在对上述部分进行对比实验后,我们仍需研究网络结构的变化对模型整体性能的影响。为此,我们设置了如下的消融实验。实验结果如表2所示。

表2中,展示了不同改进网络结构的变化对模型性能的影响。从表2中可知,在没有添加任何改进点时,基准模型的mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5仅有84.1%,参数量为7.2M,FLOPs为16.5G,FPS为154.1,在引入CBAM注意力机制模块后,mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5提升了大约3.2%,参数量仅提升了0.1M,FLOPs虽然上升了0.6G,但是FPS提升了10.2。在引入CBAM基础之上,DSconv的引入大幅度降低了模型的参数量,模型参数量下降了约为0.8M,虽然FPS下降了大约4.1,但同时mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5提升了1.4%。在最后替换掉原始的损失函数,引入SiOU边界损失函数,mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5提升至90.7%,参数量也仅有6.8M,FLOPs为16.3G,FPS为158.4。此外,改进前后最终模型的损失值曲线和mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5" target="_self">mAP@0.5曲线如图7所示。不难从图7中看出,改进后的模型在检测性能上有了明显的提升。

Table 2. Ablation experiments

表2. 消融实验

Figure 7. Loss value plot and mAP@0.5 plot

图7. 损失值曲线图和mAP@0.5曲线图

4.2. 不同模型对比实验

为了更好地观察改进后YOLOv5模型的检测效果,将其与其他主流目标检测算法进行比较。通过测量各模型的mAP、Parameters、FLOPs和FPS,对各模型进行定量比较分析。如表3所示,YOLOv5在数据集上的mAP@0.5值达到0.907,远远高于其他主流算法模型。在检测速度方面,其158.4的FPS评分优于其他所有模型。此外,参数和FLOPs的大小保持适度。结果表明,改进后的YOLOv5在砂带磨削表面缺陷数据集上的综合性能优于其他主流目标检测模型。为高效、高精度的表面缺陷识别与分析提供了可能。

Table 3. Comparative experimental results of different models

表3. 不同模型对比实验结果

5. 总结

为了提取表面缺陷的特征信息,分析砂带磨削的表面质量,本文提出了一种基于YOLOv5的砂带磨削表面缺陷检测方法。采用了砂带磨削表面缺陷数据集。利用YOLOv5准确提取磨削表面缺陷的分类和定位信息,在模型中引入CBAM注意力机制提升模型对细小缺陷的感知能力,其次对主干网络中的标准卷积替换成深度可分离卷积以降低模型参数量,最后引入SiOU边界损失函数加速模型收敛和提升准确率。通过消融实验最终表明,改进后的模型的mAP@0.5达到90.7%。其检测效率高达158.4 FPS,可进行后续实时监控,同时验证了本文提出模型的科学性和有效性。

参考文献

[1] Zhou, K., Xiao, G.J., Xu, J.Y. and Huang, Y. (2023) Wear Evolution of Electroplated Diamond Abrasive Belt and Cor-responding Surface Integrity of Inconel 718 during Grinding. Tribology International, 177, Article ID: 107972.
https://doi.org/10.1016/j.triboint.2022.107972
[2] He, Y., Xiao, G., Zhu, S., et al. (2023) Surface Formation in Laser-Assisted Grinding High-Strength Alloys. International Journal of Machine Tools and Manufacture, 186, Article ID: 104002.
https://doi.org/10.1016/j.ijmachtools.2023.104002
[3] Xiao, G., Xing, J. and Zhang, Y. (2021) Surface Rough-ness Prediction Model of GH4169 Superalloy Abrasive Belt Grinding Based on Multilayer Perceptron (MLP). Procedia Manufacturing, 54, 269-273.
https://doi.org/10.1016/j.promfg.2021.07.042
[4] Fan, W., Wang, J., Cheng, J., et al. (2020) Dynamic Contact Modeling Considering Local Material Deformation by Grit Indentation for Abrasive Belt Rail Grinding. The Internation-al Journal of Advanced Manufacturing Technology, 108, 2165-2176.
https://doi.org/10.1007/s00170-020-05553-x
[5] Huang, C., Wang, G., Song, H., Li, R.S. and Zhang, H.O. (2022) Rapid Surface Defects Detection in Wire and Arc Additive Manufacturing Based on Laser Profilometer. Measurement, 189, Article ID: 110503.
https://doi.org/10.1016/j.measurement.2021.110503
[6] Yeung, C.C. and Lam, K.M. (2022) Efficient Fused-Attention Model for Steel Surface Defect Detection. IEEE Transactions on Instrumentation and Measurement, 71, Article No. 2510011.
https://doi.org/10.1109/TIM.2022.3176239
[7] Wu, B., Zhou, J., Yang, H., et al. (2021) An Ameliorated Deep Dense Convolutional Neural Network for Accurate Recognition of Casting Defects in X-Ray Images. Knowledge-Based Systems, 226, Article ID: 107096.
https://doi.org/10.1016/j.knosys.2021.107096
[8] Feng, Z.X., Li, Y.G., Sun, B., Yang, C.H. and Huang, T.W. (2022) A Multimode Mechanism-Guided Product Quality Estimation Approach for Multi-Rate Industrial Processes. In-formation Sciences, 596, 489-500.
https://doi.org/10.1016/j.ins.2022.02.041
[9] Suo, X., Liu, J., Dong, L., et al. (2021) A Machine Vision-Based Defect Detection System for Nuclear-Fuel Rod Groove. Journal of Intelligent Manufacturing, 33, 1649-1663.
[10] Xu, R., Hao, R. and Huang, B. (2022) Efficient Surface Defect Detection Using Self-Supervised Learning Strategy and Seg-mentation Network. Advanced Engineering Informatics, 52, Article ID: 101566.
https://doi.org/10.1016/j.aei.2022.101566
[11] Wang, C.Y., Bochkovskiy, A. and Liao, H.Y.M. (2023) YOLOv7: Trainable Bag-of-Freebies Sets New State-of-the-Art for Real-Time Object Detectors. Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, Oxford, UK, 15-17 September 2023, 7464-7475.
[12] Snow, Z., Reutzel, E.W. and Petrich, J. (2022) Correlating in-situ Sensor Data to Defect Locations and Part Quality for Addi-tively Manufactured Parts Using Machine Learning. Journal of Materials Processing Technology, 302, Article ID: 117476.
https://doi.org/10.1016/j.jmatprotec.2021.117476
[13] Wang, P., Chen, D., Fan, J., et al. (2022) Study on the Influence of Process Parameters on High Performance Ti-6Al-4V Parts in Laser Powder Bed Fusion. Rapid Proto-typing Journal, 28, 1655-1676.
https://doi.org/10.1108/RPJ-09-2021-0235
[14] Gim, J., Yang, H. and Turng, L.S. (2023) Transfer Learning of Machine Learning Models for Multi-Objective Process Optimization of a Transferred Mold to Ensure Efficient and Ro-bust Injection Molding of High Surface Quality Parts. Journal of Manufacturing Processes, 87, 11-24.
https://doi.org/10.1016/j.jmapro.2022.12.055
[15] Tong, Z., Xie, S., Chen, H., et al. (2022) Quantitative Mapping of Depth Profile of Fatigue Cracks Using Eddy Current Pulsed Thermography Assisted by PCA and 2D Wavelet Trans-formation. Mechanical Systems and Signal Processing, 175, Article ID: 109139.
https://doi.org/10.1016/j.ymssp.2022.109139
[16] Li, X.C., Tang, Y.C., Zhu, W.X., Liu, J. and Wang, X.L. (2014) Research on Criterion and Prediction of Surface Defects in Alloy Steel Casting Slab. Advanced Materials Research, 1049, 23-26.
https://doi.org/10.4028/www.scientific.net/AMR.1049-1050.23
[17] Chen, J.Q., Qiang, H., Wu, J.H., Xu, G.W. and Wang, Z.K. (2021) Navigation Path Extraction for Greenhouse Cucumber-Picking Robots Using the Prediction-Point Hough Transform. Computers and Electronics in Agriculture, 180, Article ID: 105911.
https://doi.org/10.1016/j.compag.2020.105911
[18] Song, S.B., Liu, J.F., Ni, H.Y., et al. (2020) A New Automatic Thresholding Algorithm for Unimodal Gray-Level Distribution Images by Using the Gray Gradient Information. Journal of Petroleum Science and Engineering, 190, Article ID: 107074.
https://doi.org/10.1016/j.petrol.2020.107074
[19] Lin, T.Y., Dollár, P., Girshick, R., et al. (2017) Feature Pyramid Networks for Object Detection. Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Hon-olulu, 21-26 July 2017, 936-944.
https://doi.org/10.1109/CVPR.2017.106
[20] Liu, S., Qi, L., Qin, H.F., Shi, J.P. and Jia, J.Y. (2018) Path Aggre-gation Network for Instance Segmentation. 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition, Salt Lake City, 18-23 June 2018, 8759-8768.
https://doi.org/10.1109/CVPR.2018.00913