PCB defect detection method and system based on Gerber file
Through the Gerber file-based method, the multi-level features are extracted using regular matching and image encoder, and the cosine similarity training model is used to solve the problem of dependence on labeled data in the existing technology, achieving high accuracy in the case of defect-free data PCB defect detection rate.
Patent Information
- Application Number
- CN202411137897.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2024-12-03
AI Technical Summary
In the prior art, PCB defect detection methods based on deep learning rely on a large number of labeled data, and it is difficult to achieve high-accuracy detection when defect samples are scarce, especially in the case of defectless data, it is difficult to effectively use Gerber files for detection.
Through the Gerber file-based method, the Gerber file is parsed layer by layer by layer by layer, and combined with the pre-trained real image encoder and synthetic image encoder, multi-level image features are extracted, and cosine similarity is used as loss for training, so as to achieve High accuracy defect detection without labeled data.
It effectively eliminates the dependence on defective data sets, improves the generalization of detection of defects with different morphological manifestations, and realizes high-accuracy PCB defect detection in the case of defectless data.
Smart Images

Figure CN119067937A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of industrial visual inspection and image anomaly detection, and in particular to a PCB defect detection method and system based on Gerber files. Background Art
[0002] PCB is an indispensable part of the modern electronics industry, and product appearance inspection is an important guarantee of its quality. Defective products that are not properly inspected will lead to product returns and loss of customer trust. At present, traditional algorithms and deep learning models are mainly applied to the field of PCB defect detection. Traditional algorithms rely on hand-designed feature extraction and image processing techniques to identify defects by analyzing image properties such as color, texture, and edges. These methods perform well in terms of computational efficiency and have relatively low data requirements, but they are generally inflexible, difficult to adapt to complex or unseen defect types, and are also sensitive to environmental changes. In contrast, deep learning models, by automatically learning complex features from a large amount of annotated training data, demonstrate superiority in processing complex patterns and diverse defect types in images. However, the main challenge of this approach is its reliance on a large amount of annotated data, which limits the model's training and generalization capabilities when defect samples are scarce.
[0003] Gerber files are the standard output format for PCB design, which record the precise design and layout of each layer of the PCB in detail. Using Gerber files to generate composite images can provide correct information about the PCB as a reference. Using Gerber document reference information can not only improve the detection rate of design defects such as hole offset and missing silk screen, but also avoid the interference of complex background information through design information. In the absence of labeled data, high-accuracy defect detection can be achieved by comparing reference information.
[0004] In the prior art, in the real-time automatic detection and classification device of two-dimensional PCB defects based on deep learning, due to the use of supervised models, it relies on the collection and annotation of defects. In the real production environment, the number of defects is often small and the collection cycle is long. In addition, additional labor costs are required for data annotation (CN112053318A).
[0005] In summary, how to effectively use Gerber files to realize PCB defect detection without defect data is a technical problem that technicians in this field urgently need to solve. Summary of the invention
[0006] The purpose of the present invention is to provide a PCB defect detection method and system based on Gerber files to solve the problems encountered in the existing PCB defect detection field.
[0007] The purpose of the present invention is achieved by at least one of the following technical solutions.
[0008] A PCB defect detection method based on Gerber files comprises the following steps:
[0009] S1. Parse the Gerber file layer by layer based on regular matching and synthesize it into a PCB composite image;
[0010] S2, input the real image of the PCB taken by the industrial camera into the pre-trained real image encoder, and extract image features at multiple levels as real image features;
[0011] S3, inputting the PCB synthetic image into a synthetic image encoder and a feature converter, extracting synthetic image features from the PCB synthetic image and converting the synthetic image features layer by layer into image features of multiple levels as converted image features;
[0012] S4, in the training stage, the converted image features of multiple levels obtained in step S3 and the real image features of multiple levels extracted in step S2 are used to train the synthetic image encoder and the feature converter using cosine similarity as the loss;
[0013] S5, in the inference stage, the PCB synthetic image is input into the synthetic image encoder and feature converter trained in step S4, and the multi-layer latest converted image features are extracted; the second-level image features in the multi-layer latest converted image features and the multi-layer real image features are used to perform cosine similarity calculation to obtain pixel-level outliers;
[0014] S6. Classify defective and normal images according to whether the pixel-level abnormal value exceeds the threshold, and locate the defect position.
[0015] Furthermore, in step S1, a regular matching method is used to parse the PCB to obtain multiple Gerber files, and a multi-layer image is obtained. Each layer of the image represents a different component of the PCB. After the multi-layer images are merged, a composite PCB image is synthesized.
[0016] Furthermore, in step S2, the real image encoder adopts an existing known network model, including ResNet, ResNeSt or MobileNet;
[0017] The encoder is pre-trained on real images using the ImageNet dataset.
[0018] Furthermore, in step S3, the structure of the synthetic image encoder is the same as that of the real image encoder; the structure of the feature converter is opposite to that of the real image encoder.
[0019] Furthermore, in step S4, during the training phase, the converted image features of multiple levels converted in step S3 and the real image features of multiple levels extracted in step S2 are used to train the synthetic image encoder and feature converter using the cosine similarity of the image features of the corresponding levels as the loss.
[0020] Furthermore, in step S5, the cosine similarity is measured between the multi-layer latest converted image features and the second-level image features in the multi-layer real image features to obtain the pixel-level cosine similarity, and the anomaly score is obtained by the following formula:
[0021] Score = 1-cos(F r ,F t )
[0022] Score represents the abnormality score, F r represents the real image features of the second level, F t Represents the latest transformed image features of the second level.
[0023] Furthermore, in step S6, anomaly scores are calculated based on all cosine similarity values calculated in the training process in step S4, and the average value of all anomaly scores is used as a threshold for classifying defective images and normal images.
[0024] A PCB defect detection system based on Gerber files, comprising:
[0025] The Gerber file parsing module is used to parse the PCB to obtain multiple Gerber files using regular matching, and obtain multi-layer images. Each layer of the image represents different components of the PCB. After merging the multi-layer images, a composite PCB image is synthesized;
[0026] A real image feature encoding module is used to input the real image of the PCB taken by the industrial camera into a pre-trained real image encoder to extract image features at multiple levels as real image features;
[0027] A synthetic image feature encoding and conversion module is used to extract synthetic image features from the PCB synthetic image and convert the synthetic image features layer by layer into image features of multiple levels as converted image features;
[0028] A training module for training a synthetic image encoder and a feature converter using cosine similarity as a loss for multiple levels of transformed image features and multiple levels of real image features;
[0029] The defect recognition and positioning module is used to input the PCB synthetic image into the trained synthetic image encoder and feature converter to extract the multi-layer latest converted image features; use the second-level image features of the multi-layer latest converted image features and the multi-layer real image features to perform cosine similarity calculation to obtain pixel-level outliers, classify defects and normal images according to whether the pixel-level outliers exceed the threshold, and locate the defect position.
[0030] A PCB defect detection device based on a Gerber file comprises a processor and a memory arranged to store computer executable instructions. When the executable instructions are executed, the processor implements a PCB defect detection method based on the Gerber file.
[0031] A computer-readable storage medium stores a computer program that implements a PCB defect detection method based on a Gerber file when executed.
[0032] Compared with the prior art, the present invention has the following beneficial effects:
[0033] The present invention effectively utilizes Gerber documents and uses positive sample data to train synthetic image feature extractors and converters, so that the model can detect the difference between the conversion features and the features of the image to be detected. The present invention can eliminate the dependence on defect data sets and show generalization for defects with different morphological manifestations. It effectively solves the difficult problems in the field of PCB defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0035] Figure 1 A schematic diagram of a process of a PCB defect detection method based on a Gerber file in an embodiment of the present invention;
[0036] Figure 2 Schematic diagram of the network structure of the PCB defect detection method based on Gerber file in an embodiment of the present invention;
[0037] Figure 3 It is a structural block diagram of a detection system of a PCB defect detection method based on a Gerber file in an embodiment of the present invention;
[0038] Figure 4 Schematic diagram of a terminal device of a PCB defect detection method based on a Gerber file in an embodiment of the present invention. DETAILED DESCRIPTION
[0039] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0040] Example:
[0041] A PCB defect detection method based on Gerber files, such as Figure 1 , Figure 2 As shown, the following steps are included:
[0042] S1. Use regular matching to parse the PCB to obtain multiple Gerber files, and obtain multi-layer images. Each layer of the image represents different components of the PCB. After merging the multi-layer images, a composite PCB image is synthesized;
[0043] S2, input the real image of the PCB taken by the industrial camera into the pre-trained real image encoder, and extract image features at multiple levels as real image features;
[0044] In one embodiment, a ResNet18 model pre-trained on the ImageNet dataset is selected as a real image feature encoder, and the features of the first, second, and third layers are selected to be extracted as real image features;
[0045] The encoder is pre-trained on real images using the ImageNet dataset.
[0046] S3, inputting the PCB synthetic image into a synthetic image encoder and a feature converter, extracting synthetic image features from the PCB synthetic image and converting the synthetic image features layer by layer into image features of multiple levels as converted image features;
[0047] The structure of the synthetic image encoder is the same as that of the real image encoder; the structure of the feature transformer is opposite to that of the real image encoder.
[0048] In one embodiment, a ResNet18 model is selected as a synthetic image feature encoder and randomly initialized; dilated convolution or linear interpolation is selected to amplify the features, and three ResNet18 residual layers are selected to reversely compose a feature converter; and the outputs of the three residual layers are selected to be extracted as converted image features.
[0049] S4, in the training stage, for the converted image features of multiple levels converted in step S3 and the real image features of multiple levels extracted in step S2, the cosine similarity of the image features of the corresponding levels is used as the loss to train the synthetic image encoder and the feature converter;
[0050] S5, in the inference stage, the PCB synthetic image is input into the synthetic image encoder and feature converter trained in step S4, and the multi-layer latest converted image features are extracted; the second-level image features in the multi-layer latest converted image features and the multi-layer real image features are used to perform cosine similarity calculation to obtain pixel-level outliers;
[0051] The cosine similarity is measured between the multi-layer latest converted image features and the second-level image features in the multi-layer real image features to obtain the pixel-level cosine similarity, and the anomaly score is obtained by the following formula:
[0052] Score = 1-cos(F r ,F t )
[0053] Score represents the abnormality score, F r represents the real image features of the second level, F t Represents the latest transformed image features of the second level.
[0054] S6, classifying defective and normal images according to whether the pixel-level abnormal value exceeds the threshold, and locating the defect position;
[0055] According to all the cosine similarity values calculated during the training process in step S4, anomaly scores are calculated, and the average value of all anomaly scores is used as a threshold for classifying defective images and normal images.
[0056] In one embodiment, the average of the top 10 anomaly scores in the image is selected as the anomaly score of the entire image.
[0057] In one embodiment, if the image is determined to have defects, the anomaly score is displayed in the form of a heat map, and the part with anomaly score higher than the threshold is the defective part.
[0058] In one embodiment, a PCB defect detection system based on Gerber files, such as Figure 3 As shown, including:
[0059] The Gerber file parsing module is used to parse the PCB to obtain multiple Gerber files using regular matching, and obtain multi-layer images. Each layer of the image represents different components of the PCB. After merging the multi-layer images, a composite PCB image is synthesized;
[0060] A real image feature encoding module is used to input the real image of the PCB taken by the industrial camera into a pre-trained real image encoder to extract image features at multiple levels as real image features;
[0061] A synthetic image feature encoding and conversion module is used to extract synthetic image features from the PCB synthetic image and convert the synthetic image features layer by layer into image features of multiple levels as converted image features;
[0062] A training module for training a synthetic image encoder and a feature converter using cosine similarity as a loss for multiple levels of transformed image features and multiple levels of real image features;
[0063] The defect recognition and positioning module is used to input the PCB synthetic image into the trained synthetic image encoder and feature converter to extract the multi-layer latest converted image features; use the second-level image features of the multi-layer latest converted image features and the multi-layer real image features to perform cosine similarity calculation to obtain pixel-level outliers, classify defects and normal images according to whether the pixel-level outliers exceed the threshold, and locate the defect position.
[0064] In one embodiment, a PCB defect detection device based on a Gerber file, such as Figure 4 As shown, it includes a processor and a memory arranged to store computer executable instructions. When the executable instructions are executed, the processor implements a PCB defect detection method based on a Gerber file.
[0065] A computer-readable storage medium stores a computer program that implements a PCB defect detection method based on a Gerber file when executed.
[0066] In some selectable embodiments, the function / operation mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the function / operation involved, the two boxes shown in succession can actually be executed substantially simultaneously or the boxes can sometimes be executed in reverse order. In addition, the embodiment presented and described in the flow chart of the present invention is provided by way of example, for the purpose of providing a more comprehensive understanding of technology. The disclosed method is not limited to the operation and logic flow presented herein. Selectable embodiments are expected, wherein the order of various operations is changed and the sub-operation of a part for which is described as a larger operation is performed independently.
[0067] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk.
[0068] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the described embodiments. Those skilled in the art may make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of this application.
Claims
1. A PCB defect detection method based on Gerber files, characterized in that: The following steps are involved: S1. Parse the Gerber file layer by layer based on regular matching and synthesize it into a PCB composite image; S2, input the real image of the PCB taken by the industrial camera into the pre-trained real image encoder, and extract image features at multiple levels as real image features; S3, inputting the PCB synthetic image into a synthetic image encoder and a feature converter, extracting synthetic image features from the PCB synthetic image and converting the synthetic image features layer by layer into image features of multiple levels as converted image features; S4, in the training stage, the converted image features of multiple levels obtained in step S3 and the real image features of multiple levels extracted in step S2 are used to train the synthetic image encoder and the feature converter using cosine similarity as the loss; S5, in the inference stage, the PCB synthetic image is input into the synthetic image encoder and feature converter trained in step S4 to extract the latest multi-layer converted image features; Using the multi-layer latest transformed image features and the second-level image features in the multi-layer real image features, the cosine similarity is calculated to obtain the pixel-level outliers; S6. Classify defective and normal images according to whether the pixel-level abnormal value exceeds the threshold, and locate the defect position.
2. The PCB defect detection method based on Gerber file according to claim 1, characterized in that: In step S1, a regular matching method is used to parse the PCB to obtain multiple Gerber files, and a multi-layer image is obtained. Each layer of the image represents a different component of the PCB. After the multi-layer images are merged, a composite PCB image is synthesized.
3. The PCB defect detection method based on Gerber file according to claim 1, characterized in that: In step S2, the real image encoder adopts an existing known network model, including ResNet, ResNeSt or MobileNet; The encoder is pre-trained on real images using the ImageNet dataset.
4. The PCB defect detection method based on Gerber file according to claim 3, characterized in that: In step S3, the structure of the synthetic image encoder is the same as that of the real image encoder; The feature transformer has the opposite structure to the real image encoder.
5. The PCB defect detection method based on Gerber file according to claim 1, characterized in that: In step S4, during the training phase, the converted image features of multiple levels converted in step S3 and the real image features of multiple levels extracted in step S2 are used to train the synthetic image encoder and feature converter using the cosine similarity of the image features of the corresponding levels as the loss.
6. The PCB defect detection method based on Gerber file according to claim 1, characterized in that: In step S5, the cosine similarity is measured between the multi-layer latest converted image features and the second-level image features in the multi-layer real image features to obtain the pixel-level cosine similarity, and the anomaly score is obtained by the following formula: Score=1-cos(F r ,F t ) Score represents the abnormality score, F r represents the real image features of the second level, F t Represents the latest transformed image features of the second level.
7. The PCB defect detection method based on Gerber file according to claim 1, characterized in that: In step S6, anomaly scores are calculated based on all cosine similarity values calculated during the training process in step S4, and the average value of all anomaly scores is used as a threshold for classifying defective images and normal images.
8. A PCB defect detection system based on Gerber files, characterized in that: include: The Gerber file parsing module is used to parse the PCB to obtain multiple Gerber files using regular matching, and obtain multi-layer images. Each layer of the image represents different components of the PCB. After merging the multi-layer images, a composite PCB image is synthesized; A real image feature encoding module is used to input the real image of the PCB taken by the industrial camera into a pre-trained real image encoder to extract image features at multiple levels as real image features; A synthetic image feature encoding and conversion module is used to extract synthetic image features from the PCB synthetic image and convert the synthetic image features layer by layer into image features of multiple levels as converted image features; A training module for training a synthetic image encoder and a feature converter using cosine similarity as a loss for multiple levels of transformed image features and multiple levels of real image features; Defect recognition and positioning module, used to input the PCB synthetic image into the trained synthetic image encoder and feature converter, and extract the latest multi-layer converted image features; The cosine similarity is calculated using the multi-layer latest converted image features and the second-level image features in the multi-layer real image features to obtain the pixel-level outlier value. The defect and normal images are classified according to whether the pixel-level outlier value exceeds the threshold, and the defect position is located.
9. A PCB defect detection device based on Gerber files, characterized in that: The invention comprises a processor and a memory arranged to store computer executable instructions, wherein when the executable instructions are executed, the processor implements a PCB defect detection method based on a Gerber file as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A computer program is stored which, when executed, implements a PCB defect detection method based on a Gerber file as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Two-dimensional PCB defect real-time automatic detection and classification device based on deep learning
CN112053318A
Cited By
PCB layer category identification method, electronic equipment and readable storage medium
CN121236470A
A PCB layer category identification method, electronic equipment and readable storage medium
CN121236470B
