PCB anomaly detection method, device and equipment based on diffusion model

Through the PCB abnormality detection method trained by the diffusion model, combined with Gerber design information and real images, the style migration from Gerber image to real images is realized, solving the problem of inaccurate abnormality detection of PCB boards in the prior art, and improving the accuracy and efficiency of detection.

CN120375079APending Publication Date: 2025-07-25PAZHOU LAB (HUANGPU)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510485324.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-17
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

The prior art is difficult to effectively and accurately realize abnormal detection of PCB boards, especially due to the differences in material texture and color contrast between Gerber design drawings and real images, resulting in inaccurate detection of traditional AOI devices.

Method used

By using the diffusion model to train the PCB anomaly detection model, combining aligned defect-free PCB real-life images and Gerber training images and their design information, the style transfer from Gerber images to real-life images is realized, and the cross attention mechanism and loss function optimization are used to generate a reconstructed image consistent with the style of the real-life image.

Benefits of technology

Accurate abnormality detection of various components in the PCB board is achieved, which improves detection accuracy and reduces error detection rate.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120375079A_ABST
    Figure CN120375079A_ABST
Patent Text Reader

Abstract

The invention discloses a PCB anomaly detection method, device and equipment based on a diffusion model, and the method comprises the steps: training a diffusion model through employing a defect-free PCB physical image and a Gerber training image which are aligned, and corresponding Gerber design information, thereby obtaining a PCB anomaly detection model; therefore, the PCB anomaly detection model can realize style migration from the Gerber image to the PCB real object image based on the guidance of the Gerber design information, and in the actual PCB anomaly detection process, the target Gerber image can be accurately and effectively reconstructed into the reconstructed image consistent with the target real object image in style, so that the image reconstruction efficiency is improved. And accurate anomaly detection can be carried out on various PCB components in the to-be-detected PCB by using the reconstructed image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of PCBs, and in particular, to a method, device, and electronic device for PCB anomaly detection based on a diffusion model. Background Art

[0002] During the production process of a PCB (Printed Circuit Board), anomaly detection is an important step, aiming to timely detect and eliminate manufacturing anomalies of products to ensure product quality and safety. The manufacturing of a PCB board must strictly comply with requirements such as electrical connections, pad sizes, and line spacings in Gerber design drawings. Any minor deviation (such as breakage, open circuit, or drilling offset) may lead to product failure or even terminal device malfunction. Since Gerber design drawings are abstract vector graphics, there are significant differences in material texture and color contrast between them and the physical images captured by industrial cameras. Therefore, traditional AOI (Automated Optical Inspection) devices have a bottleneck of inconsistent standards during detection, which easily causes misdetection.

[0003] In the prior art, anomaly detection models based on single-class reconstruction, such as the DeStSeg model and the EfficientAD model, are usually used to detect anomalies in PCB boards. However, such anomaly detection models are difficult to reconstruct physical PCB images with diverse design styles and complex textures, so it is difficult for the prior art to effectively and accurately achieve anomaly detection of PCB boards. Summary of the Invention

[0004] Embodiments of the present invention provide a method, device, and equipment for PCB anomaly detection based on a diffusion model to solve the technical problem that it is difficult for the prior art to effectively and accurately achieve anomaly detection of PCB boards.

[0005] To solve the above technical problem, a first aspect of an embodiment of the present invention provides a method for PCB anomaly detection based on a diffusion model, including:

[0006] Rendering a target Gerber vector file corresponding to a PCB board to be tested into a target Gerber image;

[0007] Input the target physical image, target Gerber design information of the PCB board to be tested, and the target Gerber image into the PCB anomaly detection model to obtain the anomaly detection result of the PCB board to be tested output by the PCB anomaly detection model; wherein, the PCB anomaly detection model is obtained by training a diffusion model using a PCB image training set, and the PCB image training set includes several groups of aligned images containing defect-free PCB physical images and Gerber training images and their corresponding Gerber design information.

[0008] As a preferred solution, the method specifically generates the PCB image training set through the following steps:

[0009] Based on several of the Gerber training images, obtain several template images;

[0010] Perform binarization processing on several of the defect-free PCB physical images to obtain several binary images;

[0011] Use the template matching method to match several of the template images with several of the binary images to obtain several groups of matching template images and binary images, and determine the image transformation parameters between each group of matching template images and binary images;

[0012] Based on each group of matching template images and binary images, determine several groups of matching defect-free PCB physical images and Gerber training images, and perform geometric transformation on the defect-free PCB physical images using the image transformation parameters;

[0013] Align each group of geometrically transformed defect-free PCB physical images and Gerber training images to obtain several groups of initial aligned images;

[0014] Crop each group of the initial aligned images according to a preset cropping size to obtain several groups of the aligned images;

[0015] Query the Gerber design information according to the coordinates of the aligned images, and bind the queried Gerber design information to the aligned images to generate the PCB image training set.

[0016] As a preferred solution, the method specifically trains the diffusion model through the following steps:

[0017] Taking the minimization of a preset loss function as the training objective, the diffusion model is trained using the PCB image training set to obtain the PCB anomaly detection model; wherein, the loss function is a weighted sum of a classification loss, a localization loss, and a reconstruction loss; the classification loss is used to measure the error of the diffusion model in PCB anomaly classification; the localization loss is used to measure the error of the diffusion model in PCB anomaly localization; and the reconstruction loss is used to measure the error of the diffusion model in reconstructing the features of a Gerber image into the features of a physical style image.

[0018] As a preferred solution, inputting the target physical image, the target Gerber design information, and the target Gerber image of the PCB to be tested into the PCB anomaly detection model to obtain the anomaly detection result of the PCB to be tested output by the PCB anomaly detection model specifically includes:

[0019] Preprocessing the target physical image and the target Gerber image to obtain a preprocessed target physical image and a preprocessed target Gerber image;

[0020] Encoding the target Gerber design information to obtain a target semantic vector;

[0021] Inputting the preprocessed target physical image, the preprocessed target Gerber image, and the target semantic vector into the PCB anomaly detection model, and using the PCB anomaly detection model to respectively extract features from the preprocessed target physical image and the preprocessed target Gerber image to obtain target physical image features and target Gerber image features;

[0022] Based on the target semantic vector, using a cross-attention mechanism to reconstruct the target Gerber image features to obtain target reconstruction features with an image style consistent with that of the target physical image;

[0023] Performing a pixel-by-pixel comparison between the target physical image features and the target reconstruction features to obtain the anomaly detection result of the PCB to be tested.

[0024] As a preferred solution, based on the target semantic vector, using a cross-attention mechanism to reconstruct the target Gerber image features to obtain target reconstruction features with an image style consistent with that of the target physical image specifically includes:

[0025] Adding Gaussian noise to the target Gerber image features to obtain Gaussian noise image features;

[0026] Introduce the target semantic vector for the Gaussian noise image feature by using the cross-attention mechanism to obtain the latent representation feature;

[0027] Perform noise reduction processing on the latent representation feature to obtain the target reconstruction feature with the same image style as the target physical image and the image style of the target object.

[0028] As a preferred solution, the step of comparing the target physical image feature with the target reconstruction feature pixel by pixel to obtain the abnormal detection result of the PCB to be tested specifically includes:

[0029] Calculate the cosine similarity between the target physical image feature and the target reconstruction feature at each pixel;

[0030] Obtain a number of abnormal pixels whose cosine similarity is less than a preset cosine similarity threshold;

[0031] Determine the abnormal type and abnormal position of the PCB to be tested according to the target physical image feature at each abnormal pixel and the position information of each abnormal pixel.

[0032] As a preferred solution, the step of rendering the target Gerber vector file corresponding to the PCB to be tested into a target Gerber image specifically includes:

[0033] Based on the pcb-tools open source library, render the target Gerber vector file into the target Gerber image.

[0034] As a preferred solution, the target Gerber design information includes the drilling layer information, pad layer information, oil printing substrate layer information, silk screen layer information, and circuit layer information of the PCB to be tested.

[0035] The second aspect of the embodiments of the present invention provides a PCB abnormal detection device based on a diffusion model, including:

[0036] A Gerber image generation module, configured to render the target Gerber vector file corresponding to the PCB to be tested into a target Gerber image;

[0037] A PCB abnormal detection module, configured to input the target physical image, target Gerber design information, and the target Gerber image of the PCB to be tested into a PCB abnormal detection model, and obtain the abnormal detection result of the PCB to be tested output by the PCB abnormal detection model; wherein, the PCB abnormal detection model is obtained by training a diffusion model with a PCB image training set, and the PCB image training set includes several groups of aligned images containing defect-free PCB physical images and Gerber training images and their corresponding Gerber design information.

[0038] In the third aspect of the embodiments of the present invention, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for detecting PCB anomalies based on a diffusion model according to any one of the first aspect is implemented.

[0039] Compared with the prior art, the beneficial effect of the embodiments of the present invention is that by using aligned defect-free PCB physical images and Gerber training images, as well as the corresponding Gerber design information to train a diffusion model to obtain a PCB anomaly detection model, the PCB anomaly detection model can realize the style transfer from the Gerber image to the PCB physical image under the guidance of the Gerber design information. In the actual PCB anomaly detection process, the target Gerber image can be accurately and effectively reconstructed into a reconstructed image with the same style as the target physical image, and then the reconstructed image can be used to accurately detect various PCB components in the PCB board to be tested for anomalies. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 is a schematic flowchart of the method for detecting PCB anomalies based on a diffusion model in the embodiments of the present invention;

[0041] Figure 2 is a reasoning flowchart of the PCB anomaly detection model in the embodiments of the present invention;

[0042] Figure 3 is a schematic structural diagram of the device for detecting PCB anomalies based on a diffusion model in the embodiments of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0043] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0044] Please refer to Figure 1 , in the first aspect of the embodiments of the present invention, a method for detecting PCB anomalies based on a diffusion model is provided, including the following steps S1 and S2:

[0045] Step S1, rendering the target Gerber vector file corresponding to the PCB board to be tested into a target Gerber image;

[0046] Step S2, input the target physical image, target Gerber design information, and the target Gerber image of the PCB to be tested into the PCB anomaly detection model, and obtain the anomaly detection result of the PCB to be tested output by the PCB anomaly detection model; wherein, the PCB anomaly detection model is obtained by training a diffusion model using a PCB image training set, and the PCB image training set includes several groups of aligned images containing defect-free PCB physical images and Gerber training images and their corresponding Gerber design information.

[0047] Specifically, the Gerber vector file is an industry-standard file format used in the field of PCB design and manufacturing to accurately describe circuit board information. It records various design data of the PCB in the form of vector graphics. Different from bitmaps (such as common JPEG, PNG, etc. formats), vector graphics are composed of elements such as lines, shapes, curves defined by mathematical formulas, and will not distort no matter how they are scaled, and can accurately present the design details of the PCB. The Gerber vector file contains rich PCB design information, covering key contents such as electrical connections, pad sizes, and line spacings. These design information accurately specify the positions, shapes of each component on the PCB and their connection relationships, which are important bases for the PCB manufacturing process and also important bases for PCB anomaly detection. In order to be able to compare with the target physical image of the PCB to be tested, it is necessary to first render the target Gerber vector file corresponding to the PCB to be tested into a target Gerber image.

[0048] Further, the target physical image, target Gerber design information, and target Gerber image of the PCB to be tested are input into the PCB anomaly detection model to obtain the anomaly detection result of the PCB to be tested. It should be noted that the PCB to be tested in this embodiment may include various types of PCB components, such as pads, substrates, circuits, etc. During the PCB anomaly detection process, it is necessary to transfer the style of the target Gerber image to be consistent with the style of the target physical image. To avoid cross-category confusion, this embodiment needs to introduce the target Gerber design information to guide the generation of the physical style image. Further, to avoid blurred reconstruction, this embodiment uses the aligned defect-free PCB physical image and Gerber training image to train the diffusion model to obtain the PCB anomaly detection model. It can be understood that the diffusion model is a type of generative model constructed based on the principle of the physical diffusion process. It simulates the physical diffusion process and starts from the initial Gaussian noise distribution and gradually "diffuses" towards the target data distribution. In the forward process, according to a certain noise schedule, Gaussian noise is gradually added to the data (such as pictures) until the data completely becomes noise; the reverse process starts from the completely noisy state and gradually removes the noise through a neural network to restore meaningful data. Taking the image generation task as an example, in the forward process, a clear image is gradually turned into a noisy image, and in the reverse process, the trained model is used to "reconstruct" a new image similar to the original image from the noise. Each defect-free PCB physical image should include multiple different types of PCB components, so that the components at different positions in the Gerber training image can be cross-domain corresponded to the defect-free physical components, and the physical textures and materials corresponding to the components at different positions in the Gerber training image can be fully learned, laying a foundation for the clear reconstruction of the physical style image.

[0049] The PCB anomaly detection method based on the diffusion model provided by the embodiment of the present invention trains the diffusion model by using the aligned defect-free PCB physical image, Gerber training image, and the corresponding Gerber design information to obtain the PCB anomaly detection model. Thus, the PCB anomaly detection model can realize the style transfer from the Gerber image to the PCB physical image based on the guidance of the Gerber design information. During the actual PCB anomaly detection process, the target Gerber image can be accurately and effectively reconstructed into a reconstructed image with the same style as the target physical image, and then the reconstructed image can be used to accurately detect various PCB components in the PCB to be tested.

[0050] As a preferred solution, the method specifically generates the PCB image training set through the following steps:

[0051] Based on a number of the Gerber training images, a number of template images are obtained;

[0052] Perform binary processing on a number of the defect-free PCB physical images to obtain a number of binary images;

[0053] Use the template matching method to match a number of the template images with a number of the binary images, obtain a number of sets of matching template images and binary images, and determine the image transformation parameters between each set of matching template images and binary images;

[0054] Based on each set of matching template images and binary images, determine a number of sets of matching defect-free PCB physical images and Gerber training images, and perform geometric transformation on the defect-free PCB physical images using the image transformation parameters;

[0055] Align each set of geometrically transformed defect-free PCB physical images and Gerber training images to obtain a number of sets of initially aligned images;

[0056] Crop each set of the initially aligned images according to a preset cropping size to obtain a number of sets of the aligned images;

[0057] Query the Gerber design information according to the coordinates of the aligned images, and bind the queried Gerber design information to the aligned images to generate the PCB image training set.

[0058] Specifically, this embodiment realizes the cross-domain alignment between the defect-free PCB physical image and the Gerber training image based on the template matching technology. First, based on a number of Gerber training images, a number of template images are obtained. For example, pads with specific shapes or traces with specific orientations in the Gerber training images can be used as template images, and this embodiment does not make specific limitations here. Further, in order to reduce the dimension of image information, speed up the subsequent calculation speed, and at the same time highlight the geometric features of the image for easy template matching, this embodiment performs binarization processing on a number of defect-free PCB physical images to obtain a number of binary images, and then uses the template matching method to match the number of template images with the number of binary images. Exemplarily, common matching algorithms include algorithms based on gray values and algorithms based on features. Algorithms based on gray values such as Sum of Absolute Differences (SAD) and Normalized Cross-Correlation (NCC). The SAD algorithm measures the similarity by calculating the sum of the squares of the differences in pixel gray values of the same-sized regions between the template image and the binary image. The smaller the sum of squares, the higher the similarity; the NCC algorithm calculates the normalized cross-correlation coefficient between the template image and the target region, and the closer the coefficient is to 1, the higher the similarity. Algorithms based on features first extract the features of the template image and the binary image, such as edges, corners, etc., and then perform matching according to the similarity of the features. This algorithm has better adaptability to changes such as rotation and scaling of the image.

[0059] During the template algorithm matching process, in addition to obtaining several groups of matching template images and binary images, it is also possible to determine the image transformation parameters between each group of matching template images and binary images, such as translation parameters, rotation parameters, and scaling parameters, etc. These image transformation parameters are used to perform geometric transformation on the defect-free PCB physical image to achieve the precise cross-domain alignment between the defect-free PCB physical image and the Gerber training image, forming several groups of initial aligned images.

[0060] Further, according to a preset cropping size, such as a 128×128 pixel size, each group of initial aligned images is cropped to obtain several groups of aligned images. Then, the corresponding Gerber design information is queried according to the coordinates of the cropped aligned images, and the queried Gerber design information is bound to the aligned images to generate a PCB image training set.

[0061] As a preferred solution, the method specifically trains the diffusion model through the following steps:

[0062] Taking the minimization of a preset loss function as the training objective, the diffusion model is trained using the PCB image training set to obtain the PCB anomaly detection model; wherein, the loss function is a weighted sum of a classification loss, a localization loss, and a reconstruction loss; the classification loss is used to measure the error of the diffusion model in PCB anomaly classification; the localization loss is used to measure the error of the diffusion model in PCB anomaly localization; the reconstruction loss is used to measure the error of the diffusion model in reconstructing the features of a Gerber image into the features of a physical style image.

[0063] Specifically, the loss function in this embodiment can be expressed as:

[0064]

[0065] Wherein, represents the total loss value of the loss function, represents the classification loss, represents the localization loss, represents the reconstruction loss.

[0066] The PCB image training set is preprocessed. For example, the aligned defect-free PCB physical images and Gerber training images are respectively scaled to a resolution of 256×256, and then normalized. At the same time, the Gerber design information is encoded into a vector format. Then, the preprocessed defect-free PCB physical image - Gerber training image - semantic vector is input into the diffusion model. The feature extractor is used to extract the features of the defect-free PCB physical image and the Gerber training image respectively. Then, the diffusion model is used to encode the Gerber training image features into latent representation features. The latent representation features are reconstructed by combining the semantic-guided cross-attention mechanism of the input text information. The latent representation features are denoised and reconstructed into the features of a physical style image. Finally, the difference between the reconstructed features and the features of the defect-free PCB physical image is calculated pixel by pixel, and the above loss function is used to calculate the difference tensor for gradient backpropagation to optimize the diffusion model and achieve the style transfer from the Gerber image to the physical image.

[0067] As a preferred solution, the step of inputting the target physical image, the target Gerber design information, and the target Gerber image of the PCB to be tested into the PCB anomaly detection model to obtain the anomaly detection result of the PCB to be tested output by the PCB anomaly detection model specifically includes:

[0068] Preprocess the target physical image and the target Gerber image to obtain the preprocessed target physical image and the preprocessed target Gerber image;

[0069] Encode the target Gerber design information to obtain a target semantic vector;

[0070] Input the preprocessed target physical image, the preprocessed target Gerber image, and the target semantic vector into the PCB anomaly detection model, and use the PCB anomaly detection model to extract features from the preprocessed target physical image and the preprocessed target Gerber image respectively to obtain target physical image features and target Gerber image features;

[0071] Based on the target semantic vector, use the cross-attention mechanism to reconstruct the target Gerber image features to obtain target reconstruction features with an image style consistent with that of the target physical image;

[0072] Compare the target physical image features and the target reconstruction features pixel by pixel to obtain the anomaly detection result of the PCB under test.

[0073] Specifically, when performing PCB anomaly detection in this embodiment, it is first necessary to preprocess the target physical image and the target Gerber image. For example, scale the paired target physical image and target Gerber image to a resolution of 256×256 respectively, and then perform normalization processing to complete the preprocessing of the images.

[0074] Furthermore, use a pre-trained CLIP text encoder, freeze its parameters, encode the target Gerber design information to obtain a target semantic vector; then input the preprocessed target physical image, the preprocessed target Gerber image, and the target semantic vector into the PCB anomaly detection model, and use the PCB anomaly detection model to extract features from the preprocessed target physical image and the preprocessed target Gerber image respectively. Exemplarily, set a feature extractor in the PCB anomaly detection model, such as using a pre-trained HGNetv2 network with frozen parameters, so as to use this feature extractor to achieve the extraction of target physical image features and target Gerber image features.

[0075] Furthermore, this embodiment combines the target semantic vector of the input text information to guide the cross-attention mechanism to reconstruct the target Gerber image features. By guiding the generation process of the reconstruction features with the target Gerber design information contained in the target semantic vector, cross-category confusion can be avoided. In addition, combined with the attention mechanism, the sensitivity to subtle defects is improved, overfitting is reduced, and it is generalized to multi-category scenarios.

[0076] Furthermore, the differences between the features of the target physical object image and the target reconstruction features are compared pixel by pixel. Since the target physical object image may contain manufacturing defects of different PCB components, and the target Gerber image corresponding to the PCB under test is a standard PCB design drawing, the target reconstruction features generated by reconstruction are the features corresponding to the PCB under test without defects. Based on the comparison between the features, the anomaly detection of various PCB components in the PCB under test can be achieved.

[0077] As a preferred solution, based on the target semantic vector, the cross-attention mechanism is used to reconstruct the target Gerber image features to obtain target reconstruction features with the same image style as the target physical object image, which specifically includes:

[0078] Add Gaussian noise to the target Gerber image features to obtain Gaussian noise image features;

[0079] Use the cross-attention mechanism to introduce the target semantic vector into the Gaussian noise image features to obtain latent representation features;

[0080] Perform noise reduction processing on the latent representation features to obtain the target reconstruction features with the same image style as the target physical object image.

[0081] Specifically, as Figure 2 shown, in this embodiment, based on the diffusion model, the diffusion process from the initial noise distribution to the target data distribution is simulated. In the forward process, Gaussian noise is added to the target Gerber image features to obtain Gaussian noise image features; then, the cross-attention mechanism is used to interact the encoded target Gerber design information, that is, the target semantic vector, with the Gaussian noise image features. In this process, the attention weights between the features at each position in the target semantic vector and the Gaussian noise image features are calculated. By means of dot product calculation, etc., the correlation between the semantic vector and each element in the Gaussian noise image features is measured. The higher the correlation, the greater the corresponding attention weight. If the pad information is described in the target semantic vector, then the attention weight of the position of the Gaussian noise image features related to the pad will be greater. According to the calculated attention weights, the Gaussian noise image features are weighted and updated to integrate the information of the semantic vector into the Gaussian noise image features, enhance the features related to the target Gerber design information, suppress irrelevant features, avoid cross-category confusion, improve the sensitivity to subtle defects, and reduce overfitting.

[0082] Furthermore, in the reverse process, the latent representation features are subjected to noise reduction processing to be reconstructed into target reconstruction features with the same image style as the target physical object image.

[0083] As a preferred solution, the step of comparing the target physical image features with the target reconstruction features pixel by pixel to obtain the abnormal detection result of the PCB board to be tested specifically includes:

[0084] Calculating the cosine similarity between the target physical image features and the target reconstruction features at each pixel;

[0085] Obtaining a number of abnormal pixels whose cosine similarity is less than a preset cosine similarity threshold;

[0086] Determining the abnormal type and abnormal position of the PCB board to be tested according to the target physical image features on each abnormal pixel and the position information of each abnormal pixel.

[0087] Specifically, as Figure 2 shown, in order to comprehensively and accurately detect the abnormalities of the PCB board to be tested, in this embodiment, the cosine similarity between the target physical image features and the target reconstruction features is calculated at each pixel. Assume that the vector after expanding the target physical image features is: A = [a1, a2,..., an], and the vector after expanding the target reconstruction features is B = [b1, b2,..., bn], where n is the vector dimension. The cosine similarity of the two vectors is calculated according to the calculation formula of cosine similarity. This formula calculates the dot product of the two vectors and divides it by the product of their moduli to obtain a value between -1 and 1. The closer the cosine similarity value is to 1, the more similar the directions of the two vectors are, that is, the higher the similarity between the target physical image features and the target reconstruction features at the current pixel, so the position of the PCB board to be tested corresponding to this pixel is defect-free; while the closer the cosine similarity value is to -1, the more opposite the directions of the two vectors are; when the cosine similarity value is close to 0, it means that the two vectors are orthogonal, that is, the similarity between the target physical image features and the target reconstruction features at the current pixel is low, so the position of the PCB board to be tested corresponding to this pixel has defects.

[0088] By setting a suitable cosine similarity threshold, when the cosine similarity between the target physical image features and the target reconstruction features at a certain pixel is less than the preset cosine similarity threshold, it means that the position of the PCB board to be tested corresponding to the current pixel has defects, so that specific abnormal components can be located, such as pads, substrates or circuits, so that the abnormal type can be determined, and the specific abnormal position can be located based on the position of the pixel.

[0089] As a preferred solution, the step of rendering the target Gerber vector file corresponding to the PCB board to be tested into a target Gerber image specifically includes:

[0090] Based on the pcb-tools open source library, rendering the target Gerber vector file into the target Gerber image.

[0091] Specifically, in this embodiment, the pcb-tools open-source library is used to render the target Gerber vector file into a target Gerber image according to the design style of the PCB industry.

[0092] As a preferred solution, the target Gerber design information includes the drilling layer information, pad layer information, oil printing substrate layer information, silk screen layer information, and circuit layer information of the PCB to be tested.

[0093] To fully demonstrate the beneficial effects of the PCB anomaly detection method based on the diffusion model provided by the embodiments of the present invention, the following is a comparative test with three mainstream anomaly detection algorithms based on the same PCB dataset.

[0094] Specifically, based on the same PCB dataset, on the NVIDIA V100 graphics card, a comparative test is conducted with three mainstream anomaly detection algorithms, DeSTSeg, SimpleNet, and UniAD. The anomaly detection accuracy rates are shown in Table 1 below:

[0095] Table 1 Comparative results of anomaly detection

[0096] Detection method <![CDATA[mAD I > <![CDATA[mAD P > Inference time DeSTSeg 78.3 59.7 25ms SimpleNet 70.2 55.6 50ms UniAD 68.5 54.3 120ms Embodiment of the present invention 98.6 76.8 30ms

[0097] As can be seen from Table 1 above, the detection accuracy rate of the PCB anomaly detection method based on the diffusion model provided by the embodiments of the present invention is higher than that of the current mainstream anomaly detection networks, namely DeSTSeg, SimpleNet, and UniAD.

[0098] Please refer to Figure 3 , the second aspect of the embodiments of the present invention provides a PCB anomaly detection device based on a diffusion model, including:

[0099] A Gerber image generation module 100 for rendering the target Gerber vector file corresponding to the PCB to be tested into a target Gerber image;

[0100] A PCB anomaly detection module 200 for inputting the target physical image of the PCB to be tested, the target Gerber design information, and the target Gerber image into the PCB anomaly detection model to obtain the anomaly detection result of the PCB to be tested output by the PCB anomaly detection model; wherein, the PCB anomaly detection model is obtained by training a diffusion model using a PCB image training set, and the PCB image training set includes several groups of aligned images containing defect-free PCB physical images and Gerber training images and their corresponding Gerber design information.

[0101] As a preferred solution, the device further includes a PCB image training set generation module for:

[0102] Based on a plurality of the Gerber training images, obtain a plurality of template images;

[0103] Perform binarization processing on a plurality of the defect-free PCB physical images to obtain a plurality of binary images;

[0104] Adopt a template matching method to match a plurality of the template images with a plurality of the binary images, obtain several groups of matching template images and binary images, and determine the image transformation parameters between each group of matching template images and binary images;

[0105] Based on each group of matching template images and binary images, determine several groups of matching defect-free PCB physical images and Gerber training images, and perform geometric transformation on the defect-free PCB physical images by using the image transformation parameters;

[0106] Align each group of geometrically transformed defect-free PCB physical images and Gerber training images to obtain several groups of initial aligned images;

[0107] Crop each group of the initial aligned images according to a preset cropping size to obtain several groups of the aligned images;

[0108] Query Gerber design information according to the coordinates of the aligned images, and bind the queried Gerber design information to the aligned images to generate the PCB image training set.

[0109] As a preferred solution, the device further includes a diffusion model training module, which is used for:

[0110] Taking minimizing a preset loss function as the training objective, use the PCB image training set to train the diffusion model to obtain the PCB anomaly detection model; wherein, the loss function is a weighted sum of a classification loss, a localization loss, and a reconstruction loss; the classification loss is used to measure the error of the diffusion model in PCB anomaly classification; the localization loss is used to measure the error of the diffusion model in PCB anomaly localization; the reconstruction loss is used to measure the error of the diffusion model in reconstructing the features of the Gerber image into the features of the physical style image.

[0111] As a preferred solution, the PCB anomaly detection module 200 is used to input the target physical image, the target Gerber design information, and the target Gerber image of the PCB to be tested into the PCB anomaly detection model, and obtain the anomaly detection result of the PCB to be tested output by the PCB anomaly detection model, specifically including:

[0112] Preprocess the target physical object image and the target Gerber image to obtain the preprocessed target physical object image and the preprocessed target Gerber image;

[0113] Encode the target Gerber design information to obtain a target semantic vector;

[0114] Input the preprocessed target physical object image, the preprocessed target Gerber image, and the target semantic vector into the PCB anomaly detection model, and use the PCB anomaly detection model to extract features from the preprocessed target physical object image and the preprocessed target Gerber image respectively to obtain a target physical object image feature and a target Gerber image feature;

[0115] Based on the target semantic vector, use the cross-attention mechanism to reconstruct the target Gerber image feature to obtain a target reconstructed feature with an image style consistent with that of the target physical object image;

[0116] Perform a pixel-by-pixel comparison between the target physical object image feature and the target reconstructed feature to obtain the anomaly detection result of the PCB under test.

[0117] As a preferred solution, the PCB anomaly detection module 200 is used to reconstruct the target Gerber image feature using the cross-attention mechanism based on the target semantic vector to obtain a target reconstructed feature with an image style consistent with that of the target physical object image, specifically including:

[0118] Add Gaussian noise to the target Gerber image feature to obtain a Gaussian noise image feature;

[0119] Use the cross-attention mechanism to introduce the target semantic vector into the Gaussian noise image feature to obtain a latent representation feature;

[0120] Perform noise reduction processing on the latent representation feature to obtain the target reconstructed feature with an image style consistent with that of the target physical object image.

[0121] As a preferred solution, the PCB anomaly detection module 200 is used to perform a pixel-by-pixel comparison between the target physical object image feature and the target reconstructed feature to obtain the anomaly detection result of the PCB under test, specifically including:

[0122] Calculate the cosine similarity between the target physical object image feature and the target reconstructed feature at each pixel;

[0123] Obtain a number of abnormal pixels whose cosine similarity is less than a preset cosine similarity threshold;

[0124] Determine the abnormal type and abnormal position of the PCB to be tested according to the target physical image features on each of the abnormal pixels and the position information of each of the abnormal pixels.

[0125] As a preferred solution, the Gerber image generation module 100 is used to render the target Gerber vector file corresponding to the PCB to be tested into a target Gerber image, specifically including:

[0126] Based on the pcb-tools open source library, render the target Gerber vector file into the target Gerber image.

[0127] As a preferred solution, the target Gerber design information includes the drilling layer information, pad layer information, oil printing substrate layer information, silk screen layer information, and circuit layer information of the PCB to be tested.

[0128] The PCB anomaly detection device based on the diffusion model provided by the embodiments of the present invention obtains a PCB anomaly detection model by training the diffusion model using the aligned defect-free PCB physical images and Gerber training images, as well as the corresponding Gerber design information. Therefore, the PCB anomaly detection model can achieve the style transfer from the Gerber image to the PCB physical image under the guidance of the Gerber design information. In the actual PCB anomaly detection process, it can accurately and effectively reconstruct the target Gerber image into a reconstructed image with the same style as the target physical image, and then can use the reconstructed image to accurately detect various PCB components in the PCB to be tested.

[0129] A third aspect of the embodiments of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the PCB anomaly detection method according to any one of the embodiments in the first aspect.

[0130] Exemplarily, the computer program can be divided into one or more modules / units. The one or more modules / units are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, and these instruction segments are used to describe the execution process of the computer program in the electronic device.

[0131] The electronic device may include, but is not limited to, a processor and a memory. Those skilled in the art can understand that the schematic diagram is only an example of the electronic device, which does not constitute a limitation on the electronic device. It may include more or fewer components than those shown, or combine certain components, or different components. For example, the electronic device may also include input / output devices, network access devices, buses, etc.

[0132] The processor may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The processor is the control center of the electronic device, connecting various parts of the entire electronic device through various interfaces and circuits.

[0133] The memory can be used to store the computer program and / or module. The processor realizes various functions of the electronic device by running or executing the computer program and / or module stored in the memory, and by calling the data stored in the memory. The memory mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.); the data storage area can store data created according to the use of the mobile phone (such as audio data, phone book, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0134] The above is the preferred embodiment of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements are also regarded as the protection scope of the present invention.

Claims

1. A PCB anomaly detection method based on a diffusion model, characterized in that, Including: Rendering the target Gerber vector file corresponding to the PCB board to be tested into a target Gerber image; Inputting the target physical image, target Gerber design information, and the target Gerber image of the PCB board to be tested into a PCB anomaly detection model, and obtaining the anomaly detection result of the PCB board to be tested output by the PCB anomaly detection model; wherein, the PCB anomaly detection model is obtained by training a diffusion model using a PCB image training set, and the PCB image training set includes several groups of aligned images containing defect-free PCB physical images and Gerber training images and their corresponding Gerber design information.

2. The PCB anomaly detection method based on the diffusion model according to claim 1, wherein, The method specifically generates the PCB image training set through the following steps: Based on several of the Gerber training images, obtaining several template images; Performing binarization processing on several of the defect-free PCB physical images to obtain several binary images; Using a template matching method to match several of the template images with several of the binary images, obtaining several groups of matching template images and binary images, and determining the image transformation parameters between each group of matching template images and binary images; Based on each group of matching template images and binary images, determining several groups of matching defect-free PCB physical images and Gerber training images, and performing geometric transformation on the defect-free PCB physical images using the image transformation parameters; Aligning each group of geometrically transformed defect-free PCB physical images and Gerber training images to obtain several groups of initial aligned images; Cropping each group of the initial aligned images according to a preset cropping size to obtain several groups of the aligned images; Querying the Gerber design information according to the coordinates of the aligned images, and binding the queried Gerber design information to the aligned images to generate the PCB image training set.

3. The PCB anomaly detection method based on the diffusion model according to claim 1, characterized in that, The method specifically trains the diffusion model through the following steps: Taking minimizing a preset loss function as the training objective, training the diffusion model using the PCB image training set to obtain the PCB anomaly detection model; wherein, the loss function is a weighted sum of a classification loss, a localization loss, and a reconstruction loss; the classification loss is used to measure the error of the diffusion model in PCB anomaly classification; the localization loss is used to measure the error of the diffusion model in PCB anomaly localization; the reconstruction loss is used to measure the error of the diffusion model in reconstructing the features of the Gerber image into physical-style image features.

4. The PCB anomaly detection method based on the diffusion model according to claim 3, characterized in that, The step of inputting the target physical image, target Gerber design information, and the target Gerber image of the PCB board to be tested into a PCB anomaly detection model, and obtaining the anomaly detection result of the PCB board to be tested output by the PCB anomaly detection model specifically includes: Performing preprocessing on the target physical image and the target Gerber image to obtain a preprocessed target physical image and a preprocessed target Gerber image; Encode the target Gerber design information to obtain a target semantic vector; Input the preprocessed target physical image, the preprocessed target Gerber image, and the target semantic vector into the PCB anomaly detection model, and use the PCB anomaly detection model to extract features from the preprocessed target physical image and the preprocessed target Gerber image respectively to obtain a target physical image feature and a target Gerber image feature; Based on the target semantic vector, use the cross-attention mechanism to reconstruct the target Gerber image feature to obtain a target reconstruction feature with an image style consistent with that of the target physical image; Perform a pixel-by-pixel comparison between the target physical image feature and the target reconstruction feature to obtain the anomaly detection result of the PCB under test.

5. The method for detecting PCB anomalies based on a diffusion model according to claim 4, wherein, The step of using the cross-attention mechanism to reconstruct the target Gerber image feature based on the target semantic vector to obtain a target reconstruction feature with an image style consistent with that of the target physical image specifically includes: Add Gaussian noise to the target Gerber image feature to obtain a Gaussian noise image feature; Use the cross-attention mechanism to introduce the target semantic vector into the Gaussian noise image feature to obtain a latent representation feature; Perform noise reduction processing on the latent representation feature to obtain the target reconstruction feature with an image style consistent with that of the target physical image.

6. The method for PCB anomaly detection based on a diffusion model according to claim 4, wherein The step of performing a pixel-by-pixel comparison between the target physical image feature and the target reconstruction feature to obtain the anomaly detection result of the PCB under test specifically includes: Calculate the cosine similarity between the target physical image feature and the target reconstruction feature at each pixel; Obtain a number of abnormal pixels whose cosine similarity is less than a preset cosine similarity threshold; Determine the anomaly type and anomaly location of the PCB under test according to the target physical image feature at each abnormal pixel and the position information of each abnormal pixel.

7. The PCB anomaly detection method based on a diffusion model according to claim 1, wherein The step of rendering the target Gerber vector file corresponding to the PCB under test into a target Gerber image specifically includes: Based on the pcb-tools open-source library, render the target Gerber vector file into the target Gerber image.

8. The PCB anomaly detection method based on the diffusion model according to claim 1, characterized in that, The target Gerber design information includes the drilling layer information, pad layer information, oil printing substrate layer information, silk screen layer information, and circuit layer information of the PCB under test.

9. A PCB anomaly detection device based on a diffusion model, characterized in that, It includes: A Gerber image generation module for rendering the target Gerber vector file corresponding to the PCB under test into a target Gerber image; The PCB anomaly detection module is used to input the target physical image, target Gerber design information, and target Gerber image of the PCB to be tested into the PCB anomaly detection model, and obtain the anomaly detection result of the PCB to be tested output by the PCB anomaly detection model; wherein, the PCB anomaly detection model is obtained by training a diffusion model using a PCB image training set, and the PCB image training set includes several groups of aligned images containing defect-free PCB physical images and Gerber training images and their corresponding Gerber design information.

10. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the PCB anomaly detection method based on the diffusion model according to any one of claims 1 to 8.