A Semi-Supervised Anomaly Detection Model Training Method
Through the semi-supervised anomaly detection model training method, using the Encoder-Decoder module, VAE-GAN encoder and pseudo labeler, the problems of data labeling difficulty and sample imbalance in industrial anomaly detection are solved, the detection efficiency and accuracy of the model are improved, and the labeling cost is reduced.
Patent Information
- Application Number
- CN202411969128.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2044-12-30
AI Technical Summary
In the existing technology, the training process of industrial anomaly detection models faces problems such as data labeling difficulties, sample imbalance, and high risk of overfitting, resulting in insufficient detection efficiency and accuracy.
A semi-supervised anomaly detection model training method is adopted. By obtaining and labeling abnormal and normal product image samples, training and validation sets containing both are constructed. Multi-module collaborative training is performed using the Encoder-Decoder module, VAE-GAN encoder and pseudo-labeler. The learning rate and loss function are adjusted to generate pseudo labels to optimize model performance.
It effectively overcomes the negative impact of sample imbalance, improves the model's ability to identify abnormal samples, reduces the risk of overfitting, improves detection accuracy and generalization ability, and reduces the need for large-scale labeled data.
Smart Images

Figure CN119832363B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of detection model training, and in particular to a semi-supervised anomaly detection model training method. Background Art
[0002] With the rapid development of industrial automation technology, traditional manual inspection methods are no longer able to meet the high standards of modern production. Industrial anomaly detection, a key step in ensuring product quality and production safety, leverages automation technology to identify abnormal product or equipment conditions during the production process. Deep learning-based automatic defect detection technology identifies anomalies by analyzing product images, offering significant advantages in improving detection efficiency and accuracy.
[0003] However, acquiring large amounts of labeled data in industrial scenarios is costly. Not only does it require professionals to expend considerable time and effort to annotate abnormal regions and categories in images, but the accuracy and consistency of the annotations are also difficult to guarantee. A small number of labeled samples makes it difficult for the model to fully learn complex anomaly features, while large-scale annotations face cost bottlenecks. Secondly, the problem of sample imbalance in model training is serious. In actual production, the number of normal product samples often far exceeds that of abnormal samples. This unbalanced data distribution can easily lead to a biased learning of normal sample features during training, resulting in weaker recognition of abnormal samples. Furthermore, the risk of overfitting during training is high. Due to the complexity and diversity of industrial image data, if the model structure is not properly designed or the training parameters are inappropriately selected, the model can easily overfit the training set, resulting in poor performance and generalization when detecting new samples. Summary of the Invention
[0004] In view of the above analysis, an embodiment of the present invention aims to provide a semi-supervised anomaly detection model training method to solve the problems of data labeling difficulty, sample imbalance and high overfitting risk in existing training.
[0005] A semi-supervised anomaly detection model training method provided by an embodiment of the present invention includes:
[0006] Acquire an abnormal product image and mark abnormal areas in the abnormal product image to obtain abnormal samples, wherein the abnormal samples include the abnormal product image and its corresponding label, and the label corresponding to the abnormal product image includes the abnormal area and classification information of the abnormal product image;
[0007] Acquire a normal product image and label the normal product image to obtain a normal sample, wherein the normal sample includes a normal product image and a corresponding label, and the label corresponding to the normal product image includes classification information;
[0008] Constructing a training set and a validation set based on normal samples and abnormal samples; the training set and the validation set both include abnormal samples and normal samples;
[0009] Construct a semi-supervised anomaly detection model and initialize the semi-supervised anomaly detection model; input the training set into the initialized semi-supervised anomaly detection model for model training, update the model parameters, and evaluate the model performance through the validation set until the model performance meets the predetermined standards. Stop training and obtain a trained semi-supervised anomaly detection model.
[0010] As a further improvement of the present application, the step of inputting the training set into the initialized semi-supervised anomaly detection model for model training includes multiple epochs, wherein in each epoch, the training set is divided into multiple batches, each batch includes random normal samples and abnormal samples, and the multiple batches are input into the initialized semi-supervised anomaly detection model for model training;
[0011] After processing all batches in an epoch, the model performance is evaluated using the validation set. If the model performance does not meet the predetermined criteria, training continues with the next epoch.
[0012] If the model performance meets the predetermined criteria, the training is stopped and the model parameters are saved.
[0013] As a further improvement of the present application, the semi-supervised anomaly detection model includes an input module, an Encoder-Decoder module and a VAE-GAN encoder;
[0014] Each batch is input into the initialized semi-supervised anomaly detection model for model training, including:
[0015] The normal samples and abnormal samples in the batch are input to the input module of the semi-supervised anomaly detection model. The input module outputs the normal samples to the Encoder-Decoder module and the abnormal samples to the VAE-GAN encoder.
[0016] The Encoder-Decoder module extracts features from the image data of normal samples, generates image reconstruction data based on the extracted features, and outputs the extracted features to the pseudo labeler.
[0017] The VAE-GAN encoder extracts features from the image data of abnormal samples and generates potential abnormal information and abnormal reconstruction data;
[0018] The pseudo-labeler generates pseudo-labels based on the features extracted by the Encoder-Decoder module;
[0019] A loss function is constructed based on image reconstruction data, potential abnormality information, and abnormal reconstruction data, and the model parameters are updated through backpropagation. After each batch training is completed, the learning rate is adjusted according to the training progress.
[0020] As a further improvement of the present application, the semi-supervised anomaly detection model further includes a memory module and an anomaly detection module;
[0021] A memory module, used to store historical abnormal images and their corresponding abnormality detection results;
[0022] The anomaly detection module obtains an anomaly detection result of the product to be detected based on the image data of the product to be detected, the image reconstruction data, potential anomaly information, anomaly reconstruction data, pseudo labels, historical anomaly image data stored in the memory module and its corresponding anomaly detection results, and transmits the anomaly detection result to the memory module.
[0023] As a further improvement of the present application, the Encoder-Decoder module includes an Encoder unit and a Decoder unit;
[0024] The encoder unit includes the first convolutional layer, the first pooling layer, the second convolutional layer, and the second pooling layer connected end to end;
[0025] The first convolutional layer extracts features of the image data, and the first pooling layer performs a pooling operation on the features extracted by the first convolutional layer. The second convolutional layer performs a convolution operation on the output of the first pooling layer to extract features of the image data. The second pooling layer performs dimensionality reduction processing on the output of the second convolutional layer to obtain the final features of the image data. The output of the second pooling layer serves as the output of the encoder unit and is connected to the input of the decoder unit and the pseudo labeler.
[0026] The decoder unit consists of a transposed convolution layer, an upsampling layer, and a decoder convolution layer connected end to end.
[0027] The transposed convolution layer receives the output of the second pooling layer and performs a transposed convolution operation on the final features of the image data; the upsampling layer upsamples the output of the transposed convolution layer to increase the dimension of the feature space; the decoder convolution layer performs a convolution operation on the output of the upsampling layer to generate image reconstruction data. The output of the decoder convolution layer serves as the output of the decoder unit and is connected to the input of the anomaly detection module.
[0028] As a further improvement of the present application, the VAE-GAN encoder includes an encoder and a decoder connected end to end, the encoder is used to generate potential abnormality information based on the image data; the decoder is used to generate reconstructed image data based on the potential abnormality information;
[0029] The encoder includes a first convolutional layer, a first activation function layer, a first pooling layer, a second convolutional layer, a second activation function layer, a second pooling layer, a Flatten layer, a first fully connected layer, a third activation function layer, and a second fully connected layer, which are connected end to end in sequence;
[0030] Among them, the first convolution layer extracts the features of the image data, the first activation function layer performs nonlinear processing on the output of the first convolution layer; the first pooling layer performs a pooling operation on the output of the first encoder activation function layer to reduce the feature dimension after nonlinear processing; the second convolution layer performs a convolution operation on the output of the first pooling layer to extract the features of the image data; the second activation function layer performs nonlinear processing on the output of the second convolution layer; the second pooling layer performs a pooling operation on the output of the second activation function layer; the Flatten layer converts the output of the second pooling layer into a one-dimensional feature vector; the first fully connected layer performs feature compression on the one-dimensional feature vector; the third activation function layer performs nonlinear processing on the output of the first fully connected layer; the second fully connected layer performs feature mapping on the output of the third activation function layer to generate potential abnormal information of the image data;
[0031] The decoder includes a first transposed convolution layer, a first activation function layer, an upsampling layer, a second transposed convolution layer, a second activation function layer, and a decoder convolution layer connected end to end in sequence;
[0032] Among them, the first transposed convolution layer performs a transposed convolution operation on the potential abnormal information received from the encoder; the first activation function layer performs nonlinear processing on the output of the first transposed convolution layer; the upsampling layer upsamples the output of the first activation function layer; the second transposed convolution layer performs a transposed convolution operation on the output of the upsampling layer; the second activation function layer performs nonlinear processing on the output of the second transposed convolution layer; the decoder convolution layer performs a convolution operation on the output of the second activation function layer to obtain reconstructed image data.
[0033] As a further improvement of the present application, the pseudo labeler includes an input layer, a fully connected layer, an activation function layer, and an output layer connected end to end in sequence;
[0034] The input layer receives the final features of the image data output by the Encoder unit and transmits them to the fully connected layer;
[0035] The fully connected layer performs spatial mapping on the final features of the image data to generate the number of feature categories;
[0036] An activation function layer generates a distribution probability of each feature category based on the number of feature categories through a Softmax function;
[0037] The output layer generates anomaly labels based on the distribution probability of each feature category and transmits them to the anomaly detection module.
[0038] As a further improvement of the present application, the loss function is shown in formula (1);
[0039] L total =ω1.L recon +ω2.L anomaly +ω3.L latent +ω4.L pseudo (1);
[0040] Among them, L total is the total loss function; L recon is the loss function of the Encoder-Decoder module; L anomaly is the loss function of the VAE-GAN encoder; L latent is the regularization loss of potential abnormal information; L pseudo is the loss function of the pseudo labeler.
[0041] As a further improvement of the present application, the loss function of the Encoder-Decoder module is shown in formula (2);
[0042]
[0043] Where n is the number of samples, y i is the image data of the i-th sample, is the reconstructed data of the i-th sample;
[0044] The loss function of the VAE-GAN encoder is calculated as shown in formula (3);
[0045]
[0046] Where n is the number of samples, a i is the image data of the i-th sample, Reconstruct the data for the anomaly of the i-th sample;
[0047] The regularization loss of potential abnormal information is calculated as shown in formula (4);
[0048] L latent =D KL (q(z|xi)||p(z)) (4)
[0049] Among them, D KL is the KL divergence, q(z|xi) is the potential abnormal information, and p(z) is the prior distribution of abnormal information.
[0050] As a further improvement of this application, the pseudo labeler loss function is shown in formula (5);
[0051]
[0052] Where n is the number of samples, y ic is the encoding of the label of the i-th sample, is the pseudo label encoding of the i-th sample.
[0053] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects:
[0054] 1. By constructing training and validation sets based on both normal and abnormal samples, the model is fully exposed to different types of samples during training, avoiding learning bias caused by large differences in sample size. In each epoch, the training set is divided into multiple batches, and each batch randomly contains normal and abnormal samples. This helps the model better capture the characteristic differences between normal and abnormal samples, improves the ability to identify abnormal samples, and effectively overcomes the negative impact of sample imbalance.
[0055] 2. The present invention uses multi-module collaborative training, including the Encoder-Decoder module and the VAE-GAN encoder, to learn sample features from multiple perspectives, avoiding the model's over-reliance on a certain type of sample features or local features, and enhancing the model's ability to learn and integrate different features. During the training process, the model performance is evaluated through a validation set, the training strategy is adjusted according to the model performance, and the learning rate is adjusted according to the training progress after each batch training. This further optimizes the model training process, effectively reduces the risk of overfitting, and improves the model's generalization ability, enabling it to accurately identify various new abnormal situations in actual detection.
[0056] 3. A pseudo-labeler is used to generate pseudo-labels based on a small amount of labeled data. When calculating the pseudo-label deviation, the relationship between the pseudo-label and other features is fully considered, so that the model can more accurately utilize the information in the unlabeled data, effectively improving the accuracy of semi-supervised anomaly detection, reducing the demand for large-scale labeled data, reducing the cost of data labeling, and improving the practicality and scalability of the detection method.
[0057] In the present invention, the above-mentioned technical solutions can be combined with each other to achieve more preferred combinations. Other features and advantages of the present invention will be described in the following description, and some advantages will become apparent from the description or be learned through practice of the present invention. The objectives and other advantages of the present invention can be realized and obtained through the contents particularly pointed out in the description and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] The accompanying drawings are only used for the purpose of illustrating specific embodiments and are not to be considered as limiting the present invention. Throughout the drawings, the same reference symbols denote the same components.
[0059] Figure 1 A flowchart of a semi-supervised anomaly detection model training method provided by one embodiment of the present invention;
[0060] Figure 2 A schematic diagram of the structure of a semi-supervised anomaly detection model is provided for one embodiment of the present invention. DETAILED DESCRIPTION
[0061] The preferred embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, and are not used to limit the scope of the present invention.
[0062] A specific embodiment of the present invention discloses a semi-supervised anomaly detection model training method, such as Figure 1 As shown, a semi-supervised anomaly detection model training method includes:
[0063] Step 101: Acquire an abnormal product image and mark the abnormal area in the abnormal product image to obtain an abnormal sample. The abnormal sample includes the abnormal product image and its corresponding label. The label corresponding to the abnormal product image includes the abnormal area and classification information of the abnormal product image.
[0064] Product images are captured using an image acquisition device. Abnormal product images are identified through manual screening or other means. Abnormal regions in these images are labeled to create abnormal samples. Labeling can be done using the image annotation tool Labelme. Abnormal samples include abnormal product images and their corresponding labels. The labels include the abnormal regions and classification information.
[0065] Specifically, during annotation, a box is used to outline the abnormal location in the image and label the category of the abnormality. For example, the coordinates of the box can be expressed in pixel coordinates, with the coordinates of the upper left and lower right pixel points defining the extent of the box. The categories include shape deformation, surface scratches and pits, color deviation, and component missing.
[0066] Step 102 : Acquire a normal product image and label the normal product image to obtain a normal sample. The normal sample includes a normal product image and a corresponding label. The label corresponding to the normal product image includes classification information.
[0067] For normal samples, since there are no anomalies in the image, only the category information needs to be labeled. The category information is normal, which is different from the anomaly category labeled in the abnormal sample. After labeling, the normal product image and its corresponding label are regarded as normal samples.
[0068] Step 103: construct a training set and a verification set based on the normal samples and the abnormal samples; the training set and the verification set both include abnormal samples and normal samples.
[0069] The obtained normal and abnormal samples are divided into a certain ratio to form a training set. During the division process, it is necessary to ensure that both the training set and the validation set contain both normal and abnormal samples, and the distribution is as even as possible. Random sampling can be used to randomly select a certain number of normal and abnormal samples from all samples to form the training set, and the remaining samples to form the validation set.
[0070] Step 104 constructs and initializes a semi-supervised anomaly detection model. The training set is then fed into the initialized model for training. Model parameters are updated, and model performance is evaluated using the validation set. Training is terminated until the model performance meets predetermined criteria, resulting in a trained semi-supervised anomaly detection model. During training, the training set is fed into the initialized model for training. The training process consists of multiple epochs. In each epoch, the training set is divided into multiple batches, each containing random normal and abnormal samples. These batches are then fed into the model for training.
[0071] Initialization refers to the initial settings of the semi-supervised anomaly detection model before training begins. This includes setting initial values for the model's weights and biases to avoid initial bias, setting the initial learning rate, setting regularization terms to prevent overfitting, determining the number of neurons in the model, and setting model hyperparameters, including the number of epochs and batch size.
[0072] Specifically, the training set is input into the initialized semi-supervised anomaly detection model for model training, which includes multiple epochs. In each epoch, the training set is divided into multiple batches, each batch includes random normal samples and abnormal samples, and multiple batches are input into the initialized semi-supervised anomaly detection model for model training.
[0073] During model training, hyperparameters include the number of epochs, batch size, and learning rate. The specific number of epochs can be determined through experience and experimentation and can be adjusted based on the model's performance on the validation set. If the model converges slowly during training, the number of epochs can be increased. If signs of overfitting appear, training may need to be terminated early. The batch size, which refers to the number of samples in each batch, needs to be adjusted based on the training objectives and model performance requirements. The number of samples in each batch affects the training efficiency and stability of the model. Smaller batches allow the model to approach the global optimal solution more closely with each update, but may result in greater training fluctuations and slower convergence. Larger batches accelerate convergence but may lead to local optima and require higher memory. The learning rate determines the step size used in each parameter update. A larger learning rate accelerates model training but may cause the model to miss the optimal solution. A smaller learning rate allows the model to more accurately approach the optimal solution, but the training process will be very slow. During training, a learning rate decay strategy is often used to gradually reduce the learning rate as training progresses.
[0074] At the beginning of each epoch, the training set is divided into multiple batches according to the set batch size. The samples in each batch are sequentially input into the initialized semi-supervised anomaly detection model. After processing all batches in an epoch, the model performance is evaluated using the validation set. If the model performance does not meet the predetermined criteria, training continues with the next epoch. If the model performance does meet the predetermined criteria, training stops and the model parameters are saved. The calculated performance indicators are compared with the predetermined criteria. If the model performance does not meet the predetermined criteria, training continues with the next epoch. If the model performance meets the predetermined criteria, training stops and the current model parameters are saved. The model corresponding to these parameters is the trained semi-supervised anomaly detection model and can be used for subsequent anomaly detection tasks.
[0075] Furthermore, the semi-supervised anomaly detection model includes an input module, an Encoder-Decoder module, a VAE-GAN encoder, and a pseudo labeler;
[0076] Each batch is input into the initialized semi-supervised anomaly detection model for model training, including:
[0077] The normal samples and abnormal samples in the batch are input to the input module of the semi-supervised anomaly detection model. The input module outputs the normal samples to the Encoder-Decoder module and the abnormal samples to the VAE-GAN encoder.
[0078] The Encoder-Decoder module extracts features from the image data of normal samples, generates image reconstruction data based on the extracted features, and outputs the extracted features to the pseudo labeler.
[0079] The VAE-GAN encoder extracts features from the image data of abnormal samples and generates potential abnormal information and abnormal reconstruction data;
[0080] The pseudo-labeler generates pseudo-labels based on the features extracted by the Encoder-Decoder module;
[0081] A loss function is constructed based on image reconstruction data, potential anomaly information, and abnormal reconstruction data, and the model parameters are updated through backpropagation. After each batch training, the learning rate is adjusted according to the training progress. The loss function is shown in formula (1).
[0082] L total =ω1.L recon +ω2.L anomaly +ω3.L latent +ω4.L pseudo (1);
[0083] Among them, L total is the total loss function; L recon is the loss function of the Encoder-Decoder module; L anomaly is the loss function of the VAE-GAN encoder; L latent is the regularization loss of potential abnormal information; L pseudo is the loss function of the pseudo labeler.
[0084] The loss function of the Encoder-Decoder module is shown in formula (2);
[0085]
[0086] Where n is the number of samples, y i is the image data of the i-th sample, is the reconstructed data of the i-th sample;
[0087] The loss function of the VAE-GAN encoder is calculated as shown in formula (3);
[0088]
[0089] Where n is the number of samples, a i is the image data of the i-th sample, Reconstruct the data for the anomaly of the i-th sample;
[0090] The regularization loss of potential abnormal information is calculated as shown in formula (4);
[0091] L latent =D KL (q(z|xi)||p(z)) (4)
[0092] Among them, D KL is the KL divergence, q(z|xi) is the potential abnormal information, and p(z) is the prior distribution of abnormal information.
[0093] The pseudo labeler loss function is shown in formula (5);
[0094]
[0095] Where n is the number of samples, y ic is the encoding of the label of the i-th sample, is the pseudo label encoding of the i-th sample.
[0096] More specifically, the input module serves as the input to the semi-supervised anomaly detection model and receives image data of the product to be inspected. This image data refers to a two-dimensional or three-dimensional image containing information about the product's appearance and structure. It can be grayscale, color, or other image data formats. The input module sends the received image data to the encoder-decoder module, the VAE-GAN encoder, the anomaly detection module, and the memory module.
[0097] The Encoder-Decoder module extracts features from the image data of the product to be inspected and sends them to the pseudo-labeler. It also generates image reconstruction data based on the extracted features and sends this data to the anomaly detection module. The extracted features include features that represent image information, such as edges, texture, and shape. Generating image reconstruction data involves restoring the extracted features to an image. Through a combination of transposed convolution layers, upsampling layers, and convolution layers, the low-dimensional features are gradually restored to a spatial size similar to the original image. This allows the difference between the original and reconstructed images to be determined, thereby detecting anomalies.
[0098] Specifically, the Encoder-Decoder module includes an Encoder unit and a Decoder unit;
[0099] The encoder unit includes the first convolutional layer, the first pooling layer, the second convolutional layer, and the second pooling layer connected end to end;
[0100] The first convolutional layer extracts features of the image data, and the first pooling layer performs a pooling operation on the features extracted by the first convolutional layer. The second convolutional layer performs a convolution operation on the output of the first pooling layer to extract features of the image data. The second pooling layer performs dimensionality reduction processing on the output of the second convolutional layer to obtain the final features of the image data. The output of the second pooling layer serves as the output of the encoder unit and is connected to the input of the decoder unit and the pseudo labeler.
[0101] The decoder unit consists of a transposed convolution layer, an upsampling layer, and a decoder convolution layer connected end to end.
[0102] The transposed convolution layer receives the output of the second pooling layer and performs a transposed convolution operation on the final features of the image data; the upsampling layer upsamples the output of the transposed convolution layer to increase the dimension of the feature space; the decoder convolution layer performs a convolution operation on the output of the upsampling layer to generate image reconstruction data. The output of the decoder convolution layer serves as the output of the decoder unit and is connected to the input of the anomaly detection module.
[0103] A VAE-GAN encoder is used to generate potential anomaly information based on the image data of the product to be inspected, generate anomaly reconstruction data based on the potential anomaly information, and send the potential anomaly information and anomaly reconstruction data to the anomaly detection module.
[0104] Specifically, the VAE-GAN encoder consists of an encoder and a decoder connected end to end. The encoder is used to generate potential anomaly information based on image data, while the decoder is used to reconstruct image data based on the potential anomaly information. Potential anomaly information is a latent representation obtained by encoding the image data, which can contain abnormal features present in the image. The potential anomaly information needs to be restored to observable image information by the decoder. The abnormal reconstructed data is decoded by the decoder portion of the VAE-GAN encoder to generate an image. The decoded image will show significant differences in abnormal areas compared to the original image, and this difference can be used as a basis for anomaly detection.
[0105] Based on the potential anomaly information, anomaly reconstruction data is generated, which provides another angle for detecting anomalies. The potential anomaly information and anomaly reconstruction data are sent to the anomaly detection module.
[0106] The encoder includes a first convolutional layer, a first activation function layer, a first pooling layer, a second convolutional layer, a second activation function layer, a second pooling layer, a Flatten layer, a first fully connected layer, a third activation function layer, and a second fully connected layer, which are connected end to end in sequence; wherein, the first convolutional layer extracts features of image data, and the first activation function layer performs nonlinear processing on the output of the first convolutional layer; the first pooling layer performs a pooling operation on the output of the first encoder activation function layer to reduce the feature dimension after nonlinear processing; the second convolutional layer performs a convolution operation on the output of the first pooling layer to extract features of image data; the second activation function layer performs nonlinear processing on the output of the second convolutional layer; the second pooling layer performs a pooling operation on the output of the second activation function layer; the Flatten layer converts the output of the second pooling layer into a one-dimensional feature vector; the first fully connected layer performs feature compression on the one-dimensional feature vector; the third activation function layer performs nonlinear processing on the output of the first fully connected layer; the second fully connected layer performs feature mapping on the output of the third activation function layer to generate potential abnormal information of the image data.
[0107] The decoder includes a first transposed convolution layer, a first activation function layer, an upsampling layer, a second transposed convolution layer, a second activation function layer, and a decoder convolution layer connected end to end.
[0108] Among them, the first transposed convolution layer performs a transposed convolution operation on the potential abnormal information received from the encoder; the first activation function layer performs nonlinear processing on the output of the first transposed convolution layer; the upsampling layer upsamples the output of the first activation function layer; the second transposed convolution layer performs a transposed convolution operation on the output of the upsampling layer; the second activation function layer performs nonlinear processing on the output of the second transposed convolution layer; the decoder convolution layer performs a convolution operation on the output of the second activation function layer to obtain reconstructed image data.
[0109] The pseudo-labeler generates anomaly labels based on the features extracted by the Encoder-Decoder module and sends them to the anomaly detection module. Pseudo-labels are predicted labels obtained through processing in the input layer, fully connected layer, activation function layer, and output layer. They can provide additional supervision when annotated data is limited. For product images, the pseudo-labeler generates anomaly labels based on the distribution probability of each feature category.
[0110] Specifically, the pseudo labeler includes an input layer, a fully connected layer, an activation function layer, and an output layer that are connected end to end in sequence;
[0111] The input layer receives the final features of the image data output by the Encoder unit and transmits them to the fully connected layer;
[0112] The fully connected layer performs spatial mapping on the final features of the image data to generate the number of feature categories;
[0113] An activation function layer generates a distribution probability of each feature category based on the number of feature categories through a Softmax function;
[0114] The output layer generates anomaly labels based on the distribution probability of each feature category and transmits them to the anomaly detection module.
[0115] Furthermore, the semi-supervised anomaly detection model also includes a memory module and an anomaly detection module;
[0116] A memory module, used to store historical abnormal images and their corresponding abnormality detection results;
[0117] The anomaly detection module obtains an anomaly detection result of the product to be detected based on the image data of the product to be detected, the image reconstruction data, potential anomaly information, anomaly reconstruction data, pseudo labels, historical anomaly image data stored in the memory module and its corresponding anomaly detection results, and transmits the anomaly detection result to the memory module.
[0118] When retrieving the historical abnormal images with the highest similarity to the comprehensive deviation features in the memory module, the Euclidean distance or hash value can be used as a similarity metric. The abnormal classification unit maps the abnormal labels output by the pseudo labeler to specific abnormal categories.
[0119] The memory module is used to store historical abnormal image data and its corresponding abnormality detection results. The historical abnormal image data is the image data that has been detected and determined to have abnormalities. The corresponding abnormality detection results include abnormal areas and abnormality types.
[0120] The above-described embodiments of the present invention have the following beneficial effects: By constructing training and validation sets based on both normal and abnormal samples, the model is fully exposed to different types of samples during training, avoiding learning bias caused by large differences in sample size. The training set is divided into multiple batches in each epoch, and each batch randomly contains normal and abnormal samples. This helps the model better capture the feature differences between normal and abnormal samples, improves its ability to identify abnormal samples, and effectively overcomes the negative impact of sample imbalance. The present invention uses multi-module collaborative training, including an encoder-decoder module and a VAE-GAN encoder, to learn sample features from multiple perspectives, avoiding over-reliance on a particular type of sample feature or local features, and enhancing the model's ability to learn and integrate different features. During training, model performance is evaluated using a validation set, and the training strategy is adjusted based on model performance. After each batch of training, the learning rate is adjusted based on the training progress, further optimizing the model training process, effectively reducing the risk of overfitting, and improving the model's generalization ability, enabling it to accurately identify various emerging abnormalities in actual detection. By using a pseudo-labeler to generate pseudo-labels based on a small amount of labeled data, and fully considering the relationship between pseudo-labels and other features when calculating the pseudo-label deviation, the model can more accurately utilize the information in unlabeled data, effectively improving the accuracy of semi-supervised anomaly detection, reducing the demand for large-scale labeled data, reducing the cost of data labeling, and improving the practicality and scalability of the detection method.
[0121] Those skilled in the art will appreciate that all or part of the process steps of the above-described embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, such as a magnetic disk, an optical disk, a read-only memory, or a random access memory.
[0122] The above description is only a preferred specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with this technical field within the technical scope disclosed by the present invention should be covered by the scope of protection of the present invention.
Claims
1. A semi-supervised anomaly detection model training method, characterized in that: The method comprises: Acquire an abnormal product image and mark abnormal areas in the abnormal product image to obtain abnormal samples, wherein the abnormal samples include the abnormal product image and its corresponding label, and the label corresponding to the abnormal product image includes the abnormal area and classification information of the abnormal product image; Acquire a normal product image and annotate the normal product image to obtain a normal sample, wherein the normal sample includes a normal product image and a corresponding label, and the label corresponding to the normal product image includes classification information; Constructing a training set and a validation set based on normal samples and abnormal samples; the training set and the validation set both include abnormal samples and normal samples; Construct a semi-supervised anomaly detection model and initialize the semi-supervised anomaly detection model; input the training set into the initialized semi-supervised anomaly detection model for model training, update the model parameters, and evaluate the model performance through the validation set until the model performance meets the predetermined standards. Then, stop training and obtain a trained semi-supervised anomaly detection model; The inputting of the training set into the initialized semi-supervised anomaly detection model for model training includes multiple , in each In the training set, the training set is divided into multiple , each Both include random normal samples and abnormal samples, and multiple Input into the initialized semi-supervised anomaly detection model for model training; Complete one All After processing, the performance of the model is evaluated through the validation set. If the model performance does not meet the predetermined standards, the next step is continued. training; If the model performance meets the predetermined standards, the training is stopped and the model parameters are saved; The semi-supervised anomaly detection model includes an input module, Modules and encoder; Each Input into the initialized semi-supervised anomaly detection model for model training, including: Will The normal samples and abnormal samples in the input module are input to the semi-supervised anomaly detection model, and the input module outputs the normal samples to Module, outputs abnormal samples to encoder; The module extracts features from the image data of normal samples, generates image reconstruction data based on the extracted features, and outputs the extracted features to the pseudo labeler; The encoder extracts features from the image data of the abnormal sample and generates potential abnormality information and abnormal reconstruction data; Pseudo-labeler based on The features extracted by the module generate pseudo labels; Based on the image reconstruction data, potential abnormal information, and abnormal reconstruction data, the loss function is constructed and the model parameters are updated through back propagation. After training, adjust the learning rate according to the training progress.
2. The method according to claim 1, characterized in that The semi-supervised anomaly detection model also includes a memory module and an anomaly detection module; A memory module, used to store historical abnormal images and their corresponding abnormality detection results; The anomaly detection module obtains an anomaly detection result of the product to be detected based on the image data of the product to be detected, the image reconstruction data, potential anomaly information, anomaly reconstruction data, pseudo labels, historical anomaly image data stored in the memory module and its corresponding anomaly detection results, and transmits the anomaly detection result to the memory module.
3. The method according to claim 2, characterized in that described Modules include Unit and unit; The unit includes a first convolutional layer, a first pooling layer, a second convolutional layer, and a second pooling layer connected end to end; The first convolution layer extracts the features of the image data, and the first pooling layer performs a pooling operation on the features extracted by the first convolution layer; the second convolution layer performs a convolution operation on the output of the first pooling layer to extract the features of the image data; the second pooling layer performs a dimensionality reduction process on the output of the second convolution layer to obtain the final features of the image data, and the output of the second pooling layer is used as Output of the unit, connected Inputs to the unit and pseudo-labeler; The unit consists of a transposed convolution layer, an upsampling layer, and a Convolutional layers; The transposed convolution layer receives the output of the second pooling layer and performs a transposed convolution operation on the final features of the image data; the upsampling layer upsamples the output of the transposed convolution layer to increase the dimension of the feature space; The convolution layer performs convolution operation on the output of the upsampling layer to generate image reconstruction data. The output of the convolutional layer is The output of the unit is connected to the input of the anomaly detection module.
4. The method according to claim 1, wherein The encoder includes an encoder and a decoder connected end to end, the encoder is used to generate potential abnormality information based on the image data; a decoder for generating reconstructed image data based on potential anomaly information; The encoder includes a first convolution layer, a first activation function layer, a first pooling layer, a second convolution layer, a second activation function layer, a second pooling layer, layer, the first fully connected layer, the third activation function layer, and the second fully connected layer; Among them, the first convolution layer extracts the features of the image data, the first activation function layer performs nonlinear processing on the output of the first convolution layer; the first pooling layer performs a pooling operation on the output of the first encoder activation function layer to reduce the feature dimension after nonlinear processing; the second convolution layer performs a convolution operation on the output of the first pooling layer to extract the features of the image data; the second activation function layer performs nonlinear processing on the output of the second convolution layer; the second pooling layer performs a pooling operation on the output of the second activation function layer; The first fully connected layer performs feature compression on the one-dimensional feature vector; the third activation function layer performs nonlinear processing on the output of the first fully connected layer; the second fully connected layer performs feature mapping on the output of the third activation function layer to generate potential abnormal information of the image data; The decoder includes a first transposed convolution layer, a first activation function layer, an upsampling layer, a second transposed convolution layer, a second activation function layer, and a decoder convolution layer connected end to end in sequence; Among them, the first transposed convolution layer performs a transposed convolution operation on the potential abnormal information received from the encoder; the first activation function layer performs nonlinear processing on the output of the first transposed convolution layer; the upsampling layer upsamples the output of the first activation function layer; the second transposed convolution layer performs a transposed convolution operation on the output of the upsampling layer; the second activation function layer performs nonlinear processing on the output of the second transposed convolution layer; the decoder convolution layer performs a convolution operation on the output of the second activation function layer to obtain reconstructed image data.
5. The method according to claim 4, characterized in that The pseudo labeler includes an input layer, a fully connected layer, an activation function layer, and an output layer connected end to end in sequence; Input layer, receiving The final features of the image data output by the unit are transmitted to the fully connected layer; The fully connected layer performs spatial mapping on the final features of the image data to generate the number of feature categories; An activation function layer generates a distribution probability of each feature category based on the number of feature categories through a Softmax function; The output layer generates anomaly labels based on the distribution probability of each feature category and transmits them to the anomaly detection module.
6. The method according to claim 1, characterized in that The loss function is calculated as As shown; = . + . + . + . ; in, is the total loss function; for The loss function of the module; for The encoder's loss function; is the regularization loss of potential abnormal information; is the loss function of the pseudo labeler.
7. The method according to claim 6, characterized in that described The loss function of the module is calculated as As shown; ; Where n is the number of samples, is the image data of the i-th sample, is the reconstructed data of the i-th sample; described The loss function of the encoder is calculated as follows: As shown; ; in, is the sample size, is the image data of the i-th sample, Reconstruct the data for the anomaly of the i-th sample; The regularization loss of potential abnormal information is calculated as As shown; ; in, is the KL divergence, For potential abnormal information, is the prior distribution of abnormal information.
8. The method according to claim 7, characterized in that The pseudo-labeler loss function is calculated as As shown; ; Where n is the number of samples, is the encoding of the label of the i-th sample, is the pseudo label encoding of the i-th sample.
Citation Information
Patent Citations
Battlefield target behavior reasoning method guided by sequence image 3D detection
CN117853820A
Method, device, equipment and medium for detecting internal anomaly of high-siltation pipe network
CN118839270A