Search

CN-122023333-A - Method and system for detecting surface defects of printed circuit board with enhanced feature perception

CN122023333ACN 122023333 ACN122023333 ACN 122023333ACN-122023333-A

Abstract

The invention discloses a method and a system for detecting surface defects of a printed circuit board for enhancing feature perception. The method comprises the steps of obtaining a surface image of a printed circuit board through an image acquisition device, preprocessing the surface image, inputting the image to be detected into a trained defect detection model, outputting the type of a defect target, the coordinates of a boundary frame and the confidence coefficient at an inference end, and outputting a detection result to an automatic optical detection terminal for sorting or alarming. The backbone network of the defect detection model comprises a feature coding module for coupling dynamic grouping convolution and Monte Carlo attention, wherein deep and shallow layer features are fused by the dynamic grouping convolution, and self-adaptive channel weight is generated to restrain background interference through a spatial random replacement and multi-scale random sampling mechanism of Monte Carlo attention. And introducing a bounding box regression loss function based on a dynamic focusing mechanism in the detection and decoding stage, and calculating the deviation dynamic adjustment gradient contribution of the regression error of the current sample and the historical training mean value so as to focus model training on samples with general quality.

Inventors

  • SONG ZHINA
  • LUO RONGJUN
  • XU CHUAN
  • CHEN YEPEI
  • BAI TING

Assignees

  • 湖北工业大学

Dates

Publication Date
20260512
Application Date
20260130

Claims (10)

  1. 1. The method for detecting the surface defects of the printed circuit board for enhancing the feature perception is characterized by comprising the following steps of: s1, acquiring a surface image of a printed circuit board to be detected through an image acquisition device, and preprocessing; s2, inputting the preprocessed image into a pre-constructed surface defect detection model for enhancing feature perception, wherein a backbone network of the surface defect detection model comprises a feature coding module for coupling dynamic grouping convolution and Monte Carlo attention, and the feature coding module is used for carrying out multi-stage downsampling coding on the input image and outputting a multi-scale feature map; the method comprises the steps of adopting a multi-scale feature fusion network to perform up-sampling fusion and down-sampling fusion from top to bottom on multi-scale feature graphs with different resolutions output by a backbone network, performing channel splicing on the features at the fusion position, and then fusing the features through a convolution module to enhance information interaction between high-level semantics and low-level space details; s3, constructing a loss function to train a surface defect detection model, reasoning the surface image of the PCB to be tested by using the trained surface defect detection model, and outputting the type of the defect, the coordinates of the boundary frame and the confidence information.
  2. 2. The method for detecting surface defects of a printed circuit board for enhancing feature perception according to claim 1, wherein the preprocessing operation in S1 comprises the steps of performing size unification processing on the collected original image to obtain a standard input image, and then performing data enhancement processing, specifically comprising Mosaic enhancement, random scaling, random horizontal inversion and HSV color gamut disturbance.
  3. 3. The method for detecting the surface defects of the printed circuit board for enhancing the feature perception according to claim 1, wherein the backbone network adopts a five-stage feature extraction paradigm, each stage sequentially corresponds to and outputs a scale feature map P1 to P5, and the backbone network has the following specific structure: The first stage, the input PCB image is initially downsampled through a single convolution layer, and a feature map P1 is output; The second to fifth stages, all adopt the cascade structure of the convolution layer +C3k2_ MCAttn module, wherein the convolution layer is responsible for feature downsampling and dimension adjustment, the C3k2_ MCAttn module represents the feature extraction module for coupling dynamic grouping convolution and Monte Carlo attention, wherein C3k2 is a structure for stacking feature codes comprising two branches of dynamic grouping convolution residual errors, MCAttn is Monte Carlo attention, and the C3k2_ MCAttn module is used for completing basic feature extraction and realizing feature enhancement through Monte Carlo attention mechanism and channel recombination; the output scale feature graphs P3 to P5 serve as the input of a subsequent multi-scale feature fusion network and a detection head, and are respectively matched with feature fusion of different scales and accurate detection to provide multi-level feature support.
  4. 4. The method for detecting surface defects of a printed circuit board for enhancing feature perception according to claim 1 or 3, wherein the process of constructing the feature extraction module for coupling dynamic group convolution and Monte Carlo attention is as follows: The method comprises the steps of mapping an input feature map through a convolution layer, dividing the input feature map into two parts in the channel dimension, directly transmitting shallow information without processing one part of features, carrying out nonlinear transformation on the other part of features through grouping convolution comprising different residual stacking units, extracting deep features, carrying out channel splicing on the two parts of features, mapping the two parts of features through the convolution layer, inputting the two parts of features into a Monte Carlo attention module, and carrying out self-adaptive weighting on the spliced features by utilizing channel attention weights generated by the Monte Carlo attention module.
  5. 5. The method for detecting surface defects of a printed circuit board for enhancing feature perception as recited in claim 4, wherein the Monte Carlo attention module is processed as follows: step A, randomly disturbing the input feature map F in the space dimension to obtain a replacement feature map F': Wherein, the Representing a random permutation operation on the set of spatial indexes; step B, setting a multi-scale pooling resolution set From the slave The middle is randomly sampled according to uniform distribution For randomly disturbed characteristics Applying adaptive averaging pooling to obtain intermediate feature vectors ; Step C, the intermediate feature vector Input to a two-layer channel compression-expansion network to obtain channel attention weights: Wherein, the Is that Is used to determine the flattening vector of (1), 、 A trainable weight matrix of decreasing and increasing dimensions respectively, For the function to be activated by the ReLU, Is a Sigmoid function; and D, carrying out channel-by-channel weighting on the input features F by using the channel attention weights to obtain output features.
  6. 6. The method for detecting the surface defects of the printed circuit board for enhancing the feature perception according to claim 3, wherein the multi-scale feature fusion network is used for splicing and fusing feature graphs of different stages output by a backbone network in a channel dimension through up-sampling fusion from top to bottom and down-sampling fusion from bottom to top to generate small-scale, medium-scale and large-scale detection feature graphs respectively used for detecting defect targets of different scales, and the method specifically comprises the following steps: (1) The high-level characteristic diagram P5 is taken as input, the size of the high-level characteristic diagram is doubled through up-sampling operation, the high-level characteristic diagram is spliced with the P4 characteristic diagram output by a backbone network in the channel dimension, and the high-level characteristic diagram is fused through a C3k2 module to obtain a mesoscale characteristic diagram ; (2) For a pair of Performing up-sampling again and splicing with the backbone network P3 feature map, and fusing by a C3k2 module to obtain a small-scale feature map for detecting small defects ; (3) Downsampling a small-scale detection feature map through a convolution layer, and After splicing, the mesoscale detection feature map is obtained through C3k2 module fusion ; (4) Downsampling the mesoscale detection feature map through a convolution layer, splicing the mesoscale detection feature map with the P5 feature map, and fusing the mesoscale detection feature map through a C3k2 module to obtain a large-scale detection feature map 。
  7. 7. The method for detecting surface defects of a printed circuit board with enhanced feature perception as claimed in claim 1, wherein the constructed loss function Comprises at least the following three parts: Wherein, the To regress the loss based on dynamically adjusted WIoU bounding boxes, In order to achieve a loss of existence of a spatial target, For the classification loss of the defect class, Is a non-negative weight coefficient; The WIoU bounding box regression loss Based on the cross-ratio loss and dynamic focusing mechanism construction, for each prediction bounding box Real bounding box corresponding to the real bounding box Wherein (x, y) is equal to% , ) The coordinates of the central points of the predicted frame and the real frame, And (3) with The width and height of the prediction frame and the real frame are respectively calculated according to the following steps: first, calculating the intersection ratio IoU of the predicted frame and the real frame: the corresponding IoU losses are: Constructing distance attention items Weighting IoU losses by using normalized distance between center points of the prediction frame and the real frame, and enabling the minimum circumscribed rectangle size surrounding the prediction frame and the real frame to be equal to The distance attention term is: Wherein, the Representing pairs in a back propagation computation graph Gradient truncation is carried out to avoid adverse gradient to the minimum circumscribed rectangle size; introducing dynamic focusing mechanism to construct WIoU boundary box regression loss, and setting IoU loss of a sample in the current training iteration as While preserving its exponential sliding average over the training process The update form is as follows: Wherein, the Is the first IoU of the current small batch of samples at each iteration lose the mean, Is a momentum coefficient; The resulting WIoU bounding box regression loss is: Wherein, the Representing a gradient gain function describing the mass of the sample, Representing sample outliers.
  8. 8. The method for detecting surface defects of a printed circuit board with enhanced feature perception as claimed in claim 7, wherein the sample outlier degree is defined : Degree of outlier Is a relative quantity, not an absolute quantity, that describes the degree of deviation of the current sample error from the historical average; defining a gradient gain function describing sample mass The calculation is as follows: Wherein the method comprises the steps of 、 Is a super parameter.
  9. 9. The method for detecting surface defects of a printed circuit board with enhanced feature perception as claimed in claim 7, wherein the spatial target presence loss For restraining the ability of the detection head to determine whether a target exists at each spatial position, providing a multi-scale detection head at the first position Outputting target existence prediction values at each prediction position as Its corresponding real target existence label is Wherein Indicating that the predicted position is assigned as a positive sample, Representing a negative sample, then the spatial target presence penalty is defined as a binary cross entropy penalty: Wherein, the Representing the total number of predicted locations, Activating a function for Sigmoid; The defect class classification loss For constraint model to accurately determine defect type of detected target, calculate only predicted position determined as foreground, set at the first position At each foreground predicted position, the model outputs a category prediction vector of The corresponding real class label is Wherein For the total number of defect categories, the defect category classification loss is defined as: Wherein, the Representing the number of foreground samples.
  10. 10. A printed circuit board surface defect detection system for enhancing feature perception is characterized by comprising a processor and a memory, wherein the memory is used for storing program instructions, and the processor is used for calling the program instructions in the memory to execute the printed circuit board surface defect detection method for enhancing feature perception according to any one of claims 1-9.

Description

Method and system for detecting surface defects of printed circuit board with enhanced feature perception Technical Field The invention belongs to the technical field of electronic manufacturing quality detection, and particularly relates to a method and a system for detecting surface defects of a printed circuit board (Printed Circuit Board, PCB for short), which can realize high-efficiency and accurate detection of micro defects on the surface of the PCB. Background The PCB is used as a core interconnection component of electronic equipment, is a key carrier for bearing electronic components and realizing circuit signal transmission, and is widely applied to various fields of communication equipment, consumer electronics, industrial control, aerospace and the like. The manufacturing process of the PCB is complex, and various defects are easily generated due to factors such as process fluctuation, environmental impurities, equipment precision and the like in the production process, and a plurality of links such as etching, drilling and welding are involved. These defects directly affect the electrical performance, stability and service life of the electronic equipment, and may cause the whole electronic system to fail when serious, so the detection of the surface defects of the PCB is a core link in the quality control of electronic manufacturing. With the development of miniaturization, high density and high integration of electronic devices, circuit wiring of PCBs is becoming more precise, and line widths and line pitches are continuously compressed to the micrometer level. In this context, the core challenges of PCB surface defect detection have evolved to accurately capture sparse, small target defects in complex contexts. Traditional manual visual inspection is high in cost, is influenced by personnel experience and fatigue degree, and is extremely easy to generate visual omission when facing tiny and sparse targets. Traditional machine vision-based methods (such as threshold segmentation and template matching) extremely depend on manual design rules, and often have complicated flow, high time consumption and low efficiency, and cannot meet the requirements of high-precision and high-efficiency modern industrial quality inspection. In recent years, deep learning technology has been widely studied and applied in the field of target detection by virtue of strong feature characterization capability. However, the surface micro defects (such as micro scratches, circuit breaking caused by micro dust interference, extremely hidden copper leakage and the like) of the PCB occupy very little space in the image, have weak characteristics, and the defects represent typical sparse distribution states in complex circuit textures, so that the coupling degree of the target and the background is very high. In the face of such situations, it is often difficult to stably capture these subtle but complex differences directly with the universal target detection method. Therefore, based on the practical industrial quality inspection application requirements, the PCB surface defect detection method and system with the characteristics of high precision, high speed and light weight are developed, and the method and system have important application values. Disclosure of Invention Aiming at the problems existing in the prior art, the invention provides a method and a system for detecting the surface defects of a printed circuit board for enhancing feature perception, which are used for detecting small-size and sparsely distributed surface defect targets under the complex texture background of a PCB, the feature coding module for coupling dynamic grouping convolution and Monte Carlo attention is introduced into a backbone network to enhance multi-scale characterization capability, and a dynamic focusing bounding box regression loss function is introduced in a training stage to improve the positioning convergence stability of the small target defects, so that the omission ratio is reduced and the real-time detection requirement of an automatic optical detection terminal is met. The invention improves the detection stability and the positioning precision of a model to small target defects under a complex background on the premise of not increasing the calculation cost of the model by adopting the space random substitution and the multi-scale random sampling of a Monte Carlo attention module in a feature coding stage to generate channel weights and adopting a dynamic focusing bounding box regression loss function to dynamically adjust the gradient contribution of different quality samples in a model training stage. The invention relates to a printed circuit board surface defect detection method for enhancing feature perception, which is suitable for automatic optical detection of production line or off-line reinspection scenes, and comprises the following steps: s1, acquiring a surface image of a printed circuit board to be detect