Please wait a minute...
浙江大学学报(工学版)  2025, Vol. 59 Issue (8): 1608-1616    DOI: 10.3785/j.issn.1008-973X.2025.08.007
机械工程、能源工程     
基于改进YOLOv5s的印刷电路板缺陷检测算法
周著国1,2(),鲁玉军1,*(),吕利叶1,2
1. 浙江理工大学 机械工程学院,浙江 杭州 310018
2. 浙江理工大学 龙港研究院,浙江 温州 325802
Improved YOLOv5s-based algorithm for printed circuit board defect detection
Zhuguo ZHOU1,2(),Yujun LU1,*(),Liye LV1,2
1. School of Mechanical Engineering, Zhejiang Sci-Tech University, Hangzhou 310018, China
2. Longgang Institute of Zhejiang Sci-Tech University, Wenzhou 325802, China
 全文: PDF(2691 KB)   HTML
摘要:

针对印刷电路板(PCB)存在的缺陷目标较小不易被识别、误检率高以及模型尺寸较大不易部署等问题,提出基于改进YOLOv5s的缺陷检测方法. 该方法使用基于密度分层聚类的K-means (HDBK-means) 算法,重新聚类得到更适合PCB缺陷特点的锚框. 使用经空间与通道重建卷积 (SCConv) 改进的重参数化非线性跨阶段部分高效层聚合网络 (RepNCSPELAN) 替换YOLOv5s主干中的特征提取模块,在保证精度的前提下,大大提高了模型推理速度. 通过引入重参数化细节增强广义特征金字塔网络 (RDEGFPN) 进行特征融合,提升模型对于各个尺度缺陷目标的识别能力,减少计算资源消耗. 使用动态上采样(DySample)对特征融合网络进行二次创新,形成广义动态特征融合金字塔网络 (GDFPN),提高模型的轻量级与高效性,使得模型更容易部署. 在公共PCB数据集上进行的对比实验表明,该算法将平均精度均值(mAP)提高了3.8%,将精度提高了2.9%,模型大小减少了26.9%,模型的检测速度达到138.1帧/s. 将模型部署到RK3568平台上进行检测,满足了实时检测与嵌入式设备部署的要求.

关键词: 印刷电路板YOLOv5s聚类算法特征提取特征融合    
Abstract:

A defect detection method based on improved YOLOv5s was proposed aiming at the problems that exist in printed circuit board (PCB), such as small defect targets that are not easy to be identified, high false detection rate, and large model size that is not easy to be deployed. Hierarchical density-based clustering k-means (hierarchical density-based K-means, HDBK-means) algorithm was used to regroup to get the anchor frame more suitable for the characteristics of PCB defects. The feature extraction module in the YOLOv5s backbone was replaced with a reparameterized normalized cross stage partial efficient layer aggregation network (RepNCSPELAN) improved by spatial and channel reconstruction convolution (SCConv), which greatly improved the speed of model inference while ensuring accuracy. Then the recognition ability of the model for defective targets at various scales can be improved by introducing reparameterized detail-enhanced generalized feature pyramid network (RDEGFPN) for feature fusion while reducing the computational resource consumption. Dynamic upsample (DySample) was used to innovate the feature fusion network to form generalized dynamic feature pyramid network (GDFPN), which improved the lightweight and efficiency of the model and made the model easier to deploy. Comparative experiments conducted on public PCB datasets demonstrate that the proposed algorithm achieves a 3.8% improvement in mean average precision (mAP), a 2.9% enhancement in precision, and a 26.9% reduction in model size, while achieving a detection speed of 138.1 frames per second. The deployment of the model on the RK3568 platform meets the requirements for real-time detection and embedded device implementation.

Key words: printed circuit board    YOLOv5s    clustering algorithm    feature extraction    feature fusion
收稿日期: 2024-08-02 出版日期: 2025-07-28
:  TP 391  
基金资助: 浙江理工大学龙港研究院资助项目(LGYJY2021004).
通讯作者: 鲁玉军     E-mail: 2284545699@qq.com;luet_lyj@zstu.edu.cn
作者简介: 周著国(1998—),男,硕士生,从事计算机视觉的研究. orcid.org/0009-0009-8372-8526. E-mail:2284545699@qq.com
服务  
把本文推荐给朋友
加入引用管理器
E-mail Alert
作者相关文章  
周著国
鲁玉军
吕利叶

引用本文:

周著国,鲁玉军,吕利叶. 基于改进YOLOv5s的印刷电路板缺陷检测算法[J]. 浙江大学学报(工学版), 2025, 59(8): 1608-1616.

Zhuguo ZHOU,Yujun LU,Liye LV. Improved YOLOv5s-based algorithm for printed circuit board defect detection. Journal of ZheJiang University (Engineering Science), 2025, 59(8): 1608-1616.

链接本文:

https://www.zjujournals.com/eng/CN/10.3785/j.issn.1008-973X.2025.08.007        https://www.zjujournals.com/eng/CN/Y2025/V59/I8/1608

图 1  Improved_YOLOv5s网络的结构
图 2  HDBK-means算法的聚类结果
图 3  RepNCSPELAN的结构
图 4  跨阶段细节增强交互模块的结构
图 5  印刷电路板的不同类型缺陷图像
图 6  模型训练与RK3568平台部署
图 7  YOLOv5s与Improved_YOLOv5s的各性能指标对比
实验编号HDBK-meansRepNCSPELAN
_SSConv
DySampleRDEGFPNR/%P/%mAP/%S/MBFLOPs/109
1××××90.196.394.813.415.8
2×××91.697.396.413.315.8
3×××89.196.694.49.212.4
4×××90.496.195.113.315.8
5×××90.898.196.113.315.6
6××90.196.695.19.412.4
7××91.698.895.313.115.8
8××92.298.097.513.215.5
9××91.196.894.79.512.5
10××93.498.197.39.612.2
11××94.298.397.613.215.6
12×93.197.495.910.012.6
13×92.197.895.39.512.5
14×94.899.298.213.315.6
15×93.998.997.110.112.7
1695.599.298.69.812.8
表 1  消融实验结果的对比
聚类算法P/%mAP/%FLOPs/109
K-means96.394.815.8
K-means++96.895.115.8
Binary K-means96.995.415.8
DBSCAN97.195.815.8
Agglomerative Clustering94.791.815.8
Mean Shift94.190.115.8
HDBK-means97.396.415.8
表 2  不同聚类算法植入后的模型检测性能对比
特征融合方式P/%mAP/%FLOPs/109
BiFPN96.594.915.5
AFPN96.194.116.2
ASFF96.694.716.2
HSFPN97.195.214.5
GFPN97.595.616.1
GDFPN98.397.615.6
表 3  不同特征融合网络植入后的模型检测性能对比
算法P/%mAP/%S/MBFLOPs/109v/(帧·s?1)
服务器RK3568
文献[25]算法93.295.85.812.6128.046.1
文献[26]算法94.796.53.85.288.420.5
文献[27]算法93.997.310.511.8137.863.8
文献[28]算法91.695.592.341.492.521.4
文献[29]算法93.296.420.112.848.911.3
YOLOv5s96.394.813.415.8128.452.2
YOLOv7-tiny98.495.36.0310.282.519.8
YOLOv8n96.793.85.968.2134.856.1
Improved_YOLOv5s99.298.69.812.8138.166.1
表 4  不同文献算法以及YOLO系列算法检测结果对比
图 8  YOLOv5s与Improved_YOLOv5s的检测效果对比
1 XIAO Z, WANG Z, LIU D, et al A path planning algorithm for PCB surface quality automatic inspection[J]. Journal of Intelligent Manufacturing, 2021, 33 (6): 1- 13
2 黄银花, 李东波. 高速高精度印刷电路板表面贴装自动光学检测系统的研究 [J]. 机床与液压, 2014, 42(21): 105-108.
HUANG Yinhua , LI Dongbo. Research on high-speed and high-precision automatic optical inspection system for surface mount technology of printed circuit board [J]. Machine Tool and Hydraulics, 2014, 42(21): 105-108.
3 赵翔宇, 周亚同, 何峰, 等 分层提取匹配印刷电路板元器件缺陷检测[J]. 仪表技术与传感器, 2018, (8): 84- 89
ZHAO Xiangyu, ZHOU Yatong, HE Feng, et al Defect detection of printed circuit board components based on hierarchical extraction and matching[J]. Instrument Technique and Sensor, 2018, (8): 84- 89
doi: 10.3969/j.issn.1002-1841.2018.08.022
4 郭庆梅, 刘宁波, 王中训, 等. 基于深度学习的目标检测算法综述 [J]. 探测与控制学报, 2023, 45(6): 10-20.
GUO Qingmei, LIU Ningbo , WANG Zhongxun, et al. A review of object detection algorithms based on deep learning [J]. Journal of Detection and Control, 2023, 45(6): 10-20.
5 赵景波, 杜保帅 基于深度学习的小目标检测技术发展[J]. 电光与控制, 2023, 30 (2): 63- 70
ZHAO Jingbo, DU Baoshuai Development of small object detection technology based on deep learning[J]. Electronics Optics and Control, 2023, 30 (2): 63- 70
doi: 10.3969/j.issn.1671-637X.2023.02.012
6 谢富, 朱定局 深度学习目标检测方法综述[J]. 计算机系统应用, 2022, 31 (2): 1- 12
XIE Fu, ZHU Dingju A review of deep learning-based object detection methods[J]. Computer Systems and Application, 2022, 31 (2): 1- 12
7 HU B, WANG J H Detection of PCB surface defects with improved faster-RCNN and feature pyramid network[J]. IEEE Access, 2020, (8): 108335- 108345
8 TSAI D-M, CHOU Y-H Fast and precise positioning in PCBs using deep neural network regression[J]. IEEE Transactions on Instrumentation and Measurement, 2019, 69 (7): 4692- 4701
9 ZHANG H, JIANG L, LI C CS-ResNet: cost-sensitive residual convolutional neural network for PCB cosmetic defect detection[J]. Expert Systems with Applications, 2021, 185: 115673
doi: 10.1016/j.eswa.2021.115673
10 张艳, 张明路, 吕晓玲, 等 深度学习小目标检测算法研究综述[J]. 计算机工程与应用, 2022, 58 (15): 1- 17
ZHANG Yan, ZHANG Minglu, LV Xiaoling, et al A review of deep learning-based small object detection algorithms[J]. Computer Engineering and Applications, 2022, 58 (15): 1- 17
doi: 10.3778/j.issn.1002-8331.2112-0176
11 王永利, 曹江涛, 姬晓飞 基于卷积神经网络的PCB缺陷检测与识别算法[J]. 电子测量与仪器学报, 2019, 33 (8): 78- 84
WANG Yongli, CAO Jiangtao, JI Xiaofei PCB defect detection and recognition algorithm based on convolutional neural network[J]. Journal of Electronic Measurement and Instrumentation, 2019, 33 (8): 78- 84
12 苏佳, 贾欣雨, 侯卫民 基于YOLO-J的PCB缺陷检测算法[J]. 计算机集成制造系统, 2024, 30 (11): 3984- 3998
SU Jia, JIA Xinyu, HOU Weimin PCB defect detection algorithm based on YOLO-J[J]. Computer Integrated Manufacturing Systems, 2024, 30 (11): 3984- 3998
13 王淑青, 张子言, 朱文鑫, 等 基于改进YOLOv5的PCB板表面缺陷检测[J]. 仪表技术与传感器, 2023, (5): 106- 111
WANG Shuqing, ZHANG Ziyan, ZHU Wenxin, et al Surface defect detection of PCB based on improved YOLOv5[J]. Instrument Technique and Sensor, 2023, (5): 106- 111
doi: 10.3969/j.issn.1002-1841.2023.05.020
14 WANG X, ZHANG H Y, LIU Q H, et al You-only-look-once multiple-strategy printed circuit board defect detection model[J]. IEEE Multimedia, 2024, 31 (1): 76- 87
15 GEOFFREY S, MAHMOOD A-K. An implementation of the HDBSCAN* clustering algorithm [J], Applied Sciences, 2022, 12(5): 2405.
16 WANG Z, WU L, LI T, et al A smoke detection model based on improved YOLOv5[J]. Mathematics, 2022, 10 (7): 1190
doi: 10.3390/math10071190
17 葛程鹏, 赵东, 王蕊, 等 基于改进DBSCAN和距离共识评估的分段点云去噪方法[J]. 系统仿真学报, 2024, 36 (8): 1800- 1809
GE Chengpeng, ZHAO Dong, WANG Rui, et al A denoising method for segmented point cloud based on improved DBSCAN and distance consensus evaluation[J]. Journal of System Simulation, 2024, 36 (8): 1800- 1809
18 CHIEN-YAO W, YEH IH, HONG-YUAN MARK L. YOLOv9: learning what you want to learn using programmable gradient information [EB/OL]. (2024-02-29) [2024-08-01]. https://doi.org/10.48550/arXiv.2402.13616.
19 HE J J, ZHANG S H, YANG C H, et al. Pest recognition in microstates state: an improvement of YOLOv7 based on spatial and channel reconstruction convolution for feature redundancy and vision transformer with bi-level routing attention [J]. Frontiers in Plant Science, 2024, 15: 1327237.
20 XU X Z, JIANG Y Q, CHEN W H, et al. DAMO-YOLO : a report on real-time object detection design [EB/OL]. (2023-04-24) [2024-08-01]. https://doi.org/10.48550/arXiv.2211.15444.
21 CHEN Z X, HE Z W, LU Z-M DEA-Net: single image dehazing based on detail-enhanced convolution and content-guided attention[J]. IEEE Transactions on Image Processing, 2024, 33: 1002- 1015
doi: 10.1109/TIP.2024.3354108
22 LIU W Z, LU H, FU H T, et al. Learning to upsample by learning to sample [EB/OL]. (2023-08-29) [2024-08-01]. https://doi.org/10.48550/arXiv.2308.15085.
23 CHENG C S, HOU C J, WEN X, et al Small-sample underwater target detection: a joint approach utilizing diffusion and YOLOv7 model[J]. Remote Sensing, 2023, 15 (19): 4772
doi: 10.3390/rs15194772
24 GUO A, SUN K Q, ZHANG Z Y A lightweight YOLOv8 integrating FasterNet for real-time underwater object detection[J]. Journal of Real-Time Image Processing, 2024, 21 (2): 1- 15
25 XIAO G S, HOU S L, ZHOU H Y PCB defect detection algorithm based on CDI-YOLO[J]. Scientific Reports, 2024, 14 (1): 7351
doi: 10.1038/s41598-024-57491-3
26 ZHOU G A, YU L J, SU Y X, et al Lightweight PCB defect detection algorithm based on MSD-YOLO[J]. Cluster Computing, 2023, 27 (3): 3559- 3573
27 YUAN Z H, TANG X Y, NING H, et al LW-YOLO: lightweight deep learning model for fast and precise defect detection in printed circuit boards[J]. Symmetry, 2024, 16 (4): 418
doi: 10.3390/sym16040418
28 TANG J L, LIU S B, ZHAO D X, et al PCB-YOLO: an improved detection algorithm of PCB surface defects based on YOLOv5[J]. Sustainability, 2023, 15 (7): 5963
doi: 10.3390/su15075963
[1] 李朝龙,庞善民,王超玉,王翌丰,史鹏程. 基于正态分布相似性的双视角点云配准方法[J]. 浙江大学学报(工学版), 2025, 59(6): 1179-1190.
[2] 李沈崇,曾新华,林传渠. 基于轴向注意力的多任务自动驾驶环境感知算法[J]. 浙江大学学报(工学版), 2025, 59(4): 769-777.
[3] 张振利,胡新凯,李凡,冯志成,陈智超. 基于CNN和Efficient Transformer的多尺度遥感图像语义分割算法[J]. 浙江大学学报(工学版), 2025, 59(4): 778-786.
[4] 刘登峰,郭文静,陈世海. 基于内容引导注意力的车道线检测网络[J]. 浙江大学学报(工学版), 2025, 59(3): 451-459.
[5] 梁礼明,龙鹏威,金家新,李仁杰,曾璐. 基于改进YOLOv8s的钢材表面缺陷检测算法[J]. 浙江大学学报(工学版), 2025, 59(3): 512-522.
[6] 傅幼萍,张航,厉梦菡,孟濬. 基于脉搏波信号多维度特征的身份识别[J]. 浙江大学学报(工学版), 2025, 59(3): 566-576.
[7] 王博特,王卿,刘强,金波. 基于多通道振动主元特征的风电机组叶片自监督异常识别方法[J]. 浙江大学学报(工学版), 2025, 59(3): 653-660.
[8] 何永福,谢世维,于佳禄,陈思宇. 考虑跨层特征融合的抛洒风险车辆检测方法[J]. 浙江大学学报(工学版), 2025, 59(2): 300-309.
[9] 刘欢,李云红,张蕾涛,郭越,苏雪平,朱耀麟,侯乐乐. 基于MA-ConvNext网络和分步关系知识蒸馏的苹果叶片病害识别[J]. 浙江大学学报(工学版), 2024, 58(9): 1757-1767.
[10] 林俊杰,朱雅光,刘春潮,刘昊洋. 面向移动作业的腿足机器人数字孪生系统[J]. 浙江大学学报(工学版), 2024, 58(9): 1956-1969.
[11] 王海军,王涛,俞慈君. 基于递归量化分析的CFRP超声检测缺陷识别方法[J]. 浙江大学学报(工学版), 2024, 58(8): 1604-1617.
[12] 韩康,战洪飞,余军合,王瑞. 基于空洞卷积和增强型多尺度特征自适应融合的滚动轴承故障诊断[J]. 浙江大学学报(工学版), 2024, 58(6): 1285-1295.
[13] 钟博,王鹏飞,王乙乔,王晓玲. 基于深度学习的EEG数据分析技术综述[J]. 浙江大学学报(工学版), 2024, 58(5): 879-890.
[14] 刘毅,陈一丹,高琳,洪姣. 基于多尺度特征融合的轻量化道路提取模型[J]. 浙江大学学报(工学版), 2024, 58(5): 951-959.
[15] 曹寅,秦俊平,高彤,马千里,任家琪. 基于生成对抗网络的文本两阶段生成高质量图像方法[J]. 浙江大学学报(工学版), 2024, 58(4): 674-683.