Defect detection model training method, device, equipment and storage medium

By using PCB defect sample images and preset problem texts that include image description and defect description for multi-level annotation and data augmentation, the problem of poor generalization ability in the prior art is solved, and more efficient and accurate defect detection is achieved.

CN119067972BActive Publication Date: 2025-03-28SHENZHEN SMARTMORE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411555875.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-04
Publication Date
2025-03-28
Estimated Expiration
2044-11-04

AI Technical Summary

Technical Problem

In the prior art, the model used for PCB defect detection has poor generalization capabilities and is difficult to effectively detect new defect types.

Method used

By obtaining the PCB defect sample image including image description and defect description and corresponding preset problem text, multi-level labeling and data augmentation are performed, the diversity and quality of the training samples are improved, and the initial detection model is trained based on the training loss to obtain the defect detection model.

Benefits of technology

The generalization ability of the defect detection model is improved, the multi-level annotation ability of sample images is enhanced, the quality of training samples is improved, the convergence difficulty of model training is reduced, and the accuracy of the model is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119067972B_ABST
    Figure CN119067972B_ABST
Patent Text Reader

Abstract

The present application relates to a defect detection model training method, device, equipment and storage medium. The method includes: obtaining a PCB defect sample training set and a preset question text; the PCB defect sample training set includes multiple PCB defect sample images, each PCB defect sample image includes an image description and a defect description; the preset question text is determined based on at least one of the image description and the defect description; the PCB defect sample image and the corresponding preset question text are input into the initial detection model for processing, and the predicted answer corresponding to the preset question text is output; the training loss is determined according to the difference between the predicted answer and the standard answer, and the initial detection model is trained based on the training loss to obtain a defect detection model. The present application can improve the generalization ability of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to a defect detection model training method, device, equipment and storage medium. Background Art

[0002] With the advancement of manufacturing technology, the complexity and density of PCB (Printed Circuit Board) are increasing. Traditional defect detection methods, such as manual visual inspection and simple automation methods, can no longer meet the requirements of high efficiency and high precision. In the PCB manufacturing process, quality control of PCB is a crucial link, especially in defect detection.

[0003] In the related art, model training is used to detect PCB defects in order to improve the automation and accuracy of defect detection. However, in actual operation, the generalization ability of the trained model is poor, and the detection effect for new defect types is not ideal. Summary of the invention

[0004] Based on this, it is necessary to provide a defect detection model training method, device, computer equipment, computer readable storage medium and computer program product to address the above technical problems, so as to improve the generalization ability of the model.

[0005] In a first aspect, the present application provides a defect detection model training method, comprising:

[0006] Obtaining a PCB defect sample training set and a preset question text; the PCB defect sample training set includes a plurality of PCB defect sample images, each PCB defect sample image includes an image description and a defect description; the preset question text is determined based on at least one of the image description and the defect description;

[0007] Input the PCB defect sample image and the corresponding preset question text into the initial detection model for processing, and output the predicted answer corresponding to the preset question text;

[0008] The training loss is determined according to the difference between the predicted answer and the standard answer, and the initial detection model is trained based on the training loss to obtain the defect detection model.

[0009] In a second aspect, the present application provides a defect detection model training device, comprising:

[0010] A sample acquisition module is used to acquire a PCB defect sample training set and a preset question text; the PCB defect sample training set includes a plurality of PCB defect sample images, each PCB defect sample image includes an image description and a defect description; the preset question text is determined based on at least one of the image description and the defect description;

[0011] The answer prediction module is used to input the PCB defect sample image and the corresponding preset question text into the initial detection model for processing, and output the predicted answer corresponding to the preset question text;

[0012] The model training module is used to determine the training loss according to the difference between the predicted answer and the standard answer, and train the initial detection model based on the training loss to obtain the defect detection model.

[0013] In a third aspect, the present application provides a computer device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above-mentioned defect detection model training method when executing the computer program.

[0014] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the above-mentioned defect detection model training method.

[0015] In a fifth aspect, the present application provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the steps in the above-mentioned defect detection model training method.

[0016] The above-mentioned defect detection model training method, device, computer equipment, computer-readable storage medium and computer program product use PCB defect sample images including image descriptions and defect descriptions and corresponding preset question texts as PCB defect sample training sets to train the initial detection model to obtain a defect detection model, and realize multi-level annotation of sample images, which can increase the diversity of training samples and improve the generalization ability of the defect detection model; at the same time, the preset question text and the annotated sample images are used together to train the model, which can improve the quality of training samples, reduce the convergence difficulty of model training and improve the accuracy of the trained model. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 An application environment diagram of a defect detection model training method provided in an embodiment of the present application;

[0018] Figure 2 A flowchart of a defect detection model training method provided in an embodiment of the present application;

[0019] Figure 3 A schematic diagram of a process for outputting a predicted answer corresponding to a preset question text provided in an embodiment of the present application;

[0020] Figure 4 A schematic diagram of another process of outputting a predicted answer corresponding to a preset question text provided in an embodiment of the present application;

[0021] Figure 5 A schematic diagram of aligning a first image unit with a text word provided in an embodiment of the present application;

[0022] Figure 6 A flowchart of another defect detection model training method provided in an embodiment of the present application;

[0023] Figure 7 A structural block diagram of a defect detection model training device provided in an embodiment of the present application;

[0024] Figure 8 An internal structure diagram of a computer device provided in an embodiment of the present application;

[0025] Fig. 9 An internal structure diagram of another computer device provided in an embodiment of the present application;

[0026] Fig.10 An internal structure diagram of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0028] The defect detection model training method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through a communication network. The data storage system can store data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented with an independent server or a server cluster composed of multiple servers. It should be noted that the defect detection model training method provided in the embodiment of the present application is not limited to application in the above-mentioned server and terminal interaction scenarios, and can also be applied to application scenarios of separate servers or separate terminals.

[0029] like Figure 2 As shown, the embodiment of the present application provides a defect detection model training method, which is applied to Figure 1The terminal 102 or the server 104 in the example is used for explanation. It is understandable that the computer device may include at least one of the terminal and the server. The method comprises the following steps:

[0030] S202, obtaining a PCB defect sample training set and a preset question text; the PCB defect sample training set includes a plurality of PCB defect sample images, each PCB defect sample image includes an image description and a defect description; the preset question text is determined based on at least one of the image description and the defect description.

[0031] The image description refers to the overall feature description of the PCB defect sample image, such as whether there is a defect, the number of components included, and the status of the components. The image description may include a first type description and a second type description, and the first type description is less detailed than the second type description. For example, the first type description includes a simple description of whether there is a defect, defective components, the number of defects, or the defect level, and the second type description includes a detailed description of each component in the image.

[0032] Defect description refers to the description of existing defects, such as description of defect location, defect category and defect degree. Defect description may include a first defect description and a second defect description, and the first defect description is less detailed than the second defect description. For example, the first defect description includes a simple description such as defect location and defect category, and the second defect description includes a detailed description such as defect morphology, defect degree and defect formation cause. It is easy to understand that the image description and defect description can be annotated on the PCB image in the form of text.

[0033] It is easy to understand that the PCB defect sample image may include a PCB image with defects, and may also include a PCB image without defects. If a PCB image without defects is included, the corresponding defect description does not exist. Generally, the PCB defect sample image includes PCB images of various defect types. The more defect types included, the more conducive to improving the generalization ability of the defect detection model. Each PCB defect sample image may include one or more types of defects, and may also include one or more defects.

[0034] The preset question text can be determined based on the image description, for example, the preset question text is "Please give a first type of description of the image" or "Please give a second type of description of the image"; the preset question text can also be determined based on the defect description, for example, the preset question text is "Please give a first defect description of the image" or "Please give a second defect description of the image"; or the preset question text is determined based on the image description and the defect description, for example, the preset question text is "Please briefly describe the first defect of the image" or "Please describe the second defect of the image in detail", etc.

[0035] Specifically, after marking the image description and defect description of the PCB image, a PCB text-annotated image is obtained, and then data augmentation is performed on the PCB text-annotated image to obtain a PCB defect sample image. Each PCB defect sample image can correspond to multiple preset problem texts, that is, it can correspond to all types of preset problem texts respectively, and then each group of corresponding PCB defect sample images and preset problem texts are input into the initial detection model for training.

[0036] S204: Input the PCB defect sample image and the corresponding preset question text into the initial detection model for processing, and output the predicted answer corresponding to the preset question text.

[0037] Each PCB defect sample image and a corresponding preset question text can form a training data pair, that is, the training data pair includes a PCB defect sample image and a corresponding preset question text, and each PCB defect sample image can correspond to multiple preset question texts, that is, each PCB defect sample image can correspond to multiple training data pairs. Then each training data pair is input into the initial detection model for processing, and the predicted answer corresponding to the preset question text is output.

[0038] Specifically, the initial detection model includes an image encoding network and a text encoding network. The PCB defect sample image is input into the image encoding network to obtain an encoded image. The preset question text is input into the text encoding network to obtain text words. Prediction is performed based on the encoded image and text words, and the predicted answer corresponding to the preset question text is output.

[0039] Specifically, the server or terminal can also obtain a template image corresponding to the PCB defect sample image, where the template image refers to an image that does not include PCB defects and the template image is not annotated with descriptive text; the template image, the PCB defect sample image and the corresponding preset question text are input into the initial detection model for processing, and the predicted answer corresponding to the preset question text is output.

[0040] S206. Determine a training loss according to the difference between the predicted answer and the standard answer, and train the initial detection model based on the training loss to obtain a defect detection model.

[0041] The standard answer is used to represent the correct answer corresponding to the preset question text. The standard answer can be obtained based on the image description and defect description in the PCB defect sample image.

[0042] Specifically, the server or terminal obtains the standard answer, determines the training loss according to the difference between the predicted answer and the standard answer, trains the initial detection model based on the training loss until the training condition is met, and then uses the initial detection model that meets the training condition as the defect detection model. The training condition may be that the training loss is less than or equal to the loss threshold, or that the number of training times reaches the number threshold, etc.

[0043] It can be seen that in the embodiment of the present application, by using PCB defect sample images including image descriptions and defect descriptions and corresponding preset question texts as PCB defect sample training sets, the initial detection model is trained to obtain a defect detection model, and multi-level annotation of sample images is achieved, which can increase the diversity of training samples and improve the generalization ability of the defect detection model; at the same time, the preset question text and the annotated sample images are used together to train the model, which can improve the quality of training samples, reduce the convergence difficulty of model training, and improve the accuracy of the trained model.

[0044] In some embodiments, obtaining a PCB defect sample training set in S202 includes:

[0045] Performing description text annotation on the acquired initial PCB image to obtain a PCB text annotation image; the description text annotation includes annotation of description texts at multiple different levels;

[0046] Perform data augmentation on the PCB text annotation image to obtain the PCB defect sample image;

[0047] Based on the PCB defect sample images, a PCB defect sample training set is determined.

[0048] Among them, the initial PCB image refers to the image corresponding to the PCB, and the initial PCB image can be a PCB image acquired by the camera. The description text may include texts of multiple different levels of descriptions such as image description text and defect description text, that is, the initial PCB image is annotated with multiple different levels of description texts such as image description text and defect description text to obtain a PCB text annotated image, that is, the PCB text annotated image is a PCB image annotated with the description text. The image description text refers to the text corresponding to the PCB image description, and the image description text may include a first type of description text and a second type of description text. The first type of description text refers to the text corresponding to the first type of description, and the second type of description text refers to the text corresponding to the second type of description. Correspondingly, the defect description text refers to the text corresponding to the PCB defect description, and the defect description text may include a first defect description text and a second defect description text. The first defect description text refers to the text corresponding to the first defect description, and the second defect description text refers to the text corresponding to the second defect description. Among them, the meanings of the first type of description, the second type of description, the first defect description, and the second defect description can be referred to the description and explanation in the aforementioned embodiment, and will not be repeated here. In other words, the description text may include texts of multiple different levels of descriptions, such as first type description text, second type description text, first defect description text, and second defect description text. Correspondingly, the annotation of a description text can be understood as the annotation of one level of description text, and the description text annotation includes annotations of multiple different levels of description texts.

[0049] Specifically, data augmentation of the PCB text annotation image can be achieved by adjusting the color, horizontally flipping, vertically flipping, randomly scaling, etc. of the PCB text annotation image, wherein the angle corresponding to the flipping can be multiple angles, such as flipping each angle in 0-360 degrees, and the scaling ratio can also be multiple, such as scaling any one or more ratios between 10%-100%. It should be noted that when flipping, the position of the description text annotation is also updated accordingly, that is, when the flipping operation is performed, the description text in the PCB text annotation image is also flipped accordingly to avoid inconsistency between the description text and the corresponding PCB image information after the flipping operation. By performing data augmentation on the PCB text annotation image, a rapid increase in the number of training samples can be achieved. In some practical application scenarios, data augmentation is performed in the above manner, and based on an initial PCB image, dozens or hundreds of PCB defect sample images can be correspondingly augmented. Then, the obtained PCB defect sample images are used as PCB defect sample training sets.

[0050] It can be seen that in this embodiment, by annotating the initial PCB image with descriptive text and then performing data augmentation to obtain a PCB defect sample image, and then obtaining a PCB defect sample training set, the amount of training data can be quickly increased, thereby greatly expanding the amount of training data and further improving the generalization ability of the model.

[0051] In some embodiments, the initial detection model includes an image encoding network, a text encoding network, an alignment network, and a prediction network; the PCB defect sample image and the corresponding preset question text are input into the initial detection model for processing, and the predicted answer corresponding to the preset question text is output, including:

[0052] Input the PCB defect sample image into the image encoding network for encoding to obtain a first image unit; input the preset problem text into the text encoding network for lemma processing to obtain a text lemma;

[0053] Aligning the first image unit with the text word unit through an alignment network to obtain an aligned first image unit;

[0054] The text word unit and the aligned first image unit are input into the prediction network for processing, and the predicted answer corresponding to the preset question text is output.

[0055] Among them, the image encoding network can encode the input image to obtain the image unit corresponding to the input image. The image unit can be understood as an image feature. The first image unit can include multiple image features, such as color, texture, shape, edge, corner point, contour and other features. Tokenization refers to the process of decomposing a text string into smaller units or "tokens". Tokens can include words, punctuation marks, numbers, special characters, etc. Then, the first image unit is the image unit corresponding to the PCB defect sample image, the text token is the token corresponding to the preset question text, and the prediction network is used to predict the answer to the input question. The predicted answer is the answer to the preset question text predicted by the prediction network. The image encoding network can be an image encoder, such as the image encoder of the CLIP (Contrastive Language-Image Pre-training) model or the image encoder of the SAM (Segment Anything Model) model, and the text encoding network can be a text encoder.

[0056] Specifically, the alignment network can align the first image unit with the text word based on semantics to obtain the aligned first image unit, and then splice the text word and the aligned first image unit to obtain the image-text word, and then input the image-text word into the prediction network for prediction processing, and output the predicted answer corresponding to the preset question text.

[0057] In some embodiments, Figure 3 As shown, the initial detection model includes an image encoding network 302, a text encoding network 304, an alignment network 306 and a prediction network 308. The PCB defect sample image is input into the image encoding network 302 for encoding to obtain a first image unit 310. The preset question text is input into the text encoding network 304 for word unit processing to obtain a text word unit 312. The first image unit 310 is aligned with the text word unit 312 through the alignment network 306 to obtain an aligned first image unit 314. The text word unit 312 and the aligned first image unit 314 are spliced ​​to obtain an image text word unit 316. The image text word unit 316 is input into the prediction network 308 for processing to obtain and output a predicted answer corresponding to the preset question text. Among them, the prediction network 308 can be a large language model or a neural network model. The preset question text is, for example, "please give an image description", "please describe the image defect", etc., and the image therein is the image input to the image encoding network.

[0058] It can be seen that in this embodiment, the input image is encoded through the image encoding network to obtain the corresponding image unit, the input text is tokenized through the text encoding network to obtain the corresponding text word, and then the image unit and the text word are input into the prediction network to predict the answer, which can improve the accuracy of the predicted answer and thus improve the convergence speed of the training model.

[0059] In some embodiments, the above method further comprises:

[0060] Acquire a PCB template image corresponding to the PCB defect sample image, where the PCB template image refers to an image that does not include PCB defects;

[0061] Inputting the PCB template image into the image encoding network for encoding to obtain a second image unit;

[0062] Aligning the second image unit with the text word unit through an alignment network to obtain an aligned second image unit;

[0063] The text word unit and the aligned first image unit are input into the prediction network for processing, and the predicted answer corresponding to the preset question text is output, including:

[0064] The text word unit, the aligned first image unit and the aligned second image unit are input into the prediction network for processing, and the predicted answer corresponding to the preset question text is output.

[0065] Among them, the PCB template image is used to characterize the defect-free PCB image. In an actual application scenario, for a defective PCB, the image corresponding to the PCB can be collected as the initial PCB image, and the initial PCB image can be annotated with descriptive text and data augmented to obtain a PCB defect sample image; the defects of the PCB are processed to obtain a defect-free PCB, and the image corresponding to the defect-free PCB is collected to obtain the PCB template image corresponding to the PCB defect sample image. It can be understood that multiple PCB defect sample images obtained after data augmentation of the same text-annotated image can correspond to the same template image.

[0066] In this embodiment, the PCB template image is processed in the same way as the aforementioned PCB defect sample image to obtain an aligned second image unit, that is, the template image is input into the image encoding network for encoding to obtain a second image unit, and the second image unit is aligned with the text word through the alignment network to obtain an aligned second image unit. The second image unit is an image unit corresponding to the PCB template image.

[0067] Specifically, the prediction network includes a large language model. The text word unit, the aligned first image unit and the aligned second image unit are input into the prediction network for processing, which is equivalent to using the text word unit as a prompt word. The prompt word prompts the large language model to predict the answer corresponding to the preset question text, thereby obtaining a predicted answer.

[0068] In some embodiments, Figure 4As shown, the initial detection model is a multimodal model, and the initial detection model includes an image encoding network 402, a text encoding network 404, an alignment network 406 and a prediction network 408. The PCB defect sample image is input into the image encoding network 402 for encoding to obtain a first image unit 410. The preset question text is input into the text encoding network 404 for word-metamorphosis processing to obtain a text word 412. The first image unit 410 is aligned with the text word 412 through the alignment network 406 to obtain an aligned first image unit 414. The PCB template image is input into the image encoding network 402 for encoding to obtain a second image unit 416. The second image unit 416 is aligned with the text word 412 through the alignment network 406 to obtain an aligned second image unit 418. Then, the aligned first image unit 414, the text word 412 and the aligned second image unit 418 are spliced ​​to obtain an image text word 420. The image text word 420 is input into the prediction network 408 for processing, and a predicted answer corresponding to the preset question text is output. The preset question text may be, for example, "Please compare the difference between the two images and describe the content of one of the images based on the difference", or the two input images may be distinguished based on the image identifier, for example, the PCB defect sample image corresponds to image A, and the PCB template image corresponds to image B, then the preset question text may be "Please compare the content of image A and image B, obtain the difference between image A and image B, and describe the content of image A based on the difference". It is understandable that Figure 4 The boxes of different colors represent different feature data, including the first image unit, the second image unit, the text word unit, and the image text word unit.

[0069] It can be seen that in this embodiment, on the basis of inputting the PCB defect sample image and the preset question text into the initial detection model, the PCB template image corresponding to the PCB defect sample image is input into the initial detection model, and the preset question text is used as a prompt word. Based on the prompt word, the initial detection model can better compare the subtle differences between the PCB defect sample image and the PCB template image, thereby improving the recognition ability of subtle defects of the trained defect detection model.

[0070] In some embodiments, the text word unit, the aligned first image unit, and the aligned second image unit are input into a prediction network for processing, and a predicted answer corresponding to a preset question text is output, including:

[0071] splicing the text word unit, the aligned first image unit and the aligned second image unit according to the semantic order of the preset question text to obtain a spliced ​​word unit;

[0072] The concatenated word units are input into the prediction network for processing, and the predicted answer corresponding to the preset question text is output.

[0073] Among them, the spliced ​​word is used to represent the features obtained by splicing the text word, the aligned first image unit and the aligned second image unit. The semantics of the spliced ​​word is the same as the semantics of the preset question text, except that the corresponding PCB defect sample image in the text word is replaced by the aligned first image unit, and the corresponding PCB template image in the text word is replaced by the aligned second image unit. The spliced ​​word is input into the prediction network through the instructions corresponding to the preset question text.

[0074] The prediction network includes a large language model, that is, the concatenated words can be input into the large language model. Through the powerful processing capability of the large language model, the difference between the PCB defect sample image and the PCB template image can be compared, and the defects in the PCB defect sample image can be found based on the difference, thereby improving the defect detection model's ability to detect subtle defects in complex backgrounds.

[0075] It can be seen that in this embodiment, the text word unit, the aligned first image unit and the aligned second image unit are spliced ​​according to the semantic order of the preset question text to obtain the spliced ​​word unit, and then the spliced ​​word unit is input into the prediction network for processing, so that the prediction network can more accurately determine the prediction direction, improve the accuracy of the output prediction answer, and thus improve the convergence speed of the model training.

[0076] In some embodiments, aligning the first image unit with the text word through an alignment network to obtain an aligned first image unit includes:

[0077] Mapping the first image unit to the initial dimensional space through the alignment network to obtain image feature representation;

[0078] Calculate the similarity between the image feature representation and the text word, and determine the alignment loss based on the similarity;

[0079] A target dimensional space is determined based on the alignment loss, and the first image unit is aligned with the text word based on the target dimensional space to obtain an aligned first image unit.

[0080] The initial dimensional space may be a pre-set dimensional space, and the dimension of the initial dimensional space may be set according to the actual application scenario. Usually, the dimension of the initial dimensional space is higher than the dimension of the first image unit. Mapping the first image unit to the initial dimensional space is equivalent to mapping the first image unit to a high-dimensional space through a nonlinear transformation, and the nonlinear transformation may be, for example, a polynomial transformation, a Fourier transformation, and the like.

[0081] Specifically, after obtaining the image feature representation in the initial dimensional space, the similarity between the image feature representation and the text word is calculated, the alignment loss is determined according to the similarity, and the dimensional space for mapping the first image unit is re-determined based on the alignment loss until the alignment loss meets the alignment condition. For example, the alignment loss is not greater than the alignment loss threshold, and the dimensional space corresponding to the alignment loss that meets the alignment condition is taken as the target dimensional space, and then the first image unit is mapped to the target dimensional space to obtain the aligned first image unit.

[0082] Specifically, the cosine similarity between the image feature representation and the text word unit can be calculated, and then the cosine similarity loss can be calculated based on the cosine similarity, and the cosine similarity loss can be used as the alignment loss. Alternatively, the mean square error (MSE) of the similarity between the image feature representation and the text word unit can be calculated, and the mean square error can be used as the alignment loss. Alternatively, the cross entropy loss of the similarity between the image feature representation and the text word unit can be calculated, and the cross entropy loss can be used as the alignment loss. It should be noted that the implementation method of determining the alignment loss based on the similarity is not specifically limited in this embodiment.

[0083] In some embodiments, a schematic diagram of aligning the first image unit with the text word is as follows: Figure 5 As shown, the PCB defect sample image is encoded by the image encoding network to obtain a first image unit 502, and then the first image unit is mapped to the initial dimensional space by the conversion layer in the alignment network to obtain an image feature representation 504; the preset problem text is tokenized by the text encoding network to obtain a text token 506, and the alignment network calculates the similarity between the image feature representation 504 and the text token 506, and the alignment loss is determined according to the similarity. When the alignment loss meets the alignment condition, the dimensional space corresponding to the alignment loss meeting the alignment condition is used as the target dimensional space, and then the first image unit is mapped to the target dimensional space to obtain the aligned first image unit. For example, the image encoding network can use the image encoder of the SAM model, which can process images of 1024*1024 size. Compared with the image encoder of CLIP that processes images of 224*224 size, the image encoder of the SAM model can process images of larger sizes, so that the model can more easily identify small defects in the PCB defect image. It can be understood that the image encoding network can be selected according to the image size that needs to be processed or the defect size that needs to be identified.

[0084] It can be seen that in this embodiment, the first image unit is mapped in the dimensional space through the alignment network to obtain the corresponding image feature representation, the alignment loss is determined according to the difference between the image feature representation and the text word, the target dimensional space that can meet the alignment condition is determined based on the alignment loss, and then the first image unit is mapped to the target dimensional space to obtain the aligned first image unit. It can be achieved that the target dimensional space is accurately determined to align the first image unit and the text word to obtain the aligned first image unit, that is, the accuracy of the obtained first image unit can be improved.

[0085] In some embodiments, the initial detection model includes a prediction network; in S206, the initial detection model is trained based on the training loss to obtain a defect detection model, including:

[0086] Based on the training loss, other networks except the prediction network in the initial detection model are trained to obtain other trained networks;

[0087] Based on the trained other networks and the prediction network, a defect detection model is determined.

[0088] The initial detection model includes a prediction network and other networks. The prediction network may include a large language model or a neural network model and other models with prediction functions.

[0089] During training, other networks in the initial detection model are trained based on the training loss until the training conditions are met to obtain other trained networks. That is, during training, the parameters of the prediction network can be fixed and the parameters of other networks are trained until the parameters of other networks meet the training conditions to obtain other trained networks. Then the trained other networks are combined with the prediction network to obtain a defect detection model.

[0090] It can be seen that in this embodiment, by fixing the prediction network in the initial detection model during model training and training the parameters of other networks, that is, fixing some network parameters unchanged and only training some of the network parameters, the convergence speed of the model can be accelerated, the time consumption of model training can be reduced, the efficiency of model training can be improved, and the accuracy of the trained model can be guaranteed.

[0091] In some embodiments, Figure 6 As shown, taking the prediction network including a large language model as an example, the model training method includes S602 to S618.

[0092] S602, obtaining an initial PCB image, and performing text annotation of image description and defect description on the initial PCB image to obtain a PCB text annotated image.

[0093] S604, performing data augmentation on the PCB text annotation image to obtain a PCB defect sample image.

[0094] The PCB defect sample training set is composed of multiple PCB defect sample images.

[0095] S606, obtaining a preset problem text and a PCB template image, wherein the preset problem text is determined based on at least one of an image description and a defect description; and the PCB template image is an image without PCB defects corresponding to the PCB defect sample image.

[0096] S608, input the PCB defect sample image into the image coding network for encoding to obtain a first image unit; input the preset problem text into the text coding network for tokenization to obtain text tokens; input the PCB template image into the image coding network for encoding to obtain a second image unit.

[0097] S610, aligning the first image unit with the text word through an alignment network to obtain an aligned first image unit; aligning the second image unit with the text word through an alignment network to obtain an aligned second image unit.

[0098] S612, splicing the text word unit, the aligned first image unit and the aligned second image unit according to the semantic order of the preset question text to obtain a spliced ​​word unit.

[0099] S614, input the concatenated word-unit into the prediction network for processing, and output the predicted answer corresponding to the preset question text.

[0100] S616, determining a training loss according to the difference between the predicted answer and the standard answer, and training other networks except the prediction network in the initial detection model based on the training loss to obtain other trained networks.

[0101] S618, determining a defect detection model based on the trained other networks and the prediction network.

[0102] It can be understood that the meanings of the terms and steps in S602 to S618 in this embodiment can be found in the explanations and descriptions of the corresponding terms and steps in the above embodiments, and will not be repeated here.

[0103] In this embodiment, by performing multi-level annotation of image description and defect description on PCB images and data augmentation, a large amount of high-quality training data sets can be obtained, thereby solving the problem of poor model generalization ability caused by limited data quality or quantity, and improving the generalization ability of the model; through the powerful reasoning and prediction ability of the large language model, the preset question text can be used as a prompt word, and the prompt word enables the large language model to compare the difference between the PCB defect sample image and the PCB template image, so that the trained model has the ability to better identify subtle defects, thereby improving the model's recognition ability for complex defects.

[0104] It should be understood that, although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indications of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0105] Based on the same inventive concept, the embodiment of the present application also provides a defect detection model training device. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more defect detection model training device embodiments provided below can refer to the limitations of the defect detection model training method above, and will not be repeated here.

[0106] like Figure 7 As shown, the embodiment of the present application provides a defect detection model training device, comprising:

[0107] The sample acquisition module 702 is used to acquire a PCB defect sample training set and a preset question text; the PCB defect sample training set includes a plurality of PCB defect sample images, each PCB defect sample image includes an image description and a defect description; the preset question text is determined based on at least one of the image description and the defect description;

[0108] The answer prediction module 704 is used to input the PCB defect sample image and the corresponding preset question text into the initial detection model for processing, and output the predicted answer corresponding to the preset question text;

[0109] The model training module 706 is used to determine the training loss according to the difference between the predicted answer and the standard answer, and train the initial detection model based on the training loss to obtain a defect detection model.

[0110] In some embodiments, in terms of obtaining a PCB defect sample training set, the sample acquisition module 702 is specifically used to:

[0111] Performing description text annotation on the acquired initial PCB image to obtain a PCB text annotation image; the description text annotation includes annotation of description texts at multiple different levels;

[0112] Perform data augmentation on the PCB text annotation image to obtain the PCB defect sample image;

[0113] Based on the PCB defect sample images, a PCB defect sample training set is determined.

[0114] In some embodiments, the initial detection model includes an image encoding network, a text encoding network, an alignment network, and a prediction network; in terms of inputting the PCB defect sample image and the corresponding preset question text into the initial detection model for processing and outputting the predicted answer corresponding to the preset question text, the answer prediction module 704 is specifically used to:

[0115] Input the PCB defect sample image into the image encoding network for encoding to obtain a first image unit; input the preset problem text into the text encoding network for lemma processing to obtain a text lemma;

[0116] Aligning the first image unit with the text word unit through an alignment network to obtain an aligned first image unit;

[0117] The text word unit and the aligned first image unit are input into the prediction network for processing, and the predicted answer corresponding to the preset question text is output.

[0118] In some embodiments, the defect detection model training device further includes an image encoding module, which is used to: obtain a PCB template image corresponding to the PCB defect sample image, where the PCB template image refers to an image that does not include PCB defects; input the PCB template image into an image encoding network for encoding to obtain a second image unit; align the second image unit with a text word through an alignment network to obtain an aligned second image unit;

[0119] In terms of inputting the text word unit and the aligned first image unit into the prediction network for processing and outputting the predicted answer corresponding to the preset question text, the answer prediction module 704 is specifically used for:

[0120] The text word unit, the aligned first image unit and the aligned second image unit are input into the prediction network for processing, and the predicted answer corresponding to the preset question text is output.

[0121] In some embodiments, in terms of inputting the text word unit, the aligned first image unit, and the aligned second image unit into the prediction network for processing and outputting the predicted answer corresponding to the preset question text, the answer prediction module 704 is specifically used to:

[0122] splicing the text word unit, the aligned first image unit and the aligned second image unit according to the semantic order of the preset question text to obtain a spliced ​​word unit;

[0123] The concatenated word units are input into the prediction network for processing, and the predicted answer corresponding to the preset question text is output.

[0124] In some embodiments, in aligning the first image unit with the text word through the alignment network to obtain the aligned first image unit, the answer prediction module 704 is specifically used to:

[0125] Mapping the first image unit to the initial dimensional space through the alignment network to obtain image feature representation;

[0126] Calculate the similarity between the image feature representation and the text word, and determine the alignment loss based on the similarity;

[0127] A target dimensional space is determined based on the alignment loss, and the first image unit is aligned with the text word based on the target dimensional space to obtain an aligned first image unit.

[0128] In some embodiments, the initial detection model includes a prediction network; in training the initial detection model based on the training loss to obtain the defect detection model, the model training module 706 is specifically used to:

[0129] Based on the training loss, other networks except the prediction network in the initial detection model are trained to obtain other trained networks;

[0130] Based on the trained other networks and the prediction network, a defect detection model is determined.

[0131] Each module in the above defect detection model training device can be implemented in whole or in part by software, hardware and their combination. Each module can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.

[0132] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 8 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data related to defect detection model training. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in the above-mentioned defect detection model training method are implemented.

[0133] In some embodiments, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be realized through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the steps in the above-mentioned defect detection model training method are implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen; the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse, etc.

[0134] Those skilled in the art will understand that Figure 8 or Fig. 9The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0135] In some embodiments, a computer device is provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps in the above method embodiments are implemented.

[0136] In some embodiments, Fig.10 The figure shows an internal structure diagram of a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0137] In some embodiments, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0138] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0139] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0140] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0141] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A defect detection model training method, characterized in that: include: Obtain PCB defect sample training set and preset question text; The PCB defect sample training set includes a plurality of PCB defect sample images, each of which includes an image description and a defect description; the preset question text is determined based on at least one of the image description and the defect description; the image description refers to an overall feature description of the PCB defect sample image; the defect description refers to a description of a defect in the PCB defect sample image; Inputting the PCB defect sample image into an image coding network for encoding to obtain a first image unit; Input the preset question text into the text encoding network for lemma processing to obtain text lemmas; Aligning the first image unit with the text word unit through an alignment network to obtain an aligned first image unit; Acquire a PCB template image corresponding to the PCB defect sample image, wherein the PCB template image refers to an image that does not include PCB defects; Inputting the PCB template image into the image encoding network for encoding to obtain a second image unit; Aligning the second image unit with the text word unit through the alignment network to obtain an aligned second image unit; Inputting the text word unit, the aligned first image unit and the aligned second image unit into a prediction network for processing, and outputting a predicted answer corresponding to the preset question text; The training loss is determined according to the difference between the predicted answer and the standard answer, and the initial detection model is trained based on the training loss to obtain a defect detection model; the initial detection model includes the image encoding network, the text encoding network, the alignment network and the prediction network.

2. The method according to claim 1, characterized in that The step of obtaining a PCB defect sample training set includes: Performing description text annotation on the acquired initial PCB image to obtain a PCB text annotation image; the description text annotation includes annotation of description texts at multiple different levels; Performing data augmentation on the PCB text-annotated image to obtain the PCB defect sample image; Based on the PCB defect sample image, the PCB defect sample training set is determined.

3. The method according to claim 1, characterized in that The step of inputting the text word unit, the aligned first image unit, and the aligned second image unit into a prediction network for processing, and outputting a predicted answer corresponding to the preset question text comprises: Splicing the text word unit, the aligned first image unit and the aligned second image unit according to the semantic order of the preset question text to obtain a spliced ​​word unit; The concatenated word-unit is input into the prediction network for processing, and a predicted answer corresponding to the preset question text is output.

4. The method according to claim 1, characterized in that The step of aligning the first image unit with the text word unit through an alignment network to obtain an aligned first image unit includes: Mapping the first image unit to an initial dimensional space through the alignment network to obtain an image feature representation; Calculating the similarity between the image feature representation and the text word, and determining the alignment loss according to the similarity; A target dimensional space is determined based on the alignment loss, and the first image unit is aligned with the text word based on the target dimensional space to obtain an aligned first image unit.

5. The method according to claim 1, characterized in that The initial detection model is trained based on the training loss to obtain a defect detection model, including: Based on the training loss, other networks except the prediction network in the initial detection model are trained to obtain other trained networks; Based on the trained other networks and the prediction network, a defect detection model is determined.

6. The method according to any one of claims 1 to 5, characterized in that The prediction network includes a large language model.

7. The method according to any one of claims 1 to 5, characterized in that The image description includes a first type of description and a second type of description, wherein the first type of description has a less detailed level than the second type of description.

8. A defect detection model training device, characterized in that: include: Sample acquisition module, used to obtain PCB defect sample training set and preset question text; The PCB defect sample training set includes a plurality of PCB defect sample images, each of which includes an image description and a defect description; the preset question text is determined based on at least one of the image description and the defect description; the image description refers to an overall feature description of the PCB defect sample image; the defect description refers to a description of a defect in the PCB defect sample image; An answer prediction module is used to input the PCB defect sample image into an image coding network for encoding to obtain a first image unit; Input the preset question text into the text encoding network for tokenization processing to obtain text tokens; align the first image unit with the text token through the alignment network to obtain the aligned first image unit; obtain a PCB template image corresponding to the PCB defect sample image, wherein the PCB template image refers to an image that does not include PCB defects; input the PCB template image into the image encoding network for encoding to obtain a second image unit; The second image unit is aligned with the text word unit through the alignment network to obtain an aligned second image unit; the text word unit, the aligned first image unit and the aligned second image unit are input into the prediction network for processing, and a predicted answer corresponding to the preset question text is output; A model training module is used to determine the training loss according to the difference between the predicted answer and the standard answer, and train the initial detection model based on the training loss to obtain a defect detection model; the initial detection model includes the image encoding network, the text encoding network, the alignment network and the prediction network.

9. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

11. A computer program product, characterized in that The computer program product comprises a computer program, which implements the steps of the method according to any one of claims 1 to 7 when executed by a processor.

Citation Information

Patent Citations

  • Document detection model training method and device and electronic equipment

    CN117333889A