Please wait a minute...
浙江大学学报(工学版)  2023, Vol. 57 Issue (3): 455-465    DOI: 10.3785/j.issn.1008-973X.2023.03.003
计算机与控制工程     
基于改进YOLOv5的电子元件表面缺陷检测算法
曾耀(),高法钦*()
浙江理工大学 信息科学与工程学院,浙江 杭州 310018
Surface defect detection algorithm of electronic components based on improved YOLOv5
Yao ZENG(),Fa-qin GAO*()
School of Information Science and Engineering, Zhejiang Sci-Tech University, Hangzhou 310018, China
 全文: PDF(1697 KB)   HTML
摘要:

目标检测模型在电子元件生产环境中的实时检测能力不佳,为此采用GhostNet替换YOLOv5的主干网络. 针对电子元件表面缺陷存在小目标及尺度变化较大的目标的情况,在YOLOv5主干网络中加入坐标注意力机制,在避免大量计算资源消耗的前提下增强感受野,将坐标信息嵌入通道注意力中以提升模型对目标的定位. 使用加权双向特征金字塔网络结构替换YOLOv5特征融合模块中的特征金字塔网络(FPN)结构,提升多尺度加权特征的融合能力. 在自制缺陷电子元件数据集上的实验结果表明,改进的GCB-YOLOv5模型平均精度达到93%,平均检测时间为33.2 ms,相比于原始YOLOv5模型,平均精度提高了15.0%,平均时间提升了7 ms,可以同时满足电子元件表面缺陷检测精度与速度的需求.

关键词: 目标检测网络深度学习电子元件表面缺陷YOLOv5注意力机制    
Abstract:

For the poor real-time detection capability of the current object detection model in the production environment of electronic components, GhostNet was used to replace the backbone network of YOLOv5. And for the existence of small objects and objects with large scale changes on the surface defects of electronic components, a coordinate attention module was added to the YOLOv5 backbone network, which enhanced the sensory field while avoiding the consumption of large computational resources. The coordinate information was embedded into the channel attention to improve the object localization of the model. The feature pyramid networks (FPN) structure in the YOLOv5 feature fusion module was replaced with a weighted bi-directional feature pyramid network structure, to enhance the fusion capability of multi-scale weighted features. Experimental results on the self-made defective electronic component dataset showed that the improved GCB-YOLOv5 model achieved an average accuracy of 93% and an average detection time of 33.2 ms, which improved the average accuracy by 15.0% and the average time by 7 ms compared with the original YOLOv5 model. And the improved model can meet the requirements of both accuracy and speed of electronic component surface defect detection.

Key words: object detection network    deep learning    surface defect of electronic component    YOLOv5    attention module
收稿日期: 2022-05-30 出版日期: 2023-03-31
CLC:  TP 391.4  
基金资助: 浙江省教育厅一般科研项目(专业学位专项)(Y202147956)
通讯作者: 高法钦     E-mail: yaozeng2019@163.com;gfqzjlg@126.com
作者简介: 曾耀(1999—),男,硕士生,从事目标检测研究. orcid.org/0000-0003-1417-7723. E-mail: yaozeng2019@163.com
服务  
把本文推荐给朋友
加入引用管理器
E-mail Alert
作者相关文章  
曾耀
高法钦

引用本文:

曾耀,高法钦. 基于改进YOLOv5的电子元件表面缺陷检测算法[J]. 浙江大学学报(工学版), 2023, 57(3): 455-465.

Yao ZENG,Fa-qin GAO. Surface defect detection algorithm of electronic components based on improved YOLOv5. Journal of ZheJiang University (Engineering Science), 2023, 57(3): 455-465.

链接本文:

https://www.zjujournals.com/eng/CN/10.3785/j.issn.1008-973X.2023.03.003        https://www.zjujournals.com/eng/CN/Y2023/V57/I3/455

图 1  YOLOv5-6.0的网络结构
图 2  自制数据集使用Mosaic进行数据增强的结果
图 3  自制数据集使用Copy-Paste进行数据增强的结果
图 4  传统卷积与Ghost模块卷积
图 5  Ghost瓶颈层的2种结构
图 6  改进CSP_1的结构
图 7  坐标注意力模块
图 8  3种特征金字塔结构的对比
图 9  自制电子元件表面缺陷数据集展示
配置对象 配置内容
操作系统 Windows 10
处理器 NVIDIA GeForce GTX 1050
开发环境 PyCharm
深度学习框架 Pytorch 1.7.1
CUDA Cuda 10.1
CUDNN Cudnn 7.6.5
采样相机 海康工业相机MV-CE050-31GM
表 1  YOLOv5模型训练实验环境配置表
模型 权重大小/106 Np /106 GFLOPs mAP@0.5 RF/(帧·s?1)
YOLOv5s 13.70 7.02 15.9 0.809 25
YOLOv5m 68.90 34.00 50.0 0.824 14
YOLOv5l 147.00 73.20 111.4 0.833 9
YOLOv5x 269.00 134.20 209.8 0.846 5
YOLOv5s-Mobilenet-small 7.17 3.25 6.0 0.857 32
YOLOv5s-Shufflenet 1.97 3.79 7.9 0.887 34
GCB-YOLOv5 11.60 5.90 14.0 0.930 30
表 2  不同算法在自制数据集上的缺陷检测实验对比结果
图 10  2种模型在自制电子元件表面缺陷数据集上的缺陷检测结果对比
模型 mAP@0.5
轧入氧化皮 划痕
YOLOv5s 0.608 0.842
GCB-YOLOv5 0.728 0.925
表 3  2种模型在东北大学热轧带钢表面缺陷数据集上的对比实验结果
图 11  2种模型在东北大学热轧带钢表面缺陷数据集上的缺陷检测结果对比
模型 Ghostnet替换主干 加入注意力模块 修改特征金字塔 mAP@0.5 mAP@0.5 RF/(帧·s?1)
划伤类 压印类
YOLOv5s × × × 0.809 0.766 0.852 25
模型一 × × 0.823 0.771 0.875 37
模型二 × × 0.890 0.853 0.927 24
模型三 × × 0.854 0.804 0.894 21
GCB-YOLOv5 0.930 0.887 0.972 30
表 4  YOLOv5s加入不同模块的消融实验结果
1 王宇, 吴智恒, 邓志文, 等 基于机器视觉的金属零件表面缺陷检测系统[J]. 机械工程与自动化, 2018, (4): 210- 211+214
WANG Yu, WU Zhi-heng, DENG Zhi-wen, et al Metal component surface defect detection system based on machine vision[J]. Mechanical Engineering and Automation, 2018, (4): 210- 211+214
doi: 10.3969/j.issn.1672-6413.2018.04.088
2 HO C C, SU E, LI P, et al Machine vision and deep learning based rubber gasket defect detection[J]. Advances in Technology Innovation, 2020, 5 (2): 76- 83
doi: 10.46604/aiti.2020.4278
3 李璟钰, 肖俊良, 付晗, 等 基于机器视觉的导光板表面微小缺陷检测[J]. 信息系统工程, 2021, (2): 65- 69
LI Jing-yu, XIAO Jun-liang, FU Han, et al Detection of small defects on the surface of light guide plates[J]. China CIO News, 2021, (2): 65- 69
4 戴君洁. 基于机器视觉的目标识别和表面缺陷检测研究[D]. 大理: 大理大学, 2021.
DAI Jun-jie. Research on object recognition and surface defect detection based on machine vision [D]. Dali: Dali University, 2021.
5 LIU W, ANGUELOV D, ERHAN D, et al. SSD: single shot MultiBox detector [EB/OL]. [2022-04-07]. https://arxiv.org/pdf/1512.02325.pdf.
6 REDMON J, DIVVALA S, GIRSHICK R, et al. You only look once: unified, real-time object detection [C]// Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. Las Vegas: IEEE, 2016: 779-788.
7 GIRSHICK R, DONAHUE J, DARRELL T, et al. Rich feature hierarchies for accurate object detection and semantic segmentation [C]// Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. Columbus: IEEE, 2014: 580-587.
8 GIRSHICK R. Fast R-CNN [C]// 2015 IEEE International Conference on Computer Vision. Santiago: IEEE, 2015: 1440-1448.
9 REN S Q, HE K M, GIRSHICK R, et al Faster R-CNN: towards real-time object detection with region proposal networks[J]. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2017, 39 (6): 1137- 1149
doi: 10.1109/TPAMI.2016.2577031
10 HE K M, GKIOXARI G, DOLLÁR P, et al. Mask R-CNN [C]// 2017 IEEE International Conference on Computer Vision. Venice: IEEE, 2017: 2980−2988.
11 黄海新, 金鑫. 基于YOLOv4的小目标缺陷检测[J]. 电子世界, 2021(5): 146-147.
HUANG Hai-xin, JIN Xin. Detection of small object defect based on YOLOv4 [J]. Electronics World, 2021(5): 146-147.
12 刘聪. 基于卷积神经网络的微小零件表面缺陷检测技术研究[D]. 哈尔滨: 哈尔滨理工大学, 2019.
LIU Cong. Research on surface defects detection of micro parts based on convolution neural network [D]. Harbin: Harbin University of Science and Technology, 2019.
13 陈绪浩. 基于深度学习的高速连接器高精度表面缺陷检测算法研究[D]. 成都: 电子科技大学, 2021.
CHEN Xu-hao. Research on high precision surface defect detection algorithm of high speed connector based on deep learning [D]. Chengdu: University of Electronic Science and Technology of China, 2021.
14 代牮, 赵旭, 李连鹏, 等 基于改进YOLOv5的复杂背景红外弱小目标检测算法[J]. 红外技术, 2022, 44 (5): 504- 512
DAI Jian, ZHAO Xu, LI Lian-peng, et al Improved YOLOv5-based infrared dim-small target detection under complex background[J]. Infrared Technology, 2022, 44 (5): 504- 512
15 HOU Q, ZHOU D, FENG J. Coordinate attention for efficient mobile network design [C]// Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. Nashville: IEEE, 2021: 13708-13717.
16 TAN M, PANG R, LE Q V. EfficientDet: scalable and efficient object detection [EB/OL]. [2022-04-07]. https://arxiv.org/pdf/1911.09070.pdf.
17 HAN K, WANG Y, TIAN Q, et al. GhostNet: more features from cheap operations [C]// Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. Seattle: IEEE, 2020: 1577-1586.
18 LIU S, QI L, QIN H, et al. Path aggregation network for instance segmentation [C]// Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. Lake City: IEEE, 2018: 8759-8768.
19 BOCHKOVSKIY A, WANG C Y, LIAO H Y M. YOLOv4: optimal speed and accuracy of object detection [EB/OL]. [2022-04-07]. https://arxiv.org/pdf/2004.10934.pdf.
20 GHIASI G, CUI Y, SRINIVAS A, et al. Simple copy-paste is a strong data augmentation method for instance segmentation [EB/OL]. [2022-04-07]. https://arxiv.org/pdf/2012.07177.pdf.
[1] 程艳芬,吴家俊,何凡. 基于关系门控图卷积网络的方面级情感分析[J]. 浙江大学学报(工学版), 2023, 57(3): 437-445.
[2] 曾菊香,王平辉,丁益东,兰林,蔡林熹,管晓宏. 面向节点分类的图神经网络节点嵌入增强模型[J]. 浙江大学学报(工学版), 2023, 57(2): 219-225.
[3] 杨帆,宁博,李怀清,周新,李冠宇. 基于语义增强特征融合的多模态图像检索模型[J]. 浙江大学学报(工学版), 2023, 57(2): 252-258.
[4] 刘超,孔兵,杜国王,周丽华,陈红梅,包崇明. 高阶互信息最大化与伪标签指导的深度聚类[J]. 浙江大学学报(工学版), 2023, 57(2): 299-309.
[5] 鲁建厦,包秦,汤洪涛,邵益平,赵文彬. 无设备人体追踪系统的择优标签方法[J]. 浙江大学学报(工学版), 2023, 57(2): 415-425.
[6] 马骏驰,迪骁鑫,段宗涛,唐蕾. 程序表示学习综述[J]. 浙江大学学报(工学版), 2023, 57(1): 155-169.
[7] 叶晨,战洪飞,林颖俊,余军合,王瑞,钟武昌. 基于推理-情境感知激活模型的设计知识推荐[J]. 浙江大学学报(工学版), 2023, 57(1): 32-46.
[8] 王林涛,毛齐. 基于RGB与深度信息融合的管片抓取位置测量方法[J]. 浙江大学学报(工学版), 2023, 57(1): 47-54.
[9] 凤丽洲,杨阳,王友卫,杨贵军. 基于Transformer和知识图谱的新闻推荐新方法[J]. 浙江大学学报(工学版), 2023, 57(1): 133-143.
[10] 刘近贞,陈飞,熊慧. 多尺度残差网络模型的开放式电阻抗成像算法[J]. 浙江大学学报(工学版), 2022, 56(9): 1789-1795.
[11] 王万良,王铁军,陈嘉诚,尤文波. 融合多尺度和多头注意力的医疗图像分割方法[J]. 浙江大学学报(工学版), 2022, 56(9): 1796-1805.
[12] 郝琨,王阔,王贝贝. 基于改进Mobilenet-YOLOv3的轻量级水下生物检测算法[J]. 浙江大学学报(工学版), 2022, 56(8): 1622-1632.
[13] 夏杰锋,唐武勤,杨强. 光伏航拍红外图像的热斑自动检测方法[J]. 浙江大学学报(工学版), 2022, 56(8): 1640-1647.
[14] 莫仁鹏,司小胜,李天梅,朱旭. 基于多尺度特征与注意力机制的轴承寿命预测[J]. 浙江大学学报(工学版), 2022, 56(7): 1447-1456.
[15] 赵永胜,李瑞祥,牛娜娜,赵志勇. 数字孪生驱动的机身形状控制方法[J]. 浙江大学学报(工学版), 2022, 56(7): 1457-1463.