A semi-supervised part defect detection method based on an adversarial mechanism
By employing adversarial semi-supervised learning and utilizing the collaborative training of a contrastive classification network and a discriminator, the accuracy and robustness issues of part defect detection on small sample datasets are addressed, achieving efficient industrial part defect detection.
Patent Information
- Application Number
- CN202211676922.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-26
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2042-12-26
AI Technical Summary
In industrial parts defect detection, existing deep learning methods require a large amount of labeled data, resulting in insufficient expressiveness and robustness on small sample datasets, making it difficult to effectively detect manufacturing defects in parts such as multilayer ceramic capacitors.
A semi-supervised part defect detection method based on adversarial mechanism is adopted. By comparing the collaborative training of the classification network and the discriminator, and using labeled and unlabeled datasets for semi-supervised learning, the method judges whether two images are similar in order to indirectly predict the category label, thereby improving the detection accuracy and robustness.
On small-batch labeled datasets, high-precision and robust part defect detection is achieved, abandoning the traditional deep learning approach of directly predicting the category label of a single image, thus improving the effectiveness and stability of detection.
Smart Images

Figure CN115830397B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of target detection technology, specifically relating to a semi-supervised part defect detection method based on an adversarial mechanism. Background Technology
[0002] With industrial development, research on defect detection of industrial parts surfaces is becoming increasingly necessary. For example, industrial parts such as multilayer ceramic capacitors (MLCCs), which consist of stacked capacitor modules with metallized terminals connecting to integrated circuit boards, are susceptible to various manufacturing defects, including cracks, blistering, debris, contamination, and voids in the termination coating. Furthermore, these capacitors can store a large amount of energy; failures not only affect defective MLCCs but can also damage adjacent components or the integrated circuit board itself. Therefore, defect detection of these parts is essential.
[0003] In recent years, deep learning has made significant progress in image classification tasks and has been rapidly applied to industrial inspection, achieving superior performance in defect detection of parts. For example, VGGNet and ResNet neural network models based on convolutional neural networks (CNNs) can achieve accuracy rates of over 85% on large training sets, meeting industrial needs. Furthermore, with the introduction of the Transformer model, defect detection accuracy can be stabilized at over 90%.
[0004] However, these deep learning methods typically require sufficient labeled data to train a classifier with good performance, meaning they need to accumulate a large amount of labeled data to train the classifier. However, in many cases, MLCC surface defect datasets are insufficient, and due to the high resource consumption of manually labeling datasets, it is often difficult to obtain a large number of labeled training samples. This greatly limits the generalization ability and robustness of deep learning methods. Therefore, this application proposes a semi-supervised part defect detection method based on an adversarial mechanism to address the performance degradation of traditional deep learning methods on small datasets containing a large number of unlabeled samples. Summary of the Invention
[0005] The purpose of this invention is to address the above-mentioned problems by proposing a semi-supervised part defect detection method based on an adversarial mechanism, which has high detection accuracy and good performance and robustness on small batches of labeled datasets.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0007] This invention proposes a semi-supervised part defect detection method based on an adversarial mechanism, comprising the following steps:
[0008] S1. Establish a contrastive classification network, which includes a classifier C initialized with parameter θ.θ and initialization parameters are Discriminator
[0009] S2, using the labeled parts image dataset S l Training classifier C θ ;
[0010] S3. Utilizing the labeled parts image dataset S l And unlabeled parts image dataset S u Training the discriminator Specifically as follows:
[0011] S31, From the dataset S of labeled part images l Randomly sample a triplet And obtain the corresponding matching score c, where, if and If they match, the matching score c is 1. and If they do not match, the matching score c is 0. For image pairs True similarity Image and pictures Dissimilar Image and pictures resemblance, For classifier C θ Output image pairs The predicted similarity, Image and pictures Dissimilar Image and pictures resemblance;
[0012] S32, From the unlabeled parts image dataset S u Randomly sample an image pair and the image Input classifier C θ Perform forward propagation to obtain the corresponding predicted similarity. Then the triplet Input discriminator Perform forward propagation to obtain the predicted matching score.
[0013] S33. Calculate the first loss function L based on the value function. D Second loss function L CThe process of forming an adversarial relationship includes:
[0014] 1) Establish the value function:
[0015]
[0016] In the formula, E represents the expectation. Represents a triplet Follows the first probability distribution p l , Indicates image pair Follows the second probability distribution p u , This represents the discriminator's predicted match score;
[0017] 2) Transform the value function into the first loss function L D Second loss function L C The formula is as follows:
[0018] When the preset number of training iterations is reached:
[0019]
[0020]
[0021] When the preset number of training iterations has not been reached:
[0022]
[0023]
[0024] In the formula, λ is the equilibrium hyperparameter. This represents the predicted matching score of the discriminator in the k-th batch;
[0025] S34, the first loss function L D Second loss function L C Perform backpropagation and use the Adam optimizer to optimize parameters;
[0026] S35. Determine the first loss function L D Second loss function L C Has convergence been achieved? If yes, proceed to step S4; otherwise, return to step S31.
[0027] S4. Using the trained classifier C θ Predictions are made from images of the parts to be tested to obtain the final inspection results.
[0028] Preferably, the labeled parts image dataset S is used. l Training classifier C θ The details are as follows:
[0029] S21, From the labeled parts image dataset S l Randomly sample an image pair And obtain the corresponding true similarity.
[0030] S22. Adjust the image... Input classifier C θ Perform forward propagation to obtain the corresponding predicted similarity.
[0031] S23. Based on true similarity and predicted similarity Calculate the first cost function L Csup The formula is as follows:
[0032]
[0033] In the formula, For the image pairs in the kth batch The predicted similarity, where K is the batch size, k = 1, ..., K;
[0034] S24, Apply the first cost function L Csup Perform backpropagation and use the Adam optimizer to optimize parameters;
[0035] S25. Determine the first cost function L. Csup If convergence has occurred, proceed to step S3; otherwise, return to step S21.
[0036] Preferably, the first cost function L Csup Perform backpropagation and use the Adam optimizer to optimize the parameters, as shown in the following formula:
[0037]
[0038] In the formula, To obtain the gradient with respect to θ, a is the learning rate preserved by stochastic gradient descent, β1 is the exponential decay rate estimated by the first moment, and β2 is the exponential decay rate estimated by the second moment.
[0039] Preferably, the first loss function L D Second loss function L c Perform backpropagation and use the Adam optimizer to optimize the parameters, as shown in the following formula:
[0040]
[0041]
[0042] In the formula, To Find the gradient. To obtain the gradient with respect to θ, a is the learning rate preserved by stochastic gradient descent, β1 is the exponential decay rate estimated by the first moment, and β2 is the exponential decay rate estimated by the second moment.
[0043] Preferably, the trained classifier C is used. θ The process of predicting the image of the part to be tested to obtain the final inspection result is as follows:
[0044] S41, from the labeled parts image dataset S l Select a positive sample image from the middle. and the image of the part to be tested Compared with positive sample images Pairing images together forms image pairs
[0045] S42. Adjust the image... Input the trained contrastive classification network, and obtain the corresponding predicted similarity through the forward propagation of the trained contrastive classification network.
[0046] S43. Determine whether the conditions are met. η is the similarity threshold; if it is, then... and If the images of the parts to be tested are of the same category, that is, if they are positive samples, it means that the parts to be tested are defect-free and qualified; otherwise, if the images of the parts to be tested are negative samples, it means that the parts to be tested are defective and unqualified.
[0047] Preferably, each part image dataset includes images of defect-free, qualified parts and images of defective, unqualified parts.
[0048] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0049] This method employs a semi-supervised learning approach, utilizing adversarial mechanisms to train a high-precision and robust classifier on small-batch labeled parts image datasets. In adversarial learning, the discriminator is trained semi-supervised, using both labeled and unlabeled parts image datasets, and then a co-classifier performs classification. This approach abandons the traditional deep learning classification task's concept of predicting the category label of a single image, instead focusing on determining whether two images are similar to indirectly predict the category label. It demonstrates good performance and robustness on small-batch labeled datasets. Attached Figure Description
[0050] Figure 1 The flowchart shows the semi-supervised part defect detection method based on the adversarial mechanism of the present invention.
[0051] Figure 2 This is a schematic diagram of the comparative classification network of the present invention. Detailed Implementation
[0052] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0053] It should be noted that, unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application.
[0054] For humans, while it's sometimes impossible to directly determine the specific category of an object, we can indirectly classify it by judging whether two objects are similar. In summary, "determining whether two objects belong to the same category" is easier than "determining which specific category an object belongs to." Based on this metric learning, we studied generalizable "contrastive knowledge" applicable to different categories and proposed a "contrastive classification network" for small-sample learning on defective data. Therefore, the classification task no longer aims to directly predict the category label of a single image, but rather focuses on determining whether two images are similar, thereby indirectly predicting the category label. This achieves the same high performance and robustness with a small batch of labeled samples.
[0055] In summary, this application proposes a contrastive classification network consisting of a classifier and a discriminator. The classifier aims to determine whether two images belong to the same category; the discriminator works collaboratively using an adversarial mechanism to ensure that the classification results are consistent with reality. Through the continuous adversarial process between the classifier and discriminator, the accuracy of classification and discrimination is continuously improved. Using this semi-supervised approach, the constructed classifier achieves high accuracy and robustness on a small batch of labeled parts image datasets. Finally, the test parts images are predicted using the finally trained classifier to obtain the corresponding final detection results.
[0056] This application relates to the research on defect detection of industrial parts surfaces, belonging to the field of object classification, and can be applied to the detection of many fields including precision components, 3C, home appliances, machinery manufacturing, semiconductors, chemicals, aerospace, etc.
[0057] like Figure 1-2As shown, a semi-supervised part defect detection method based on an adversarial mechanism includes the following steps:
[0058] S1. Establish a contrastive classification network, which includes a classifier C initialized with parameter θ. θ and initialization parameters are Discriminator
[0059] like Figure 2 As shown, the comparison classification network includes classifier C. θ (i.e., comparison classifier) and discriminator The classifier (i.e., the Matching Discriminator) has a two-branch structure, with each branch consisting of multiple encoders. The two branches are structurally identical but do not share weights. The classifier takes two unordered image pairs as input, processes them through the two branches to generate representations of length r, and then uses the difference in these representations as input to output the similarity score of the image pairs through fully connected layers. An attention mechanism is introduced into the encoder, employing a Vision Transformer architecture. First, self-attention is applied to each input image pair to extract features. This allows the two identical Vision Transformer architectures to focus on global information during feature extraction, enabling them to learn from each other's information. Therefore, after self-attention, an additional cross-attention mechanism is designed to better integrate the information from the two branches. This design allows each image to pay attention to both itself and the other, making the comparative learning effect more significant. The discriminator and classifier are structurally identical except for the number of neurons in the first layer of the final fully connected layer. Its input consists of a pair of images and a true similarity. The image pair is input at the beginning, first passing through a two-branch encoding structure to generate a representation information pair. Unlike a classifier, it then concatenates the representation information difference with the similarity vector, using this as input to the fully connected layer. The final prediction is whether the image pair matches the true similarity. Each image generates a representation information of length r after passing through the encoding branch. The representation information pairs are first subtracted and their absolute values are taken; the representation information difference is still of length r. Then, the input true similarity p is expanded to the same length as the representation information difference, i.e., [p1, p2, ..., p...]. rThen, it is concatenated with the representation information difference to form a vector of length 2r, which is then input into the fully connected layer. The discriminator will eventually output the similarity score (i.e., the matching score) between the image pairs. The score is between 0 and 1. The higher the similarity score, the more closely the image pairs match.
[0060] Figure 2 In the dataset, Labeled Samples represents the dataset S of labeled part images. l Unlabeled Samples represent the dataset S of unlabeled part images. u Image1 and Image2 represent the two images in an image pair. PredictedSimilarity Score and GT Similarity Score represent the predicted similarity and the true similarity, respectively. The left case in the figure represents the predicted similarity of different image pairs by the classifier. For example, if a threshold of 0.5 is set, a value greater than 0.5 is 1, and a value less than 0 is 0. The right case in the figure represents the matching score (True / False) of different image pairs.
[0061] This contrastive classification network utilizes an adversarial mechanism for learning. For datasets with only a small batch of labeled data, simply inputting unlabeled data into the classifier is insufficient because the cost function cannot be calculated, and the model parameters cannot be updated for further training. Therefore, a discriminator is needed to coordinate with the classifier. The discriminator judges the accuracy of the classifier's output, thus guiding parameter updates. Simultaneously, the discriminator itself needs a certain level of discriminative ability; therefore, labeled supervision signals are incorporated during training on unlabeled data, forming a semi-supervised detection system. Specifically:
[0062] S2, using the labeled parts image dataset S l Training classifier C θ .
[0063] In one embodiment, a dataset of labeled parts images S is used. l Training classifier C θ The details are as follows:
[0064] S21, From the labeled parts image dataset S l Randomly sample an image pair And obtain the corresponding true similarity.
[0065] S22. Adjust the image... Input classifier C θ Perform forward propagation to obtain the corresponding predicted similarity.
[0066] S23. Based on true similarity and predicted similarity Calculate the first cost function L Csup The formula is as follows:
[0067]
[0068] In the formula, For the image pairs in the kth batch The predicted similarity, where K is the batch size, k = 1, ..., K;
[0069] S24, Apply the first cost function L Csup Perform backpropagation and use the Adam optimizer to optimize parameters;
[0070] S25. Determine the first cost function L. Csup If convergence has occurred, proceed to step S3; otherwise, return to step S21.
[0071] In one embodiment, the first cost function L is... csup Perform backpropagation and use the Adam optimizer to optimize the parameters, as shown in the following formula:
[0072]
[0073] In the formula, To obtain the gradient with respect to θ, a is the learning rate preserved by stochastic gradient descent, β1 is the exponential decay rate estimated by the first moment, and β2 is the exponential decay rate estimated by the second moment.
[0074] S3. Utilizing the labeled parts image dataset S l And unlabeled parts image dataset S u Training the discriminator Specifically as follows:
[0075] S31, From the dataset S of labeled part images l Randomly sample a triplet And obtain the corresponding matching score c, where, if and If they match, the matching score c is 1. and If they do not match, the matching score c is 0. For image pairs True similarity Image and pictures Dissimilar Image and pictures resemblance, For classifier C θ Output image pairs The predicted similarity, Image and pictures Dissimilar Image and pictures resemblance;
[0076] S32, From the unlabeled parts image dataset S u Randomly sample an image pair and the image Input classifier C θ Perform forward propagation to obtain the corresponding predicted similarity. Then the triplet Input discriminator Perform forward propagation to obtain the predicted matching score.
[0077] S33. Calculate the first loss function L based on the value function. D Second loss function L C The process of forming an adversarial relationship includes:
[0078] 1) Establish the value function:
[0079]
[0080] In the formula, E represents the expectation. Represents a triplet Follows the first probability distribution p l , Indicates image pair Follows the second probability distribution p u , This represents the discriminator's predicted match score;
[0081] 2) Transform the value function into the first loss function L D Second loss function L C The formula is as follows:
[0082] When the preset number of training iterations is reached:
[0083]
[0084]
[0085] When the preset number of training iterations has not been reached:
[0086]
[0087]
[0088] In the formula, λ is the equilibrium hyperparameter. This represents the predicted matching score of the discriminator in the k-th batch;
[0089] S34, the first loss function L D Second loss function L C Perform backpropagation and use the Adam optimizer to optimize parameters;
[0090] S35. Determine the first loss function L D Second loss function L c Has convergence been achieved? If yes, proceed to step S4; otherwise, return to step S31.
[0091] In one embodiment, the first loss function L D Second loss function L c Perform backpropagation and use the Adam optimizer to optimize the parameters, as shown in the following formula:
[0092]
[0093]
[0094] In the formula, To Find the gradient. To obtain the gradient with respect to θ, a is the learning rate preserved by stochastic gradient descent, β1 is the exponential decay rate estimated by the first moment, and β2 is the exponential decay rate estimated by the second moment.
[0095] Unlabeled data requires some prior knowledge to train. In step S2, the classifier, using a small batch of labeled data, already possesses a certain predictive ability. However, if only unlabeled data is input into the classifier, the cost function cannot be calculated due to the lack of labels, and the model parameters cannot be updated for further training. In this case, a discriminator is introduced to determine the accuracy of the classifier's output in step S2, thereby guiding the classifier to update its parameters. Simultaneously, the discriminator itself needs a certain level of discriminative ability, so labeled supervision signals need to be incorporated while training on unlabeled data.
[0096] If the predicted similarity matches the true similarity, the matching score c is 1 (True); if the predicted similarity does not match the true similarity, the matching score c is 0 (False). The classifier hopes that its predicted image similarity will be sufficient for the discriminator to judge the image. The discriminator, on the other hand, is very strict, judging all predictions made by the classifier. Based on the above, the value function is defined. There is corresponding tag data. This corresponds to unlabeled data. The classifier aims to minimize the value function, while the discriminator aims to maximize it. The classifier's predictions become negative samples for the discriminator, making the classifier's requirements more stringent after the discriminator updates its parameters. Each parameter update by the classifier aims to improve its predictive ability, attempting to pass the discriminator's test in the next iteration. This iterative process, with both classes continuously improving their capabilities through this adversarial competition, is a testament to their combined strengths.
[0097] In the early stages of learning, when the number of training iterations has not reached the preset number and the classifier performs poorly, the discriminator can confidently reject samples because they are clearly different from the labeled training data. In this situation... Saturation. To solve this problem, a classifier C can be trained. θ , making Minimize, improve L C .
[0098] Improved L C It will make C θ and Having the same dynamic stability point allows for stronger gradients in the early stages of training. Furthermore, for the discriminator, training on labeled and unlabeled data is performed simultaneously, rather than training on labeled data first and then on unlabeled data. This is because a well-trained discriminator cannot provide sufficient gradients to a weaker classifier, leading to gradient vanishing. By mutually providing strong gradients to each other, they collectively improve the performance of both.
[0099] S4. Using the trained classifier C θ Predictions are made from images of the parts to be tested to obtain the final inspection results.
[0100] In one embodiment, a trained classifier C is used. θ The process of predicting the image of the part to be tested to obtain the final inspection result is as follows:
[0101] S41, from the labeled parts image dataset S l Select a positive sample image from the middle. and the image of the part to be tested Compared with positive sample images Pairing images together forms image pairs
[0102] S42. Adjust the image... Input the trained contrastive classification network, and obtain the corresponding predicted similarity through the forward propagation of the trained contrastive classification network.
[0103] S43. Determine whether the conditions are met. η is the similarity threshold; if it is, then... and If the images of the parts to be tested are of the same category, that is, if they are positive samples, it means that the parts to be tested are defect-free and qualified; otherwise, if the images of the parts to be tested are negative samples, it means that the parts to be tested are defective and unqualified.
[0104] In one embodiment, each part image dataset includes images of defect-free, qualified parts and images of defective, unqualified parts.
[0105] During the testing phase, only a contrastive classifier is used. Typically, representative images are selected beforehand from each category. For each image of a part to be tested, it is compared one by one with representative images from each category, and the category with the highest similarity is its class. Since the detection of surface defects in MLCCs is a binary classification problem with only two categories—positive samples (defect-free, acceptable products) and negative samples (defective, unacceptable products)—the detection result can be obtained simply by selecting a representative image from either the positive or negative samples for pairing and detection.
[0106] This method employs a semi-supervised learning approach, utilizing adversarial mechanisms to train a high-precision and robust classifier on small-batch labeled parts image datasets. In adversarial learning, the discriminator is trained semi-supervised, using both labeled and unlabeled parts image datasets, and then a co-classifier performs classification. This approach abandons the traditional deep learning classification task's concept of predicting the category label of a single image, instead focusing on determining whether two images are similar to indirectly predict the category label. It demonstrates good performance and robustness on small-batch labeled datasets.
[0107] The technical features of the above embodiments can be combined in any way. For the sake of brevity, 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.
[0108] The embodiments described above are merely specific and detailed examples of the embodiments described in this application, and should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the scope of protection of this application. Therefore, the scope of protection of this patent application should be determined by the appended claims.
Claims
1. A semi-supervised part defect detection method based on an adversarial mechanism, characterized in that: The semi-supervised part defect detection method based on the adversarial mechanism comprises the following steps: S1, a contrast classification network is established, the contrast classification network includes a classifier C with initialized parameters θ θ and a discriminator with initialized parameters S2, utilize labeled part picture dataset S l train classifier C θ ; S3, utilize labeled part picture dataset S l and unlabeled part picture dataset S u Train discriminator As follows: S31, From the dataset S of labeled part images l Randomly sample a triplet And obtain the corresponding matching score c, where, if and If they match, the matching score c is 1. and If they do not match, the matching score c is 0. For image pairs True similarity Image and pictures Dissimilar Image and pictures resemblance, For classifier C θ Output image pairs The predicted similarity, Image and pictures Dissimilar Image and pictures resemblance; S32、from the no-label part picture data set Su randomly sample a picture pair and input the picture pair into the classifier C θ forward propagation, obtain the corresponding predicted similarity and input the triple into the discriminator forward propagation, obtain the predicted matching score S33、calculating a first loss function L according to the value function D and a second loss function L C , forming an adversarial process, comprising: 1) establishing a value function: where E denotes expectation, denotes a triple subject to a first probability distribution p l , denotes a picture pair subject to a second probability distribution p u , denotes a predicted match score by the discriminator; 2) converting the value function into a first loss function L D and a second loss function L C , as follows: When the number of training reaches the preset number: When the number of training does not reach the preset number: where λ is a balancing hyperparameter, represents the predicted match score of the kth batch of discriminators; S34, the first loss function L D and the second loss function L C are back-propagated, and the parameters are optimized using an Adam optimizer; S35, judging whether the first loss function L D and the second loss function L c converges, if yes, executing step S4, otherwise, returning to execute step S31; S4, using the trained classifier C θ The final detection result of the to-be-tested part is obtained by predicting the to-be-tested part picture.
2. The adversarial mechanism based semi-supervised part defect detection method of claim 1, wherein: The labeled parts picture dataset S l Training the classifier C θ In particular as follows: S21, from the labeled part picture dataset S l a picture pair is randomly sampled and the corresponding real similarity is obtained S22, pair of pictures input classifier C θ forward propagation to obtain the corresponding prediction similarity S23、according to the real similarity and the predicted similarity calculating the first cost function L Csup , as follows: wherein is the prediction similarity of picture pair in the k-th batch, K is the batch size, k = 1,...., K; is the prediction similarity of picture pair in the k-th batch, K is the batch size, k = 1,...., K; S24, the first cost function L Csup Backpropagation is performed and the Adam optimizer is used for parameter optimization. S25. Determine the first cost function L. Csup If convergence has occurred, proceed to step S3; otherwise, return to step S21.
3. The adversarial mechanism based semi-supervised part defect detection method of claim 2, wherein: The first cost function L Csup Backpropagation is performed and the Adam optimizer is used for parameter optimization, with the formula as follows: wherein For the gradient of θ, a is the learning rate maintained by the stochastic gradient descent, β1 is the exponential decay rate of the first moment estimate, and β2 is the exponential decay rate of the second moment estimate.
4. The adversarial mechanism based semi-supervised part defect detection method of claim 1, wherein: The first loss function L D and the second loss function L c are back-propagated, and the parameters are optimized using an Adam optimizer, as follows: wherein is the gradient of is the gradient of is the gradient of is the learning rate maintained by the stochastic gradient descent, β1is the exponential decay rate of the first moment estimate, and β2is the exponential decay rate of the second moment estimate.
5. The adversarial mechanism based semi-supervised part defect detection method of claim 1, wherein: The trained classifier C is used θ The final detection result of the part to be tested is obtained by predicting the picture of the part to be tested, and the process is as follows: S41, from the labeled part picture dataset S l a positive sample picture is selected and the part picture to be tested is paired with the positive sample picture to form a picture pair S42, obtaining a picture pair inputting the trained contrast classification network, and obtaining a corresponding predicted similarity through forward propagation of the trained contrast classification network S43, judging whether the condition is satisfied η is a similarity threshold value, if yes, then and is the same category, that is, the picture of the part to be tested is a positive sample, representing that the part to be tested is qualified without defects, otherwise, the picture of the part to be tested is a negative sample, representing that the part to be tested is unqualified with defects.
6. The adversarial mechanism based semi-supervised part defect detection method of claim 1, wherein: Each of the part picture data sets comprises a qualified part picture without defects and an unqualified part picture with defects.