PCB semantic segmentation method fusing ResNet and attention mechanism

Through the PCB semantic segmentation method that integrates ResNet and attention mechanism, the problem of insufficient detection accuracy of micro defects in the prior art is solved, and a higher precision PCB defect segmentation is achieved.

CN120374640APending Publication Date: 2025-07-25GUANGDONG POLYTECHNIC NORMAL UNIV
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510380388.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-28
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

The existing PCB defect detection algorithm is not accurate enough and fails to fully integrate the micro defect information, resulting in the inability to effectively segment the micro defects.

Method used

The PCB semantic segmentation method that combines ResNet and attention mechanism is adopted to extract defect area features through image enhancement, preprocessing, and UNet model encoder, and introduce CBAM attention mechanism to enhance feature representation to improve detection accuracy.

Benefits of technology

It improves the accuracy of PCB image segmentation, ensures accurate detection of micro defect areas, and reduces the amount of model calculation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120374640A_ABST
    Figure CN120374640A_ABST
Patent Text Reader

Abstract

The invention discloses a PCB semantic segmentation method fusing ResNet and an attention mechanism. The method comprises the following steps of performing defect segmentation area cutting and data enhancement on a PCB image; carrying out image smoothing filtering on the enhanced PCB defect image data set by adopting a generalization edge preserving and structure preserving image smoothing model, and inputting a UNet model encoder to extract defect area features; performing layer-by-layer down-sampling on the defect area features to obtain initial feature maps of different scales; inputting the initial feature maps of different scales into a CBAM module according to corresponding levels, and adding the feature maps processed by the CBAM attention mechanism with the initial feature maps of different scales by the CBAM module; and the UNet model decoder obtains the feature map of each layer of the CBAM module, recovers the image resolution layer by layer, obtains an image boundary, and outputs a defect segmentation result. According to the invention, the segmentation precision of PCB image detection can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of PCB semantic segmentation, and specifically relates to a PCB semantic segmentation method integrating ResNet and attention mechanism. Background Art

[0002] Printed circuit board (PCB) is a key component of intelligent products, carrying the connection of electronic components. With the increasing trend of integration of electronic products, the requirements for the quality and reliability of PCBs are also getting higher and higher. PCB defect detection is an important link to ensure product quality, and is of great significance for improving the performance of electronic products, extending service life and reducing maintenance costs. In the process of PCB production, due to the complex manufacturing process, each process may cause defects on the PCB surface. The surface contour information of defective products helps to accurately repair the products, thereby reducing production costs and improving product quality. The defects on the PCB surface are tiny, and the current defect detection algorithms have insufficient accuracy and fail to fully integrate sufficient defect information, resulting in the failure to effectively segment tiny defects. In view of the problem of tiny defects, how to fully extract defect feature information is a problem that needs to be studied currently. Summary of the Invention

[0003] In order to overcome the defects and deficiencies existing in the prior art, the present invention provides a PCB semantic segmentation method integrating ResNet and attention mechanism. When detecting PCB images, the present invention uses the DiffuseMix method for image enhancement, and uses a generalized edge-preserving and structure-preserving image smoothing model for image preprocessing to make the defect image features clearer. The UNet model encoder uses the ResNet50 network for downsampling operations to extract tiny defect region features at different levels, and introduces an attention mechanism to make the model focus on the defect region features, improving the segmentation accuracy of detecting PCB images.

[0004] In order to achieve the above purpose, the present invention adopts the following technical solutions:

[0005] The present invention provides a PCB semantic segmentation method integrating ResNet and attention mechanism, including the following steps:

[0006] Obtain a PCB image, perform defect segmentation area cropping and data augmentation on the PCB image to obtain an enhanced PCB defect image dataset;

[0007] Perform preprocessing operations on the enhanced PCB defect image dataset, and use a generalized edge-preserving and structure-preserving image smoothing model for image smoothing filtering;

[0008] Input the enhanced PCB defect image dataset processed by image smoothing filtering into the encoder of the UNet model. The encoder of the UNet model extracts the defect region features based on the ResNet50 network;

[0009] Perform layer-by-layer downsampling on the defect region features to obtain initial feature maps of different scales;

[0010] Input the initial feature maps of different scales into the CBAM module according to their corresponding levels. The CBAM module adds the feature maps processed by the CBAM attention mechanism to the initial feature maps of different scales respectively to enhance the defect region features;

[0011] The decoder of the UNet model obtains the feature maps of each layer of the CBAM module, restores the image resolution layer by layer to obtain the image boundary, and outputs the defect segmentation result.

[0012] As a preferred technical solution, perform defect segmentation region cropping and data augmentation on the PCB image, specifically including:

[0013] Perform defect segmentation region cropping on the PCB image to obtain the PCB defect image dataset, and unify the resolution in the PCB defect images to the same size;

[0014] Use the data augmentation technology DiffuseMix based on the diffusion model to perform data augmentation on the PCB defect image dataset to obtain the generated image

[0015] Concatenate the original image and the generated image to obtain image H iju , denoted as:

[0016]

[0017] Obtain the fractal image dataset, randomly select a fractal image and mix it into image H iju to obtain the enhanced image, denoted as:

[0018] A ijuv =ωF v +(1 - ω)H iju

[0019] where A ijuv represents the enhanced PCB defect image, ω represents the mixing factor, and F v represents the fractal image.

[0020] As a preferred technical solution, perform preprocessing operations on the enhanced PCB defect image dataset, and use the generalized edge-preserving and structure-preserving image smoothing model for image smoothing filtering, specifically including:

[0021] Construct the Huber penalty function, expressed as:

[0022]

[0023] where \(x\) represents the intensity of the input image, and \(a\) and \(b\) are constants;

[0024] Based on the Huber penalty function, construct the truncated Huber penalty function, expressed as:

[0025]

[0026] where \(a\leq b\);

[0027] Based on the truncated Huber penalty function, construct a smoothed filtering generalization model, set parameters, and select structure-preserving and edge-preserving models for image smoothing filtering.

[0028] As a preferred technical solution, set parameters and select structure-preserving and edge-preserving models for image smoothing filtering. The objective function is expressed as:

[0029]

[0030] where \(h\) T represents the truncated Huber penalty function, \(u\) represents the output image, \(f\) represents the input image, \(\{a\) d ,b\) d}\) and \(\{a\) s ,b\) s}\) respectively represent the parameters of the truncated Huber penalty function \(h\) T in the data term and the smoothing term, \(\lambda\) represents the weight factor, \(N\) d (i) and \(N\) s (i) are the neighbors with radii \(r\) d and \(r\) s centered at pixel \(i\), respectively. and are defined as follows:

[0031]

[0032] where \(g\) represents the guidance image;

[0033] By making different combinations of \(\{a\) d ,b\) d}\), \(\{a\) s ,b\) s}\), \(r\) d , \(r\) s , \(\alpha\), and the guidance image \(g\), select structure-preserving and edge-preserving models for image smoothing filtering.

[0034] As a preferred technical solution, the CBAM module includes a channel attention module and a spatial attention module;

[0035] The channel attention module performs global information aggregation. Through global average pooling and global max pooling operations, the spatial dimension of the input feature is compressed to 1, generating two channel feature maps;

[0036] After feature transformation, the two channel feature maps are subjected to feature transformation through a shared multi-layer perceptron to generate a channel attention map. The values of the channel attention map are normalized to the range [0, 1] through the Sigmoid function;

[0037] The channel attention map output by the channel attention module is input into the spatial attention module. The spatial attention module performs channel average pooling and max pooling respectively in the channel dimension, generating two spatial feature maps;

[0038] The two spatial feature maps are concatenated in the channel dimension, and then through average pooling, max pooling and a convolutional layer to obtain a spatial attention map. The values of the spatial attention map are normalized to the range [0, 1] through the Sigmoid function;

[0039] The output of the channel attention is multiplied by the output of the spatial attention to obtain the output of the CBAM attention mechanism, which is specifically expressed as:

[0040]

[0041] where, F represents the feature map input to the channel attention module, and M c (F) represents the output result of the channel attention module for the input feature map, represents element-wise multiplication, F′ represents the processing result of the feature map input to the spatial attention module, and M s (F′) represents the spatial attention module, and F″ is the final output result.

[0042] The present invention also provides a PCB semantic segmentation system integrating ResNet and an attention mechanism, including: a data augmentation module, a data preprocessing module, a UNet model encoder, an initial feature map extraction module, a CBAM module, and a UNet model decoder;

[0043] The data augmentation module is used to obtain a PCB image, perform defect segmentation area cropping and data augmentation on the PCB image to obtain an enhanced PCB defect image dataset;

[0044] The data preprocessing module is used to perform preprocessing operations on the enhanced PCB defect image dataset, and perform image smoothing filtering using a generalization edge-preserving and structure-preserving image smoothing model;

[0045] The encoder of the UNet model is used to obtain an enhanced PCB defect image dataset processed by image smoothing filtering, and extract defect region features based on the ResNet50 network;

[0046] The initial feature map extraction module is used to perform layer-by-layer downsampling on the defect region features to obtain initial feature maps of different scales;

[0047] The CBAM module is used to take the initial feature maps of different scales as inputs, add the feature maps processed by the CBAM attention mechanism to the initial feature maps of different scales respectively, and enhance the defect region features;

[0048] The decoder of the UNet model is used to obtain the feature maps of each layer of the CBAM module, restore the image resolution layer by layer to obtain the image boundary, and output the defect segmentation result.

[0049] As a preferred technical solution, defect segmentation region cropping and data augmentation are performed on the PCB image, specifically including:

[0050] Perform defect segmentation region cropping on the PCB image to obtain a PCB defect image dataset, and unify the resolutions in the PCB defect images to the same size;

[0051] Use the data augmentation technology DiffuseMix based on the diffusion model to perform data augmentation on the PCB defect image dataset to obtain generated images

[0052] Concatenate the original image and the generated image to obtain image H iju , expressed as:

[0053]

[0054] Obtain a fractal image dataset, randomly select fractal images and mix them into image H iju to obtain an enhanced image, expressed as:

[0055] A ijuv = ωF v +(1 - ω)H iju

[0056] where A ijuv represents the enhanced PCB defect image, ω represents the weight factor, and F v represents the fractal image.

[0057] As a preferred technical solution, the data preprocessing module is used to perform preprocessing operations on the enhanced PCB defect image dataset, and uses a generalization edge-preserving and structure-preserving image smoothing model for image smoothing filtering, specifically including:

[0058] Construct the Huber penalty function, expressed as:

[0059]

[0060] where x represents the intensity of the input image, and a and b are constants;

[0061] Based on the Huber penalty function, construct the truncated Huber penalty function, expressed as:

[0062]

[0063] where a ≤ b;

[0064] Based on the truncated Huber penalty function, construct a smoothed filtering generalization model, set parameters and select a structure-preserving and edge-preserving model for image smoothing filtering.

[0065] As a preferred technical solution, set parameters and select a structure-preserving and edge-preserving model for image smoothing filtering, and the objective function is expressed as:

[0066]

[0067] where h T represents the truncated Huber penalty function, u represents the output image, f represents the input image, {a d , b d} and {a s , b s} respectively represent the parameters of the truncated Huber penalty function h T in the data term and the smoothing term, λ represents the weight factor, N d (i) and N s (i) are the neighbors with radii r d and r s centered at pixel i respectively, and are defined as follows:

[0068]

[0069] where g represents the guidance image;

[0070] By making different combinations of {a d , b d}, {a s , b s}, r d , r s , α, and the guidance image g, select a structure-preserving and edge-preserving model for image smoothing filtering.

[0071] As a preferred technical solution, the CBAM module includes a channel attention module and a spatial attention module;

[0072] The channel attention module performs global information aggregation. Through global average pooling and global max pooling operations, the spatial dimension of the input feature is compressed to 1, generating two channel feature maps;

[0073] After feature transformation, the two channel feature maps are subjected to feature transformation through a shared multi-layer perceptron to generate a channel attention map. The values of the channel attention map are normalized to the range [0, 1] through the Sigmoid function;

[0074] The channel attention map output by the channel attention module is input into the spatial attention module. The spatial attention module performs channel average pooling and max pooling respectively in the channel dimension to generate two spatial feature maps;

[0075] The two spatial feature maps are concatenated in the channel dimension, and then through average pooling, max pooling and a convolutional layer to obtain a spatial attention map. The values of the spatial attention map are normalized to the range [0, 1] through the Sigmoid function;

[0076] The output of the channel attention is multiplied by the output of the spatial attention to obtain the output of the CBAM attention mechanism, which is specifically expressed as:

[0077]

[0078] Among them, F represents the feature map input to the channel attention module, M c (F) represents the output result of the channel attention module for the input feature map, represents element-wise multiplication, F′ represents the processing result of the feature map input to the spatial attention module, M s (F′) represents the spatial attention module, and F″ is the final output result.

[0079] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0080] The present invention improves the accuracy of the model in detecting defective areas by integrating ResNet50 and introducing an attention mechanism into the semantic segmentation model UNet. Before model training, the present invention performs image preprocessing operations, combines image processing methods and deep learning methods to make the accuracy of defective areas in the segmented images higher and reduce the model's computational workload; uses ResNet50 in the UNet model encoder to fully extract the feature information of tiny defective areas and improve the performance of the model in extracting tiny defective features; introduces the CBAM attention mechanism in the skip connection module to fuse channel attention and spatial attention mechanisms to enhance feature representation, and fuses the feature information from the skip connection module and the information in the upsampling process in the UNet model decoder, and performs feature superposition on the feature maps containing more context information, so as to accurately calculate the edge feature information of the defective areas, thereby improving the accuracy of defect segmentation. BRIEF DESCRIPTION OF THE DRAWINGS

[0081] Figure 1 It is a schematic flowchart of the PCB semantic segmentation method for integrating ResNet and attention mechanism of the present invention;

[0082] Figure 2 It is a schematic flowchart of using the DiffuseMix method for image enhancement of the present invention;

[0083] Figure 3 It is a schematic diagram of the network architecture of the PCB semantic segmentation method for integrating ResNet and attention mechanism of the present invention;

[0084] Figure 4 (a) It is a partial network structure schematic diagram of the UNet encoder of the present invention;

[0085] Figure 4 (b) It is a network structure schematic diagram of BottleNeck1 of the present invention;

[0086] Figure 4 (c) It is a network structure schematic diagram of BottleNeck2 of the present invention;

[0087] Figure 5 It is a network structure schematic diagram of the skip connection of the present invention;

[0088] Figure 6 (a) It is a schematic diagram of the defective area to be segmented;

[0089] Figure 6 (b) It is a schematic diagram of the defective area segmentation effect by only UNet;

[0090] Figure 6 (c) It is a schematic diagram of the defective area segmentation effect of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0091] To make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only for explaining the present invention and are not used to limit the present invention.

[0092] Embodiment 1

[0093] As Figure 1 shown, this embodiment provides a PCB semantic segmentation method integrating ResNet and attention mechanism, including the following steps:

[0094] S1: Obtain a PCB image, perform defect segmentation area cropping and data augmentation on the PCB image to obtain an enhanced PCB defect image dataset, specifically including:

[0095] S11: Crop the defect segmentation area of the PCB image to obtain a PCB defect image dataset, and unify the resolution in the PCB defect images to the same size;

[0096] S12: As Figure 2 shown, this embodiment uses the data augmentation technology DiffuseMix based on the diffusion model to perform data augmentation on the PCB defect image dataset. The diffusion model obtains a specified condition Pi from a set of predefined k, such as Mosaic, etc., and performs data augmentation according to the specified condition Pi to obtain a generated image

[0097] S13: Concatenate the original image and the generated image to avoid generating unrealistic images;

[0098] In this embodiment, the concatenation process is specifically as follows:

[0099] A mask M u randomly selected from the mask set is used to connect a part of the original input image I i with the corresponding generated image to obtain an image H iju , which is expressed as:

[0100]

[0101] S14: Obtain a fractal image dataset, randomly select a fractal image and mix it into the image H iju to obtain an enhanced image A ijuv , and further obtain an enhanced PCB defect image dataset. The enhanced image A ijuv is specifically expressed as:

[0102] A ijuv = ωF v +(1 - ω)Hiju

[0103] Among them, ω represents the mixing factor, and F v represents the fractal image;

[0104] In summary, the enhanced image A ijuv The overall construction process can be expressed as:

[0105]

[0106] S2: Preprocess the enhanced PCB defect image dataset, and use the generalized edge-preserving and structure-preserving image smoothing model for image smoothing filtering to enhance the defect image features, specifically including:

[0107] S21: Construct the Huber penalty function, which is expressed as:

[0108]

[0109] The above formula shows that it behaves as an L2 penalty function in the region where x < a, and as an L1 penalty function in the region greater than a;

[0110] S22: The truncated Huber penalty function is improved based on the Huber penalty function. Among them, a and b are constants, and the function is defined as follows:

[0111]

[0112] The truncated Huber can flexibly exhibit different characteristics under different parameter settings. Assuming that the intensity range of the input image is within [0, I m , then all edge intensities will also be within [0, I m . If a = ε is set to a sufficiently small value, and b > I m , the truncated Huber will not saturate like the Huber function, and at the same time, a sufficiently small a also exhibits the characteristics of an L1 penalty function for small inputs; if a = ε and b < I m , the truncated Huber will saturate before the edge intensity reaches the maximum value I m , so that it does not penalize strong edges while penalizing weak edges, thereby sharpening strong edges. This means that b can be used as a switch to adjust whether the truncated Huber function sharpens edges. On the other hand, if a = b > I m or a = b < I m , the function then exhibits the characteristics of an L2 penalty function, and a is the switch to control the ordinary L2 penalty function and the truncated L2 penalty function;

[0113] S23: Construct a smoothed filtering generalization model based on the truncated Huber penalty function, set parameters, and select a Structure-Preserving and Edge-Preserving (EP&SP) model for image smoothed filtering;

[0114] Based on the truncated Huber penalty function, construct an efficient objective function to achieve multifunctional smoothing. Given an input image f and a guidance image g, the output image u is the solution of the following objective function:

[0115]

[0116] where h T represents the truncated Huber penalty function, and {a d , b d} and {a s , b s} represent the parameters of the truncated Huber penalty function h T in the data term and the smoothing term of the energy function respectively. N d (i) and N s (i) are the neighbors with radii r d and r s centered at pixel i respectively. and are defined as follows respectively:

[0117]

[0118] where g represents the guidance image, δ = 1e-3. By making different combinations of {a d , b d}, {a s , b s}, r d , r s , α, and the guidance image g, the above model can achieve different smoothing characteristics, that is, different types of application tasks can be processed through different modes of the model. The specific parameter settings are as follows:

[0119] Table 1 Parameter settings for different tasks

[0120]

[0121] where ε represents a very small constant, I m represents the maximum intensity value of the input image f, and g = f means taking the input image as both the guidance image and the smoothing object;

[0122] S3: Use the enhanced PCB defect image dataset processed by image smoothing filtering as the input of the encoder of the UNet model. In the UNet model encoder, the ResNet50 network is used for downsampling operations to extract feature maps of tiny defect regions at different levels.

[0123] As Figure 3 shown, there are 5 Stages in the ResNet50 network, specifically Stage0, Stage1, Stage2, Stage3, and Stage4. Replace the Stage0 layer with a CONV convolution operation to reduce the model's computational complexity and initially extract features. The input defect image passes through Stage0, Stage1, Stage2, Stage3, and Stage4 in sequence. By gradually deepening the network layers, features are extracted step by step from low levels to high levels. State1 is used to extract low-level features, Stage2 is used to extract middle-level features, Stage3 is used to extract high-level features, and Stage4 integrates all features and outputs to generate a feature map effective for the segmentation task. As Figure 4 (a)- Figure 4 (c) shown, the Bottleneck1 and Bottleneck2 structures are respectively included in Stage1, Stage2, Stage3, and Stage4. These structures effectively reduce the model's computational complexity and improve the model's performance in extracting defect features.

[0124] In this embodiment, the Bottleneck1 structure requires four parameters for input: C, W, C1, and S, which respectively represent the number of input channels, the size of the input feature map, the number of output channels, and the stride of the convolutional layer. This structure passes the input through a convolutional layer and three convolutional blocks, adds the outputs G(X) and F(X), and then passes through the ReLU activation function to obtain the output result.

[0125] In this embodiment, the Bottleneck2 structure requires two parameters for input: C and W, which respectively represent the number of input channels and the size of the input feature map. The Bottleneck2 structure passes the input through three convolutional blocks to output F(X), adds F(X) and X, and then passes through the ReLU activation function to obtain the output result.

[0126] S4: Introduce the CBAM attention mechanism in the skip connection part of the UNet model to enable the model to focus on the feature information of the defect region.

[0127] In this embodiment, the attention mechanism is applied to the skip connection part of the UNet model. In the encoder part of the UNet model, the feature maps obtained after the operation in step S3 are downsampled layer by layer, that is, the feature maps obtained through module F1, module F2, module F3, and module F4 are respectively fed into the CBAM modules of the corresponding layers.

[0128] In this embodiment, the size of the input image is 320×320. After successive downsampling operations layer by layer, feature maps of 160×160, 80×80, 40×40, and 20×20 are obtained after passing through module F1, module F2, module F3, and module F4 respectively. The feature maps of different scales are fed into the CBAM module according to their corresponding levels. The operation of each layer of the CBAM module is to add the feature maps processed by the CBAM attention mechanism to the feature maps of their corresponding layers, namely module F1, module F2, module F3, and module F4 respectively, to obtain the output feature maps of different layers of the CBAM module. This operation is to enhance the features of the defect area;

[0129] In this embodiment, the CBAM attention mechanism combines the channel attention mechanism and the spatial attention mechanism. Specifically, the CBAM module includes a channel attention module and a spatial attention module. The channel attention module first performs global information aggregation. Through global average pooling and global max pooling operations, the spatial dimension of the input feature is compressed to 1 to generate two channel feature maps. Secondly, after feature transformation, the two channel feature maps are subjected to feature transformation through a shared multi-layer perceptron to generate a channel attention map. Finally, the values of the channel attention map are normalized to the range [0, 1] through the Sigmoid function;

[0130] After the image passes through the channel attention module, it enters the spatial attention module. First, channel max pooling and average pooling are respectively performed on the channel dimension to generate two empty feature maps. Secondly, the two spatial feature maps are concatenated on the channel dimension, and a spatial attention map is generated through a convolutional layer. Finally, the values of the spatial attention map are normalized to the range [0, 1] through the Sigmoid function. The calculation formula of the channel attention module is as follows:

[0131]

[0132] where M c ∈R C×1×1 ,M c (F) represents the output result of the channel attention module for the input feature map, and W0 and W1 are the parameter weights of the first layer and the second layer of the MLP respectively.

[0133] The calculation formula of the spatial attention module is as follows:

[0134]

[0135] where M s ∈R 1×H×W ,M s (F) is a two-dimensional spatial attention feature map.

[0136] Multiply the output of the channel attention by the output of the spatial attention to obtain the output of the CBAM attention mechanism. The formula is as follows:

[0137]

[0138] where F represents the feature map input to the channel attention module, and M c (F) represents the output result of the channel attention module for the input feature map, denotes element-wise multiplication, F′ represents the processing result of the feature map input to the spatial attention module, and M s (F′) represents the spatial attention module, and F″ is the final output result.

[0139] S5: Use the decoder of the UNet model to refine to the size of the original PCB image to obtain the defect segmentation result;

[0140] In this embodiment, the decoder part of the UNet model fuses the upsampling and the feature information of each layer of the CBAM module from the operation in S4. The decoder part of the UNet model restores the image resolution layer by layer, and maps the high-level feature extracted by the model back to the original image resolution through module F6, module F7, and module F8 in sequence. The decoder of the UNet model contains an upsampling operation and combines the corresponding feature layers from the CBAM module to achieve fine image boundary restoration.

[0141] Combined Figure 3 As shown, modules F1, F2, F3, F4, F5, F6, F7, and F8 are all network structures of a conv2d layer + BN layer + ReLU layer;

[0142] As Figure 5 shown, the size of the input defect image is 320×320. After successive downsampling operations, it becomes 160×160, 80×80, 40×40, 20×20. The upsampling operation restores the image to 20×20, 40×40, 80×80, and 160×160 layer by layer, and finally obtains the defect segmentation result;

[0143] In this embodiment, the network model of the segmentation result uses the cross-entropy loss as the error loss function. The formula is as follows:

[0144]

[0145] where y i and p i correspond to the true label and predicted probability of the i-th category, and n represents the number of categories;

[0146] In this embodiment, ResNet50 is integrated into the encoder module of the UNet model to fully extract the feature information of tiny defects. The CBAM attention mechanism is introduced into the model skip connection module, enabling the model to pay more attention to the feature information of the defect area. Finally, the decoder module of the UNet model fully integrates the information from the skip connection module and the upsampled feature information to ensure that different tiny defect features are fully integrated, thereby improving the accuracy of defect segmentation. As shown in Figure 6 (a)- Figure 6 (c), the edges of the present invention are clear and the detailed information is complete, and the segmentation effect is better than that of only using the UNet method.

[0147] The above embodiments are the preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications made without departing from the spirit and principle of the present invention shall be equivalent replacement methods and are all included in the protection scope of the present invention.

Claims

1. A PCB semantic segmentation method integrating ResNet and attention mechanism, characterized in that, It includes the following steps: Obtain a PCB image, perform defect segmentation region cropping and data augmentation on the PCB image to obtain an enhanced PCB defect image dataset; Perform preprocessing operations on the enhanced PCB defect image dataset, and use a generalized edge-preserving and structure-preserving image smoothing model for image smoothing filtering; Input the enhanced PCB defect image dataset processed by image smoothing filtering into the UNet model encoder, and the UNet model encoder extracts defect region features based on the ResNet50 network; Perform layer-by-layer downsampling on the defect region features to obtain initial feature maps of different scales; Input the initial feature maps of different scales into the CBAM module according to their corresponding levels. The CBAM module adds the feature maps processed by the CBAM attention mechanism to the initial feature maps of different scales respectively to enhance the defect region features; The UNet model decoder obtains the feature maps of each layer of the CBAM module, restores the image resolution layer by layer to obtain the image boundary, and outputs the defect segmentation result.

2. The PCB semantic segmentation method integrating ResNet and attention mechanism according to claim 1, wherein Performing defect segmentation region cropping and data augmentation on the PCB image specifically includes: Perform defect segmentation region cropping on the PCB image to obtain a PCB defect image dataset, and unify the resolution in the PCB defect images to the same size; Use the data augmentation technique DiffuseMix based on the diffusion model to perform data augmentation on the PCB defect image dataset to obtain generated images The original image and the generated image are connected in series to obtain image H iju , which is expressed as: Obtain a fractal image dataset and randomly select fractal images to be mixed into image H iju to obtain an enhanced image, denoted as: A ijuv = ωF v + (1 - ω)H iju Among them, A ijiv represents the enhanced PCB defect image, ω represents the mixing factor, and F v represents the fractal image.

3. The PCB semantic segmentation method integrating ResNet and attention mechanism according to claim 1, characterized in that, Perform preprocessing operations on the enhanced PCB defect image dataset, and use a generalized edge-preserving and structure-preserving image smoothing model for image smoothing filtering, specifically including: Construct a Huber penalty function, expressed as: where x represents the intensity of the input image, and a and b are constants; Construct a truncated Huber penalty function based on the Huber penalty function, expressed as: where a ≤ b; Construct a smoothing filtering generalization model based on the truncated Huber penalty function, set parameters and select a structure-preserving and edge-preserving model for image smoothing filtering.

4. The PCB semantic segmentation method integrating ResNet and attention mechanism according to claim 3, characterized in that, Set parameters and select a structure-preserving and edge-preserving model for image smoothing filtering. The objective function is expressed as: where h T represents the truncated Huber penalty function, u represents the output image, f represents the input image, {a d , b d} and {a s , b s} represent the parameters of the truncated Huber penalty function h T in the data term and the smooth term respectively, λ represents the weight factor, N d (i) and N s (i) are the neighbors with radii r d and r s centered at pixel i respectively, and are defined as follows: where g represents the guiding image; By performing different combinations on {a d , b d}, {a s , b s}, r d , r s , α, and the guiding image g, a structure-preserving and edge-preserving model is selected for image smoothing filtering.

5. The PCB semantic segmentation method integrating ResNet and attention mechanism according to claim 1, characterized in that The CBAM module includes a channel attention module and a spatial attention module; The channel attention module performs global information aggregation. Through global average pooling and global maximum pooling operations, the spatial dimension of the input features is compressed to 1 to generate two channel feature maps; After feature transformation, the two channel feature maps are subjected to feature transformation through a shared multi-layer perceptron to generate a channel attention map, and the values of the channel attention map are normalized to the range of [0, 1] through the Sigmoid function; Input the channel attention map output by the channel attention module into the spatial attention module. The spatial attention module performs channel average pooling and maximum pooling respectively in the channel dimension to generate two spatial feature maps; Connect the two spatial feature maps in the channel dimension, and then obtain a spatial attention map through average pooling, maximum pooling and a convolutional layer. The values of the spatial attention map are normalized to the range of [0, 1] through the Sigmoid function; Multiply the output of the channel attention by the output of the spatial attention to obtain the output of the CBAM attention mechanism, specifically expressed as: Among them, F represents the feature map of the input channel attention module, and M c (F) represents the output result of the channel attention module for the input feature map, represents element-wise multiplication, F′ represents the processing result of the feature map of the input spatial attention module, and M s (F′) represents the spatial attention module, and F″ is the final output result.

6. A PCB semantic segmentation system integrating ResNet and attention mechanism, characterized in that It includes: Data augmentation module, data preprocessing module, UNet model encoder, initial feature map extraction module, CBAM module, UNet model decoder; The data augmentation module is used to obtain PCB images, perform defect segmentation area cropping and data augmentation on the PCB images, and obtain an enhanced PCB defect image dataset; The data preprocessing module is used to perform preprocessing operations on the enhanced PCB defect image dataset, and perform image smoothing filtering using a generalized edge-preserving and structure-preserving image smoothing model; The UNet model encoder is used to obtain the enhanced PCB defect image dataset processed by image smoothing filtering, and extract defect area features based on the ResNet50 network; The initial feature map extraction module is used to perform layer-by-layer downsampling on the defect area features to obtain initial feature maps of different scales; The CBAM module is used to take the initial feature maps of different scales as inputs, add the feature maps processed by the CBAM attention mechanism to the initial feature maps of different scales respectively, and enhance the defect area features; The UNet model decoder is used to obtain the feature maps of each layer of the CBAM module, restore the image resolution layer by layer to obtain the image boundary, and output the defect segmentation result.

7. The PCB semantic segmentation system integrating ResNet and attention mechanism according to claim 6, characterized in that Performing defect segmentation area cropping and data augmentation on the PCB image specifically includes: Performing defect segmentation area cropping on the PCB image to obtain a PCB defect image dataset, and unifying the resolution in the PCB defect images to the same size; Use the data augmentation technique DiffuseMix based on the diffusion model to augment the PCB defect image dataset to obtain generated images The original image and the generated image are connected in series to obtain image H iju , which is expressed as: Obtain a fractal image dataset and randomly select fractal images to be mixed into image H iju to obtain an enhanced image, denoted as: A ijuv = ωF v + (1 - ω)H iju Among them, A ijuv represents the enhanced PCB defect image, ω represents the weight factor, and F v represents the fractal image.

8. The PCB semantic segmentation system integrating ResNet and attention mechanism according to claim 6, characterized in that, The data preprocessing module is used to perform preprocessing operations on the enhanced PCB defect image dataset, and perform image smoothing filtering using a generalized edge-preserving and structure-preserving image smoothing model, specifically including: Construct a Huber penalty function, expressed as: where x represents the intensity of the input image, and a and b are constants; Construct a truncated Huber penalty function based on the Huber penalty function, expressed as: where a ≤ b; Construct a smoothing filtering generalization model based on the truncated Huber penalty function, set parameters and select a structure-preserving and edge-preserving model for image smoothing filtering.

9. The PCB semantic segmentation system integrating ResNet and attention mechanism according to claim 8, characterized in that, Set parameters and select a structure-preserving and edge-preserving model for image smoothing filtering, and the objective function is expressed as: where h T represents the truncated Huber penalty function, u represents the output image, f represents the input image, {a d , b d} and {a s , b s} represent the parameters of the truncated Huber penalty function h T in the data term and the smooth term respectively, λ represents the weight factor, N d (i) and N s (i) are the neighbors with radii r d and r s centered at pixel i respectively, and are defined as follows: where g represents the guidance image; By making different combinations of {a d , b d}, {a s , b s}, r d , r s , α, and the guiding image g, select a structure-preserving and edge-preserving model for image smoothing filtering.

10. The PCB semantic segmentation system integrating ResNet and attention mechanism according to claim 6, characterized in that, The CBAM module includes a channel attention module and a spatial attention module; The channel attention module performs global information aggregation. Through global average pooling and global max pooling operations, the spatial dimension of the input features is compressed to 1 to generate two channel feature maps; After feature transformation, the two channel feature maps are subjected to feature transformation through a shared multi-layer perceptron to generate a channel attention map, and the values of the channel attention map are normalized to the range of [0, 1] through the Sigmoid function; Input the channel attention map output by the channel attention module into the spatial attention module. The spatial attention module performs channel average pooling and max pooling respectively in the channel dimension to generate two spatial feature maps; Connect two spatial feature maps in the channel dimension, and then obtain a spatial attention map through average pooling, max pooling, and convolutional layers. Normalize the values of the spatial attention map to the range of [0, 1] through the Sigmoid function; Multiply the output of the channel attention by the output of the spatial attention to obtain the output of the CBAM attention mechanism, which is specifically expressed as: Among them, F represents the feature map of the input channel attention module, and M c (F) represents the output result of the channel attention module for the input feature map, represents element-wise multiplication, F′ represents the processing result of the feature map of the input spatial attention module, and M s (F′) represents the spatial attention module, and F′′ is the final output result.

Citation Information

Cited By

  • PCB schematic diagram wire instance segmentation method and device based on pixel connectivity analysis

    CN121259861A

  • Industrial material segmentation and size measurement method based on deep learning

    CN121685546A