Image classification and defect detection method based on self-supervised contrast learning
Through the self-supervised comparison learning image classification method, the misjudgment and misjudgment of ship paint removal surface defect detection is solved, efficient defect recognition is achieved in complex environments, detection accuracy and stability are improved, and intelligent needs are met.
Patent Information
- Application Number
- CN202510562382.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-08-12
AI Technical Summary
Under complex working conditions, the image detection method of ship paint removal surfaces has problems of misjudgment and misjudgment, especially when labels are scarce, it is difficult to improve the accuracy of defect detection.
The image classification method based on self-supervised contrast learning is adopted, and the image is converted to the LAB color space, and the information of the A channel, B channel and L channel is used to generate principal component analysis feature representations. The latent feature vectors are extracted in combination with the first and second encoders, and the semantic feature encoder is optimized by contrast learning, and classification detection is performed through the classifier network.
It improves the accuracy and stability of the detection of surface defects of ship paint removal, reduces the labor intensity of workers, meets the demand for intelligence in the ship field, and improves the inspection efficiency.
Smart Images

Figure CN120472216A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and in particular to an image classification and defect detection method based on self-supervised contrast learning. Background Art
[0002] Traditional methods for removing rust from ship surfaces include sandblasting and high-pressure water paint stripping. After paint removal, the surface must be visually inspected by workers for quality defects, leading to inefficiencies and missed inspections. Due to the complex and ever-changing environment of ship construction, the air contains large amounts of dust, dirt, and paint particles, creating harsh conditions that are unsuitable for long-term manual work. Therefore, visual inspection technology is being used to replace manual inspection. After long-term voyages, ship surfaces will exhibit varying degrees of rust, surface deposits, minor scratches, and bumps. Consequently, images of metal surfaces after paint removal include both normal metal textures and images of various defects.
[0003] Because accurate datasets and defect samples for image classification are difficult to obtain, accurately identifying surface defects in complex surface processing environments is challenging. Traditional image classification techniques, using low-level image features, can easily lead to problems such as overfitting. While deep learning algorithms are widely used in industrial defect detection, traditional detection methods, such as one-class support vector machines (SVMs) and SVDDs, rely on manually labeled datasets. Classification problems using small sample images often suffer from the curse of dimensionality when directly applied to high-dimensional, complex data. Existing methods generally follow the principle of feature extraction and learning a normal data distribution. For example, Deep SVDD fits neural network outputs to a minimal set. Furthermore, anomaly detection based on generative adversarial networks (GANs) can learn to fit a normal data distribution, often producing visually clearer image data. However, these methods are limited by the lack of an operational latent space and unstable training.
[0004] Therefore, how to improve the image detection method of ship paint removal surface and improve the accuracy of defect detection when labels are scarce has become an urgent problem to be solved. Summary of the Invention
[0005] In view of this, an embodiment of the present invention provides an image classification and defect detection method based on self-supervised contrastive learning to solve the problem in the prior art that under complex working conditions, the quality classification and defect identification of the ship's paint removal surface by the wall-climbing robot visual inspection system is greatly disturbed by the external environment, and there are unnecessary misjudgments and missed judgments.
[0006] An embodiment of the present invention provides an image classification and defect detection method based on self-supervised contrastive learning, comprising:
[0007] Convert the image to be detected to the LAB color space, and generate the feature representation information of principal component analysis based on the information of the separated A channel, B channel and L channel;
[0008] Extracting target latent feature vectors from feature representation information through a first encoder;
[0009] Extracting high-level semantic information from the target latent feature vector through a first semantic feature encoder;
[0010] Classify and detect high-level semantic information through a classifier network;
[0011] The construction of the first encoder and the first semantic feature encoder includes:
[0012] Inputting the training sample set into the first encoder and the second encoder respectively to obtain a first training data set for inputting the first semantic feature encoder and a second training data set for inputting the second semantic feature encoder;
[0013] The parameters of the first semantic feature encoder and the second semantic feature encoder are optimized using contrastive learning.
[0014] Optionally, the first encoder is a deformable autoencoder based on Transformer; the second encoder is an autoencoder based on convolutional neural network.
[0015] Optionally, before inputting the first training data set and the second training data set into the first semantic feature encoder and the second semantic feature encoder respectively, the method further includes:
[0016] The mean square error loss function is used to optimize the parameters of the Transformer-based deformable autoencoder;
[0017] The parameters of the autoencoder based on convolutional neural network are optimized by using the gradient descent method combining reconstruction loss and KL divergence.
[0018] Optionally, converting the image to be detected into a LAB color space image includes:
[0019] The image to be detected is blurred with a large kernel to extract the illumination component, and then a Gaussian kernel weighted average is used to obtain the intermediate image;
[0020] The intermediate image is converted to the LAB color space through nonlinear mapping, and the spatial weight function is used to enhance the feature representation;
[0021] The information of the A channel, B channel and L channel is separated based on the LAB color space information represented by the enhanced features.
[0022] Optionally, the construction of the first encoder and the first semantic feature encoder further includes:
[0023] Use deformable attention to dynamically focus on the key areas of the input training sample set, and use the Transformer encoding mechanism to generate the first latent feature vector;
[0024] The decoder of the deformable autoencoder decodes the first latent feature vector through deformable attention dynamics to achieve fine and accurate reconstruction of local details and obtain a first training dataset.
[0025] Optionally, it also includes:
[0026] The autoencoder based on the convolutional neural network generates a second latent feature vector according to the input training sample set;
[0027] The autoencoder based on the convolutional neural network generates a second training data set according to the preset likelihood density of the second potential feature vector.
[0028] Optionally, the parameters of the first semantic feature encoder and the second semantic feature encoder are optimized by contrastive learning, including:
[0029] Input the training data into the Transformer-based deformable autoencoder to obtain the first feature;
[0030] Input the training data into the CNN-based autoencoder to obtain the second feature;
[0031] The first feature and the second feature obtained based on the same training data are used as positive sample pairs, and the second feature obtained based on different training data is used as the negative sample of the first feature;
[0032] With the first semantic feature encoder v q =f q (x q ) and the second semantic feature encoder v k =f k (x k ) respectively extract high-level semantic information from the latent feature vectors of the training data; where v q and v k+ is a positive sample pair x q and x k+ The encoded feature, v k- For all negative samples x k- Encoded features; 1≤i≤M; 1≤j≤M, M is the number of negative samples;
[0033] The optimization is performed through the improved prototype contrast learning loss function, the formula is:
[0034]
[0035] Among them, δ represents the concentration of prototype feature distribution; represents the feature representation of v and prototype c in the same cluster; Z represents the number of feature points; ω is a hyperparameter; H is the number of prototypes; by reducing L p For the first semantic feature encoder f q The parameters of the second semantic feature encoder f k The parameters of are optimized so that the enhancement module of self-supervised contrastive learning can increase the distance between prototypes.
[0036] Optionally, the optimization process of the classifier network includes:
[0037] The quality grade classification head is connected to the output of the first semantic feature encoder composed of a fully connected layer. The quality grade classification head uses the loss function to calculate the classification loss:
[0038]
[0039] Among them, Q is the representation set of the image to be detected; Y represents the set of different categories; q i,j Represents the image to be detected q i is predicted to be category j; θ is the indicator function, θ = 1 when the classification of the image to be detected is correct; p is the predicted probability;
[0040] Calculate the similarity of normal quality level sample pairs and defective sample pairs respectively, and at the same time increase the distance between normal quality level sample pairs and defective sample pairs; calculate the centroid representation of normal quality level samples and defective samples:
[0041]
[0042] Where m is the category of normal quality level, n is the category of defective quality level c m is the centroid of the normal sample, c n is the centroid representation of the defect category feature; f(x i ) represents the feature extractor; S m represents the normal quality level category label set, S n Represents a set of defect quality grade category labels;
[0043] The cosine distance is used to measure the similarity of sample pairs:
[0044]
[0045] Among them, v q is the feature representation of the image to be detected, s(·) is the similarity measurement function;
[0046] Compute defect classes using negative log-probability loss:
[0047]
[0048] The total loss function to be optimized is the weighted sum of defect classification loss, quality grade classification loss and contrast loss:
[0049]
[0050] Among them, α and β are hyperparameters that adjust the relative weight between classification loss and defect classification loss;
[0051] The parameters of the classifier network are optimized by minimizing the total loss function to be optimized.
[0052] Beneficial effects of the present invention:
[0053] The present invention proposes an image classification and defect detection method based on self-supervised contrastive learning for real-time surface quality classification and defect identification in a visual inspection system for a ship paint removal robot. This image classification algorithm not only improves detection speed and stability, but also finds application in the visual inspection and classification of high-pressure water paint removal robots. This meets the demand for intelligent shipbuilding, reduces worker workload, and improves detection efficiency. It also has important theoretical and practical implications for improving the automated rust removal and intelligent detection technology system for wall-climbing robots. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] The features and advantages of the present invention will be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the present invention in any way. In the accompanying drawings:
[0055] Figure 1 A flowchart of an image classification and defect detection method based on self-supervised contrastive learning in an embodiment of the present invention is shown;
[0056] Figure 2 A flowchart of constructing an enhancement module of self-supervised contrastive learning in an image classification and defect detection method based on self-supervised contrastive learning in an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0057] To make the purpose, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making any creative efforts shall fall within the scope of protection of the present invention.
[0058] like Figure 1 As shown, an embodiment of the present invention provides an image classification and defect detection method based on self-supervised contrastive learning, comprising:
[0059] Step S10: convert the image to be detected into the LAB color space, and generate feature representation information of principal component analysis based on the information of the separated A channel, B channel and L channel.
[0060] In this example, the image, denoised by Gaussian filtering, is converted to LAB space. LAB color space conversion decouples color and brightness, generating image features with spatial information. RGB is converted to LAB space, and information for rust enhancement (A channel), oil suppression (B channel), and reflection suppression (L channel) is extracted. Channel fusion is then performed to generate LAB space conversion information.
[0061] Specifically, a large kernel blur is used to extract the illumination component, and then a Gaussian kernel weighted average is used to retain low-frequency information and suppress high-frequency noise. The input image is represented as I, and the Gaussian kernel is convolved with the image. The new value of each pixel is the weighted average of its neighboring pixels:
[0062]
[0063] Where I(x, y) represents the pixel value of the image at (x, y), with a value range of [0, 255], k is the radius of the Gaussian kernel, the kernel size is 2k+1, and (i, j) represents the horizontal and vertical offset of the center pixel (x, y).
[0064] The core of Gaussian filtering is the Gaussian kernel, whose weights are generated by a two-dimensional Gaussian function:
[0065]
[0066] Where: G(i, j) represents the weight value of the filter kernel (convolution kernel), σ is the standard deviation of the Gaussian distribution, which controls the smoothing strength of the filter (the larger σ is, the blurrier the image is). 2 : Normalization coefficient to ensure that the sum of all weights in the kernel is 1.
[0067] Since the metal surface will be affected by water stains and oil stains during operation, the regular texture of the surface will be disturbed. Given N images X = {x1, x2, ..., x n The image after denoising is H, which is expressed as H = I (X n ).
[0068] For the input image H∈R H×W×3 (BGR format), the nonlinear mapping converted to LAB space is:
[0069]
[0070] Enhanced feature representation combining spatial information:
[0071]
[0072] Spatial weight function:
[0073]
[0074] in: is the width of each bin, is the indicator function, l,m∈{0,1,…,K-1}. In a specific embodiment, K is 16, and S=16.
[0075] Through LAB color space conversion, the information of A, B, and L channels is separated to generate the feature representation information x of principal component analysis (PCA) o ∈R s×s×h It can accurately capture color differences and is highly robust to rust, oil stains, and light.
[0076] Step S20: extracting a target latent feature vector from the feature representation information through a first encoder.
[0077] In this embodiment, the first encoder uses a Transformer-based autoencoder or a Convolutional Neural Networks (CNN) encoder to extract a target potential feature vector from the input feature representation information.
[0078] Step S30: extracting high-level semantic information from the target latent feature vector through a first semantic feature encoder.
[0079] In this embodiment, the first semantic feature encoder is optimized by contrastive learning. Therefore, a second semantic feature encoder needs to be set. On this basis, the training samples from the same training set are encoded by two different encoders to generate different training data, that is, different training data are generated by the first encoder and the second encoder.
[0080] The parameter optimization of the first semantic feature encoder and the second semantic feature encoder are updated synchronously. After the parameter optimization is completed, the first semantic feature encoder or the second semantic feature encoder can be arbitrarily selected to extract high-level semantic information.
[0081] Step S40: classify and detect the high-level semantic information through a classifier network.
[0082] like Figure 2As shown, the first encoder and the first semantic feature encoder form an image enhancement module, which extracts latent feature vectors from the image information after Lab space conversion, and then extracts high-level semantic information from the latent feature vectors. The high-level semantic information of the latent feature vectors in the image to be detected is used as the basis for classification calculation to achieve classification detection.
[0083] In this embodiment, the classification loss encourages the model to distinguish between images of different categories. The contrast loss keeps similar images as close as possible in the representation space, while images of different categories are kept as far apart as possible. The defect classification loss tries to distinguish the distance between defective and normal images. In defect detection, the similarity between the test sample and the normal prototype is calculated, and defects are identified when the similarity falls below a threshold.
[0084] This embodiment provides an image classification and defect detection method based on self-supervised contrastive learning, which mainly optimizes parameters of three modules: 1) the first encoder and the second encoder; 2) the first semantic feature encoder and the second semantic feature encoder; 3) the classifier network.
[0085] The optimization of the first and second encoders includes:
[0086] The first encoder uses a Transformer-based autoencoder, employs deformable attention on the feature map, dynamically focuses on key areas, and uses the Transformer encoding mechanism to generate latent features. In a specific embodiment, the first encoder uses deformable attention to extract latent features in the specific application of image classification detection.
[0087] In a specific embodiment, minimizing the defect classification loss function and the cluster classification loss function is used as the optimization goal, and the parameters of the Transformer-based autoencoder are optimized.
[0088] The preprocessed input feature x o ∈R s×s×b , divided into N P×P blocks, we get Each block is then mapped to a D-dimensional vector through linear projection and position encoding is added: Each query vector Z r t initial reference points p t ∈[0, 1] 2 (normalized coordinates), and use Zr to represent the query vector at the query position r. The offset Δp of each reference point is predicted by the multi-layer perceptron network MLP. t , that is, Δp t =MLP(Z r ). According to the reference point Δp t , bilinearly interpolate the sampled feature value v from the input featuret , predict the attention weight a of each sampling point t , and perform weighted summation: The feature output by the Transformer encoder is Z = E(x), and the first potential vector is obtained
[0089] To reconstruct the data from the first latent vector Z Deformable attention is also used in the Transformer-based decoder to accurately reconstruct local details.
[0090] Dynamically align the encoded features through deformable attention, copy Z several times to make the copied features consistent with the target sequence length, and add position encoding: Use a multilayer perceptron network to predict the offset Δp of each reference point t =MLP(q r ), decoder query q r Predict the offset Δp of t reference points t ∈[0, 1] 2 According to the reference point Δp t , sampled encoder features v t , weighted sum encoding features, update query vector The decoded sequence Q t Mapping back to image block space Reshape the block sequence into a complete feature image
[0091] The second encoder uses CNN convolutional autoencoder. CNN convolutional autoencoder consists of encoder and decoder. The convolutional autoencoder model uses continuous latent space to reconstruct the data as close as possible to the input data in a probabilistic sense. Given an input vector x o , identification model q φ (z|x o ) is used as a neural network encoder to generate a second latent vector z. The decoder converts the second latent vector z into a likelihood density p θ (x o |z) to generate samples. Minimizing the total loss of the convolutional autoencoder is equivalent to maximizing the variational lower bound (ELBO):
[0092]
[0093] The first term on the right side of Equation 6 represents the reconstruction loss, expressed as q α (z|x o )(Gaussian distribution) generates the latent feature z, By p β (x o|z)(conditional distribution) generation, where α represents the parameters in the encoder network and β represents the parameters in the decoder network. The second term represents the KL divergence, ensuring that the learned output latent variable q(z|x o ) is close to the prior distribution p(z), where μ is the mean of the variational distribution, σ 2 is the variance of the variational distribution, represents a Gaussian distribution, The mean is 0 and the variance is I.
[0094] As an optional implementation, the mean square error loss function is used to optimize the training of the Transformer-based deformable autoencoder: The parameters of the autoencoder based on convolutional neural network are optimized by using the gradient descent method combining reconstruction loss and KL divergence.
[0095] CNN autoencoders, consisting of an encoder and a decoder, are paired with a variant autoencoder, using the latent features (i.e., CNN features) as sample pairs for comparative learning.
[0096] The optimization of the first semantic feature encoder and the second semantic feature encoder includes:
[0097] S1, the training image is converted into information x after LAB space transformation u .
[0098] S2, the information x u Input the Transformer-based deformable autoencoder to get the first feature x uq .
[0099] S3, the information x u Input the CNN-based autoencoder to get the second feature x uk .
[0100] S4, when uq=uk, that is, when the first feature and the second feature come from the same information input, the first feature x uq and the second feature as a positive sample pair.
[0101] When uq≠uk, that is, the first feature and the second feature come from different information inputs, the second feature As the first feature x uk Among them, 1≤uq;uk≤M, M is the number of negative samples.
[0102] S5, using prototype contrast learning, with the first semantic feature encoder v q =f q (x q) and the second semantic feature encoder v k =f k (x k ) extracts high-level semantic information of input features. q and v k+ is a positive sample pair x q and x k+ The encoded features, For all negative samples Encoded features.
[0103] S6 is optimized by the improved prototype contrast learning loss function, the formula is:
[0104]
[0105] Among them, δ represents the concentration of prototype feature distribution. represents the feature representation of v and prototype c in the same cluster. Z represents the number of feature points. ω is a hyperparameter. In order to estimate the probability of outputting the prototype more stably, the sample is clustered N times. H is the number of prototypes. By reducing L p To optimize the encoder parameters, the enhancement module of self-supervised contrastive learning increases the distance between prototypes, allowing the model to learn more advanced semantic information. The model calculates features and each prototype c s The distance, which belongs to category c, is based on the probability distribution of v q With prototype c k The Softmax function of the negative distance, that is, v q with c k The closer the distance is, the greater the probability that it belongs to category c.
[0106] In a specific embodiment, the Adam optimizer is used to combine contrastive learning loss, classification loss and defect loss functions to implement parameter updates of the semantic feature encoder network through the back propagation mechanism. k Update using momentum update method, that is: fk←lf k +(1-l)f q , l∈(0,1) is the momentum update coefficient.
[0107] High-level semantic information is extracted through the prototype contrastive learning network, and the gradient loss is calculated using the contrastive learning loss function.
[0108] Optimization of the classifier network includes:
[0109] The quality classifier is connected to the f consisting of fully connected layers. q The output of the encoder, the quality level classification head uses the cross entropy loss function to calculate the classification loss:
[0110]
[0111] Among them, Q is the representation set of the image to be detected; Y represents the set of different categories; q i,j represents the i-th image q to be detected, which is predicted to be of category j; θ represents the true label of the sample, and θ = 1 when the classification of the image to be detected is correct; p is the predicted probability.
[0112] The parameter optimization process of the classifier includes:
[0113] Calculate the similarity of normal quality level sample pairs and defective sample pairs respectively, and at the same time increase the distance between normal quality level sample pairs and defective sample pairs; calculate the centroid representation of normal quality level samples and defective samples:
[0114]
[0115] Where m is the category of normal quality level, n is the category of defective quality level c m is the centroid of the normal sample, c n is the centroid representation of the defect category feature; f(x i ) represents the feature extractor; S m represents the normal quality level category label set, S n Represents a set of defect quality grade category labels;
[0116] The cosine distance is used to measure the similarity of sample pairs:
[0117]
[0118] Among them, v q is the feature representation of the image to be detected, s(·) is the similarity measurement function;
[0119] Compute defect classes using negative log-probability loss:
[0120]
[0121] The total loss function to be optimized is the weighted sum of defect classification loss, quality grade classification loss and contrast loss:
[0122]
[0123] Among them, α and β are hyperparameters that adjust the relative weight between the classification loss and the defect classification loss.
[0124] Parameter optimization is achieved by minimizing the total loss function to be optimized.
[0125] The classifier network uses a cross-entropy loss function to optimize parameters to improve the accuracy of quality grade classification. A negative log-probability loss function is used to minimize the negative log-probability, which encourages the model to output high-confidence defect category predictions. Momentum updates are used to update the parameters of the momentum encoder.
[0126] The following is a method for verifying the accuracy of the image classification and defect detection method based on self-supervised contrastive learning provided in this embodiment:
[0127] The accuracy of image quality classification and defect detection is a multi-classification problem, which can be expressed by the formula of the sum of all positive examples:
[0128]
[0129] The indicator Accuracy (ACC) represents the ratio of correctly classified samples to the total number of samples. It is calculated as follows: By dividing the number of correctly classified cases by the total number of occurrences in the test set and multiplying the result by 100, we can calculate the accuracy. This calculation is expressed as follows:
[0130]
[0131] Among them, TP is the number of samples correctly predicted by the model as positive (actually positive, predicted as positive), TN is the number of samples correctly predicted by the model as negative (actually negative, predicted as negative), FP is the number of samples incorrectly predicted as positive (actually negative, but predicted as positive), and FN is the number of samples incorrectly predicted as negative (actually positive, but predicted as negative).
[0132] The training network model is deployed in the visual inspection system. After the visual inspection system obtains the rust removal image, it sets a reasonable model detection error and threshold, and obtains the defect results and category classification results through reasoning operations.
[0133] This embodiment provides an image classification and defect detection method based on self-supervised contrastive learning, which is applied to defect detection on rust removal surfaces of ship wall-climbing robots. It includes the following parts:
[0134] 1) Image preprocessing module: Gaussian filtering and LAB conversion are used to generate LAB space conversion information.
[0135] 2) An enhanced module for self-supervised contrastive learning, which trains Transformer-based autoencoders and CNN-based autoencoders to generate positive and negative samples for contrastive learning.
[0136] 3) A prototype contrastive learning network extracts high-level semantic information, uses a contrastive learning loss function to calculate gradient loss, and employs momentum updates to update the momentum encoder parameters. The classifier network optimizes parameters using a cross-entropy loss function to improve the accuracy of quality grade classification. A negative logarithmic probability loss function is employed to minimize the negative logarithmic probability, encouraging the model to output high-confidence defect category predictions.
[0137] 4) Run the inference operation in the classifier network, set the appropriate image error threshold, and obtain the final detection result.
[0138] This embodiment proposes an image classification and defect detection method based on self-supervised contrastive learning for real-time surface quality classification and defect identification in a visual inspection system for a ship paint removal robot. This image classification algorithm not only improves detection speed and stability, but also finds application in the visual inspection and classification of high-pressure water paint removal robots. This meets the demand for intelligent shipbuilding, reduces worker workload, and improves inspection efficiency. It also has important theoretical and practical implications for improving the automated rust removal and intelligent inspection technology system for wall-climbing robots.
[0139] Although the embodiments of the present invention have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A method for image classification and defect detection based on self-supervised contrastive learning, characterized in that: include: Convert the image to be detected to the LAB color space, and generate the feature representation information of principal component analysis based on the information of the separated A channel, B channel and L channel; Extracting a target latent feature vector from the feature representation information using a first encoder; extracting high-level semantic information from the target latent feature vector using a first semantic feature encoder; Classify and detect the high-level semantic information through a classifier network; The construction of the first encoder and the first semantic feature encoder includes: Inputting the training sample set into the first encoder and the second encoder respectively to obtain a first training data set for inputting the first semantic feature encoder and a second training data set for inputting the second semantic feature encoder; Parameters of the first semantic feature encoder and the second semantic feature encoder are optimized by contrastive learning.
2. The image classification and defect detection method based on self-supervised contrastive learning according to claim 1, characterized in that: The first encoder is a deformable autoencoder based on Transformer; the second encoder is an autoencoder based on convolutional neural network.
3. The image classification and defect detection method based on self-supervised contrastive learning according to claim 2, characterized in that: Before inputting the first training data set and the second training data set into the first semantic feature encoder and the second semantic feature encoder respectively, the method further includes: The mean square error loss function is used to optimize the parameters of the Transformer-based deformable autoencoder; The parameters of the autoencoder based on convolutional neural network are optimized by using the gradient descent method combining reconstruction loss and KL divergence.
4. The image classification and defect detection method based on self-supervised contrastive learning according to claim 1, characterized in that: Convert the image to be detected into a LAB color space image, including: Using a large kernel blur to extract the illumination component of the image to be detected, and then using a Gaussian kernel weighted average to obtain an intermediate image; Converting the intermediate image into LAB color space through nonlinear mapping, and enhancing feature representation using a spatial weight function; The information of the A channel, the B channel and the L channel is separated based on the LAB color space information represented by the enhanced features.
5. The image classification and defect detection method based on self-supervised contrastive learning according to claim 2, characterized in that: The construction of the first encoder and the first semantic feature encoder further includes: Dynamically focusing on a key area of the input training sample set using deformable attention, and generating the first latent feature vector using a Transformer encoding mechanism; The decoder of the deformable autoencoder dynamically decodes the first latent feature vector through deformable attention to achieve fine and accurate reconstruction of local details, thereby obtaining the first training data set.
6. The image classification and defect detection method based on self-supervised contrastive learning according to claim 5, characterized in that: Also includes: The autoencoder based on the convolutional neural network generates a second potential feature vector according to the input training sample set; The autoencoder based on the convolutional neural network generates the second training data set according to the preset likelihood density of the second potential feature vector.
7. The image classification and defect detection method based on self-supervised contrastive learning according to claim 6, characterized in that: Optimizing parameters of the first semantic feature encoder and the second semantic feature encoder by using a contrastive learning method includes: Input the training data into the Transformer-based deformable autoencoder to obtain the first feature; Inputting the training data into a CNN-based autoencoder to obtain a second feature; The first feature and the second feature obtained based on the same training data are used as a positive sample pair, and the second feature obtained based on different training data is used as a negative sample of the first feature; Using the first semantic feature encoder v q =f q (x q ) and the second semantic feature encoder v k =f k (x k ) respectively extract the high-level semantic information in the potential feature vector of the training data; wherein, v q and v k+ is a positive sample pair x q and x k+ The encoded feature, v k- For all negative samples x k- Encoded features; The optimization is performed through the improved prototype contrast learning loss function, the formula is: Among them, δ represents the concentration of prototype feature distribution; represents the feature representation of v and prototype c in the same cluster; Z represents the number of feature points; ω is a hyperparameter; H is the number of prototypes; by reducing L p For the first semantic feature encoder f q The parameters of the second semantic feature encoder f k The parameters of are optimized so that the enhancement module of the self-supervised contrastive learning increases the distance between prototypes.
8. The image classification and defect detection method based on self-supervised contrastive learning according to claim 1, characterized in that: The optimization process of the classifier network includes: The quality level classification head is connected to the output of the first semantic feature encoder composed of a fully connected layer. The quality level classification head calculates the classification loss using the loss function: Among them, Q is the representation set of the image to be detected; Y represents the set of different categories; q i,j Represents the image to be detected q i is predicted to be category j; θ is an indicator function, θ=1 when the classification of the image to be detected is correct; p is the predicted probability; The similarities of the normal quality level sample pair and the defective sample pair are calculated respectively, and the distance between the normal quality level sample pair and the defective sample pair is enlarged; the centroid representation of the normal quality level sample and the defective sample is calculated: Where m is the category of normal quality level, n is the category of defective quality level c m is the centroid of the normal sample, c n is the centroid representation of the defect category feature; f(x i ) represents the feature extractor; S m represents the normal quality level category label set, S n Represents a set of defect quality grade category labels; The cosine distance is used to measure the similarity of sample pairs: Among them, v q is the feature representation of the image to be detected, s(·) is the similarity measurement function; Compute defect classes using negative log-probability loss: The total loss function to be optimized is the weighted sum of defect classification loss, quality grade classification loss and contrast loss: Among them, α and β are hyperparameters that adjust the relative weight between classification loss and defect classification loss; The parameters of the classifier network are optimized by minimizing the total loss function to be optimized.
Citation Information
Cited By
SMT element defect real-time detection and classification identification method based on machine vision
CN121789224A