作者投稿和查稿 主编审稿 专家审稿 编委审稿 远程编辑

计算机工程 ›› 2026, Vol. 52 ›› Issue (5): 226-238. doi: 10.19678/j.issn.1000-3428.0070376

• 计算机视觉与图形图像处理 • 上一篇    下一篇

基于改进YOLOv5s的PCB缺陷检测算法

魏文泉, 莫宏伟*()   

  1. 哈尔滨工程大学智能科学与工程学院, 黑龙江 哈尔滨 150001
  • 收稿日期:2024-09-14 修回日期:2024-11-19 出版日期:2026-05-15 发布日期:2026-05-12
  • 通讯作者: 莫宏伟
  • 作者简介:

    魏文泉, 男, 硕士研究生, 主研方向为机器感知与人工智能

    莫宏伟(通信作者), 教授、博士

  • 基金资助:
    黑龙江省重点研发计划(GA21A302)

PCB Defect Detection Algorithm Based on Improved YOLOv5s

WEI Wenquan, MO Hongwei*()   

  1. College of Intelligent Systems Science and Engineering, Harbin Engineering University, Harbin 150001, Heilongjiang, China
  • Received:2024-09-14 Revised:2024-11-19 Online:2026-05-15 Published:2026-05-12
  • Contact: MO Hongwei

摘要:

印刷电路板(PCB)的质量对工业电子产品的性能具有决定性的作用, 因此对PCB出厂质量的严格把控具有重要意义。PCB易出现的6类缺陷是评价PCB质量的主要参考依据, 针对现有的目标检测算法模型对PCB缺陷的检测精度低、体积庞大等问题, 提出改进的YOLOv5s-CMS模型。根据PCB缺陷的特点, YOLOv5s-CMS模型采用聚焦小目标信息的特征提取网络CCG(C2f-C3-Ghost)替换原有的特征提取网络, 使模型在特征提取阶段更加关注小目标的空间和梯度流信息; 在特征融合阶段, 提出一种多尺度跨层小目标特征融合网络(MCSTF-Net)来替换路径聚合网络(PANet), 在提高模型对PCB缺陷检测精度的同时大幅降低模型的参数量; 为进一步提升模型对小目标特征的理解程度, 将CCG网络和MCSTF-Net分别与SE(Squeeze-and-Excitation)注意力机制相结合, 在抑制无关通道的同时突出目标特征信息丰富的通道。消融实验结果表明, YOLOv5s-CMS模型对PCB缺陷检测的精确率、召回率、mAP@0.5和mAP@0.5∶0.95分别达到了98.1%、97.8%、98.4%和61.2%, 相比于YOLOv5s原模型分别提高了2.2、1.3、0.8和5.0百分点, 模型参数量同比减少了约46.1%。

关键词: 计算机视觉, YOLOv5s模型, 多尺度跨层特征融合, 印刷电路板缺陷, 小目标检测

Abstract:

The quality of Printed Circuit Boards (PCBs) plays a decisive role in the performance of industrial electronic products. Therefore, strict control of PCB factory quality is of considerable importance. The six types of defects that PCB are prone to are the primary basis for evaluating PCB quality. To address problems such as the low accuracy and large size of PCB defects detected by existing target detection algorithm models, an improved YOLOv5s-CMS model is proposed. According to the characteristics of PCB defects, the YOLOv5s-CMS model adopts a feature extraction network C2f-C3-Ghost (CCG) focusing on small target information to replace the original feature extraction network, such that the model pays more attention to the space and gradient flow information of small targets in the feature extraction stage. In the feature fusion phase, a Multi-scale Cross-layer Small Target Feature Fusion Network (MCSTF-Net) is proposed to replace the Path Aggregation Network (PANet), which can improve the accuracy of PCB defect detection while considerably reducing the number of parameters in the model. To further improve the model's understanding of small target characteristics, the CCG network and MCSTF-Net are combined with the Squeeze-and-Excitation (SE) attention mechanism to highlight the channels rich in target characteristics while suppressing irrelevant channels. The ablation experiment results showed that the accuracy, recall, mAP@0.5, and mAP@0.5∶0.95 of PCB defect detection using the YOLOv5s-CMS model reached 98.1%, 97.8%, 98.4%, and 61.2%, respectively. Compared to the original YOLOv5s model, the number of parameters increased by 2.2, 1.3, 0.8, and 5.0 percentage points, respectively, and the number of model parameters decreased by approximately 46.1%.

Key words: computer vision, YOLOv5s model, multi-scale cross-layer feature fusion, Printed Circuit Board (PCB) defect, small target detection