Due to the high integration, complex circuits, and increasing parameters of printed circuit boards (PCBs), defects in PCBs directly affect production efficiency, making computer vision-based defect detection crucial for PCB manufacturing. A self-attention-based PCB defect detection algorithm was proposed based on the YOLO object detection algorithm. First, a polarized self-attention (PSA) mechanism was introduced in the feature extraction stage to separately extract spatial and semantic features of PCBs, which were combined with input raw features to enhance the network’s feature representation capability. Then, a small-object detection head was added in the decoding stage, which fully utilized low-resolution features from the YOLO network Backbone module to enable the network to focus on local details of PCBs and improve defect positioning accuracy. Experiments show that the proposed method achieves 95.5% accuracy on the PCB dataset, 4% higher than the original YOLOv8 method, with the mAP0.5∶0.95 metric increased by 2.8%.
YOLO(you only look once)算法是一种目标检测算法,它的主要优势在于实时性能很高.传统目标检测算法通常将目标检测问题分解为两个子任务:候选区域生成和目标分类,在处理速度上存在瓶颈,因为需要对大量的候选区域进行分类.相比之下,YOLO算法采用了一种不同的策略.它将目标检测问题视为一个回归问题,通过将CNN应用于整个图像来同时预测目标的边界框和类别,如图1所示.具体来说,YOLO算法将输入图像分为S×S个网格单元,并在每个单元格中预测B个边界框.每个边界框由5个要素组成:边界框的位置(x、y、宽度、高度)和置信度分数(表示该边界框包含目标的概率).每个边界框还与一个特定的类别相关联.这样,YOLO算法可以一次性地检测出图像中的多个目标.为了训练YOLO模型,需要大量带有标注框和类别的训练图像数据.通过优化损失函数,模型可以学习到目标的位置和类别信息.
如图3所示,先用1×1卷积将输入特征 X 转换为和,其中的通道被完全压缩,而的通道维度保持在一个比较高的水平(C/2).因为的通道维度被压缩,需要通过HDR进行信息增强,因此采用Softmax对进行信息增强.然后将和进行矩阵乘法,并在后面接上1×1卷积,LN将通道维度从C/2提升为C.最后用Sigmoid函数使得所有参数都保持在0~1之间.
PSA机制通过2个分支的输出在并行布局下组成:
=
.
其中是通道注意力机制表达式:
.
其中:FSG是Sigmoid激活函数; Z 是输出特征;表示通道卷积之间的参数;,是1×1卷积层;,是重塑操作(reshape operator);是Softmax算子;×是矩阵点积运算;是通道乘法运算操作符;是空间乘法运算操作符.
实验结果如表1所示,在PCB数据集上对比了YOLOv6,YOLOv8,加入小目标检测头的YOLOv8(YOLOv8_p2),加入PSA机制的YOLOv8(YOLOv8_psa)和加入PSA机制和小目标检测头的YOLOv8(YOLOv8_p2_psa)算法的精度(precision)、召回率(recall)、平均精度均值(mean average precision,mAP)以及每个模型的参数量.
ZhengX Q, ZhengS, KongY G, et al. Recent advances in surface defect inspection of industrial products using deep learning techniques[J]. The International Journal of Advanced Manufacturing Technology, 2021, 113(1): 35-58.
[2]
AnithaD B, RaoM. A survey on defect detection in bare PCB and assembled PCB using image processing techniques[C]// International Conference on Wireless Communications, Signal Processing and Networking (WiSPNET). Chennai, 2017: 39-43.
[3]
MaJ J. Defect detection and recognition of bare PCB based on computer vision[C]// 36th Chinese Control Conference (CCC). Dalian, 2017: 11023-11028.
ZouHua-dong. Online optical inspection of PCB hole position information based on machine learning[J]. Journal of Liaoning Technical University (Natural Science Edition), 2012, 31(1): 93-97.
[6]
ZhangZ Q, WangX D, LiuS, et al. An automatic recognition method for PCB visual defects[C]// 2018 International Conference on Sensing, Diagnostics, Prognostics, and Control (SDPC). Xi’an, 2018: 138-142.
[7]
WangN, WangB, HuangJ M, et al. PCB characteristic impedance prediction based on an error compensated random forest regression model[C]// 34th Chinese Control and Decision Conference (CCDC). Hefei, 2022: 3999-4004.
[8]
ChangQ T, ZhangY, SunZ. Research on surface defect detection algorithm of ice-cream bars based on clustering[C]// IEEE 3rd Information Technology, Networking, Electronic and Automation Control Conference (ITNEC). Chengdu, 2019: 537-541.
[9]
HuB, WangJ H. Detection of PCB surface defects with improved faster-RCNN and feature pyramid network[J]. IEEE Access, 2020, 8: 108335-108345.
LiuWei-sen, FangYi-jian. PCB bare board defect recognition algorithm based on multi-scale lightweight convolutional network[J]. Automation & Information Engineering, 2020,41(5): 20-25.
[12]
HanW, RenH W, ZhuX J, et al. Research and implementation of PCB defect detection based on improved YOLOv5 algorithm[C]// IEEE 3rd International Conference on Information Technology, Big Data and Artificial Intelligence (ICIBA). Chongqing, 2023: 1475-1478.
[13]
LiY T, HuangH S, XieQ S, et al. Research on a surface defect detection algorithm based on MobileNet-SSD[J]. Applied Sciences, 2018, 8(9): 1678.
[14]
AnK, ZhangY P. LPViT: a transformer based model for PCB image classification and defect detection[J]. IEEE Access, 2022, 10(5): 42-53.
WangYong-li, CaoJiang-tao, JiXiao-fei. PCB defect detection and recognition algorithm based on convolutional neural network [J]. Journal of Electronic Measurement and Instrumentation, 2019, 33(8): 78-84.
XuSi-ang, LiYi-jie, LiangQiao-kang, et al. PCB bare board defect detection based on improved YOLOv5 algorithm [J]. Packaging Engineering, 2022, 43(15): 33-41.
[19]
SusaJ A B, MariquinaE, TriaM L, et al. Cap-Eye-citor: a machine vision inference approach of capacitor detection for PCB automatic optical inspection[C]// IEEE 7th International Conference on Engineering Technologies and Applied Sciences (ICETAS). Kuala Lumpur, 2020:1-5.
[20]
XuS Y, ChenX L, HuangY R, et al. Defect detection of substation instrumentation equipment based on improved YOLOv4 algorithm[C]// 2023 China Automation Congress (CAC). Chongqing, 2023: 9091-9096.