Image unsupervised anomaly detection method and device, electronic equipment and medium
By introducing normal feature filters into the image abnormality detection model, the misjudgment problem caused by sparse positive samples is solved, the accuracy and sensitivity of detection are improved, and more efficient abnormality detection effect is achieved.
Patent Information
- Application Number
- CN202411693320.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2025-04-15
AI Technical Summary
When processing data sets with sparse positive samples, it is difficult to accurately learn the key characteristics of positive samples, resulting in high misjudgment rates, lack of dynamic adjustment capabilities, and unable to adaptively adjust detection strategies.
The normal feature filter is added to the anomaly detection model of the constructed image to filter normal features that are prone to misjudgment and strengthen features, thereby reducing the probability of misjudgment and enhancing the ability to capture subtle differences between normal and abnormal samples.
By reducing the misjudgment rate, the accuracy and sensitivity of abnormal detection are improved, and the adaptability of the system is enhanced, so that positive samples can be more effectively handled.
Smart Images

Figure CN119832289A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image detection technology, and in particular to an image unsupervised anomaly detection method, device, electronic equipment and medium. Background Art
[0002] In the field of unsupervised anomaly detection, existing technologies mainly rely on global statistics or preset thresholds to identify anomalies. This method usually performs well when the data is evenly distributed, but in practical applications, it often faces the problem of sparse positive samples, resulting in a significant decrease in detection performance. Especially in key areas such as industrial quality inspection and medical image analysis, the scarcity and criticality of positive samples require that the detection system must have extremely high accuracy and sensitivity. Existing models often fail to accurately learn the key features of positive samples when processing data sets with a small number of positive samples, resulting in a high misclassification rate and incorrectly classifying positive samples as negative samples. In addition, these models usually lack dynamic adjustment capabilities and cannot adaptively adjust the detection strategy according to the actual data distribution, which limits their applicability and reliability in practical applications. Therefore, there is an urgent need for a new method to effectively solve the misclassification problem of sparse positive samples and improve the accuracy and adaptability of anomaly detection. Summary of the invention
[0003] The present invention provides an unsupervised anomaly detection method for images to solve the technical problem that anomaly detection models are prone to misjudgment when positive samples are sparse.
[0004] According to one aspect of the present invention, there is provided an unsupervised anomaly detection method for an image, comprising:
[0005] A dataset is constructed using a variety of normal image samples and a variety of abnormal samples;
[0006] Constructing an abnormality detection model for an image, wherein the abnormality detection model includes a normal feature filter, wherein the normal feature filter is used to filter normal features that are easily misjudged and strengthen the features;
[0007] The anomaly detection model constructed by training based on the data set is obtained to obtain the trained anomaly detection model;
[0008] The image to be predicted is input into the trained anomaly detection model, and the detection result is output.
[0009] Optionally, the anomaly detection model includes an encoder, a normal feature filter, an abnormal feature filter, and a decoder;
[0010] The encoder is used to extract a first feature of the input image data;
[0011] The normal feature filter is used to perform feature adjustment on the first feature to enhance feature information;
[0012] The abnormal feature filter is used to identify and suppress abnormal features while retaining normal data features, and the input of the abnormal feature filter is the adjusted feature plus the first feature;
[0013] The decoder is used to reconstruct the feature data after filtering by the abnormal feature filter.
[0014] Optionally, the normal feature filter uses a residual network module to convert the input first feature into a residual feature, and outputs the residual feature plus the first feature.
[0015] Optionally, if the normal feature filter is added on the basis of the trained unsupervised anomaly detection model, the anomaly detection model constructed based on the training of the data set includes:
[0016] The abnormality detection model with the normal feature filter added is trained based on the image samples in the data set, and the parameters of the normal feature filter are updated until the training is completed when the first loss function converges, thereby obtaining the trained abnormality detection model.
[0017] Optionally, the anomaly detection model constructed based on the training of the data set includes:
[0018] S201, constructing a first loss function for the normal feature filter and a second loss function for the abnormal feature filter; the first loss function is used to filter out normal features that are misjudged as abnormal by the abnormal feature filter, and to highlight normal features and abnormal features; the second loss function is used to highlight normal features and abnormal features, and to ensure that the first feature of the abnormality detection model is close to the reconstructed feature;
[0019] S202, training the abnormal feature filter N1 times based on the image samples in the data set, and updating the parameters of the abnormal feature filter;
[0020] S203, training the normal feature filter N2 times based on the image samples in the data set, and updating the parameters of the normal feature filter;
[0021] Repeat step S202 to step S203 until the first loss function of the abnormal feature filter and the second loss function of the normal feature filter converge, and the training is completed to obtain the trained abnormality detection model.
[0022] Optionally, the calculation formulas of the second loss functions L1 and L2 are:
[0023]
[0024] In the formula, f I_a and f I ' _a The dimensions of f are all [c, h, w], where c represents the number of channels of the feature, h and w represent the width and height of the feature respectively; define f I_a_mean [:,i,j] and f I ' _a_mean [:,i,j] are the features f I_a and f I ' _a The result of normalization of the c-dimensional feature vector at position [i, j]. I_a is the feature data output by the positive sample after the abnormal feature filter; f I_e is the feature data output by the encoder; f o is the feature data output by the decoder; f I ' _a It is the characteristic data obtained after the noise sample passes through the abnormal feature filter.
[0025] Optionally, the calculation formulas of the first loss functions L3 and L4 are:
[0026]
[0027] In the formula, f I_n and f o The dimensions of f are all [c, h, w], where c represents the number of channels of the feature, h and w represent the width and height of the feature respectively; define f I_n_mean [:,i,j],f o_mean [:,i,j] and f I ' _n_mean [:,i,j] are the features f I_n 、f o and f I ' _n The result of normalization of the c-dimensional feature vector at position [i, j], 1≤k≤c; f I_n The feature data output by the normal feature filter; f I_e is the feature data output by the encoder; f o is the feature data output by the decoder; f I ' _n is the feature obtained after the noise sample passes through the normal feature filter; S[i,j] represents f I_n_mean [:,i,j] and f o_mean Cosine similarity of [:,i,j].
[0028] According to another aspect of the present invention, there is provided an image unsupervised anomaly detection device, comprising:
[0029] A data set construction unit, used for constructing a data set using a plurality of non-abnormal image samples and a plurality of abnormal samples;
[0030] A model building unit, used to build an abnormality detection model for an image, wherein the abnormality detection model includes a normal feature filter, wherein the normal feature filter is used to filter normal features that are easily misjudged and strengthen the features;
[0031] A training unit, configured to train the constructed anomaly detection model based on the data set to obtain the trained anomaly detection model;
[0032] The detection unit is used to input the image to be predicted into the trained anomaly detection model and output the detection result.
[0033] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0034] at least one processor; and
[0035] a memory communicatively connected to the at least one processor; wherein,
[0036] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the image unsupervised anomaly detection method described in any embodiment of the present invention.
[0037] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the image unsupervised anomaly detection method described in any embodiment of the present invention when executed.
[0038] The technical solution of the embodiment of the present invention adds a normal feature filter for filtering normal features that are easily misjudged and strengthening features in the abnormality detection model for constructing an image, so that the abnormality detection model can filter normal features that are easily misjudged by the abnormal feature filter, so that the trained abnormality detection model can reduce the probability of misjudgment; in addition, by enhancing features through the normal feature filter, the model can enhance the ability to capture subtle differences between normal and abnormal samples, thereby reducing the misjudgment rate and enhancing the accuracy and sensitivity of the system.
[0039] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0041] Figure 1 is a flowchart of an unsupervised anomaly detection method for an image provided according to Embodiment 1 of the present invention;
[0042] Figure 2 A schematic diagram of the network structure of an unsupervised anomaly detection network in one embodiment;
[0043] Figure 3 A schematic diagram of a structure for training an abnormal feature filter in an anomaly detection model in one embodiment of the present invention;
[0044] Figure 4 A schematic diagram of a structure for training a normal feature filter in an anomaly detection model in one embodiment of the present invention;
[0045] Figure 5 It is a schematic diagram of an abnormality detection model predicting an image sample to be predicted in one embodiment of the present invention;
[0046] Figure 6 An architecture diagram of an unsupervised anomaly detection device for images provided in Embodiment 2 of the present invention;
[0047] Figure 7 It is a structural schematic diagram of an electronic device for implementing the image unsupervised anomaly detection method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the 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 ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0049] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0050] A major difficulty in detecting abnormal samples is the sparsity of positive samples (i.e., abnormal events). In many practical applications, such as medical image analysis and industrial quality control, abnormal events are relatively rare, which makes it difficult for the model to learn effective abnormal features from the data, resulting in high false positive and false negative rates. Since anomalies usually appear as subtle deviations, this requires the algorithm to accurately extract and understand the deep features of the data. Traditional unsupervised learning methods often have difficulty capturing these subtle abnormal patterns without sufficient labels. In addition, in a dynamically changing data environment, data distribution and abnormal patterns may evolve over time. Existing anomaly detection algorithms often lack sufficient adaptability and cannot effectively cope with changes in data distribution, thus affecting the accuracy and reliability of detection results.
[0051] Existing anomaly detection often mistakenly marks normal activities as abnormal (false positive) or treats abnormal activities as normal (false negative), which will have a serious impact on the final application results. Especially in many key fields such as medical image diagnosis, industrial quality control, and security monitoring, anomaly detection is crucial. Correctly identifying anomalies in images can not only detect diseases, equipment failures, and safety threats in a timely manner, but also greatly reduce the costs and risks caused by misdiagnosis or missed diagnosis.
[0052] In an unsupervised anomaly detection method, such as Figure 2 The network structure diagram of the unsupervised anomaly detection network shown in the figure can include an encoder, an abnormal feature filter and a decoder. The encoder is used to extract the feature data of the input image data, including the features of the input positive samples and the features of the noise samples. The input image data is usually converted into a low-dimensional feature representation, and the encoder uses a pre-trained model and remains fixed during the entire model iteration process without updating. The abnormal feature filter is used to identify and suppress abnormal features while retaining normal data features. The decoder is used to reconstruct the feature data filtered by the abnormal feature filter so that the reconstructed data can be restored to the original data as much as possible.
[0053] In order to solve the technical problem that anomaly detection models are prone to misjudgment when positive samples are sparse, the present invention adds a normal feature filter for filtering normal features that are easily misjudged and strengthening features in the anomaly detection model for constructing an image, so that the anomaly detection model can filter normal features that are easily misjudged by the abnormal feature filter, so that the trained anomaly detection model can reduce the probability of misjudgment; in addition, by enhancing features through the normal feature filter, the model can enhance the ability to capture subtle differences between normal and abnormal samples, thereby reducing the misjudgment rate and enhancing the accuracy and sensitivity of the system.
[0054] Embodiment 1
[0055] Figure 1 A flowchart of an unsupervised anomaly detection method for an image is provided for the first embodiment of the present invention. Figure 1 As shown, the system includes:
[0056] S101. Construct a data set using a variety of non-abnormal image samples and a variety of abnormal samples.
[0057] This embodiment can obtain a large number of image samples, which may include multiple different types of image samples, such as texture image data samples and object image data samples. In addition, the image samples also include positive samples without abnormalities and noise samples containing various abnormalities, that is, texture image data samples or object image data contain positive samples without abnormalities and noise samples containing various abnormalities.
[0058] After constructing the data set, the data set can be divided into a training set and a test set according to a certain ratio for subsequent training of the anomaly detection model.
[0059] S102: construct an abnormality detection model for the image, wherein the abnormality detection model includes a normal feature filter, and the normal feature filter is used to filter normal features that are easily misjudged and strengthen the features.
[0060] In this embodiment, an anomaly detection model for image detection can be designed as needed, or a normal feature filter module can be added to the existing unsupervised anomaly detection model. The normal feature filter module has the function of filtering normal features that are easily misjudged and strengthening positive sample features and noise sample features, so that the anomaly detection model with the normal feature filter module added can reduce the misjudgment of anomaly detection and enhance the accuracy and sensitivity of the model.
[0061] S103: Train the constructed anomaly detection model based on the data set to obtain the trained anomaly detection model.
[0062] S104: input the image to be predicted into the trained anomaly detection model, and output the detection result.
[0063] The training set and test set obtained after dividing the data set can be input into the constructed anomaly detection model to train the anomaly detection model until the model training is completed when the preset conditions are met, and the trained anomaly detection model is obtained. The preset condition can be that the loss function of the model is in a convergence state, or it can be that the iteration is stopped when the number of iterations reaches a preset number of iterations. In the sample prediction stage, the image to be predicted can be input into the trained anomaly detection model, and the detection result of the model can be output.
[0064] The technical solution of the embodiment of the present invention adds a normal feature filter for filtering normal features that are easily misjudged and strengthening features in the abnormality detection model for constructing an image, so that the abnormality detection model can filter normal features that are easily misjudged by the abnormal feature filter, so that the trained abnormality detection model can reduce the probability of misjudgment; in addition, by enhancing features through the normal feature filter, the model can enhance the ability to capture subtle differences between normal and abnormal samples, thereby reducing the misjudgment rate and enhancing the accuracy and sensitivity of the system.
[0065] In one embodiment, the anomaly detection model includes an encoder, a normal feature filter, an abnormal feature filter, and a decoder;
[0066] The encoder is used to extract a first feature of the input image data;
[0067] The normal feature filter is used to perform feature adjustment on the first feature to enhance feature information;
[0068] The abnormal feature filter is used to identify and suppress abnormal features while retaining normal data features, and the input of the abnormal feature filter is the adjusted feature plus the first feature;
[0069] The decoder is used to reconstruct the feature data after filtering by the abnormal feature filter.
[0070] like Figure 3 and Figure 4 From the structural schematic diagram of training the abnormal feature filter and the structural schematic diagram of training the normal feature filter in the abnormal detection model, it can be seen that the abnormal feature filter of this embodiment includes an abnormal detection model including an encoder, a normal feature filter, an abnormal feature filter and a decoder.
[0071] Specifically, the encoder E uses a deep neural network to convert the input image data into a low-dimensional feature representation f I eThis step is used to extract important features from the image, laying the foundation for subsequent anomaly detection. Usually, the encoder uses a pre-trained model and keeps it fixed during the entire model iteration process without updating. The encoder's formula for extracting features from an image can be expressed as:
[0072] f I_e =E(I)
[0073] Normal feature filter N f After receiving the feature data extracted by the encoder, the first feature extracted by the encoder is further refined to obtain a new feature with unchanged dimension. Its main purpose is to assist in filtering out positive sample features that are prone to misdetection, thereby reducing the model's misjudgment.
[0074] In one embodiment, the normal feature filter uses a residual network module to convert the first input feature into a residual feature, and converts the residual feature N f (f I_e ) and add the first characteristic f I_e As output, the input features are adjusted to enhance the features. Normal feature filter N f The formula for adjusting the first feature can be expressed as:
[0075] f I_n =f I_e +N f (f I_e )
[0076] The abnormal feature filter is used to identify and suppress potential abnormal features while retaining normal data features. The abnormal feature filter adjusts the features f of the normal feature filter. I_n The processing formula can be expressed as:
[0077] f I_a =N a (f I_n )
[0078] The encoder is used to reconstruct the data that has been filtered by the abnormal feature filter. This step is mainly to verify the effectiveness of the filtering process and evaluate the performance of the filter by restoring the features of the original data as much as possible. The formula for reconstructing feature data by the encoder can be expressed as:
[0079] f o =D(f I_a )
[0080] In one embodiment, if the normal feature filter is added on the basis of the trained unsupervised anomaly detection model, the anomaly detection model constructed based on the training of the data set includes:
[0081] The abnormality detection model with the normal feature filter added is trained based on the image samples in the data set, and the parameters of the normal feature filter are updated until the training is completed when the first loss function converges, thereby obtaining the trained abnormality detection model.
[0082] When adding normal feature filters directly to the trained unsupervised anomaly detection model, such as Figure 2 When the unsupervised anomaly detection model shown is already a trained anomaly detection model, a normal feature filter can be added to the unsupervised anomaly detection model to obtain Figure 4 The anomaly detection model shown only needs to adopt an appropriate loss function to train the anomaly detection model, and during the training process, only the model parameters of the normal feature filter need to be updated until the training is completed when the first loss function converges to obtain a trained anomaly detection model.
[0083] In one embodiment, the calculation formulas of the first loss functions L3 and L4 are:
[0084]
[0085] In the formula, f I_n and f o The dimensions of f are all [c, h, w], where c represents the number of channels of the feature, h and w represent the width and height of the feature respectively; define f I_n_mean [:,i,j],f o_mean [:,i,j] and f I ' _n_mean [:,i,j] are the features f I_n 、f o and f I ' _n The result of normalization of the c-dimensional feature vector at position [i, j], 1≤k≤c; f I_n The feature data output by the normal feature filter; f I_e is the feature data output by the encoder; f o is the feature data output by the decoder; f I ' _n is the feature obtained after the noise sample passes through the normal feature filter; S[i,j] represents f I_n_mean [:,i,j] and f o_mean Cosine similarity of [:,i,j].
[0086] It should be noted that the abnormal graph S obtained by the above formula is composed of the feature f I_n and f oThe cosine similarity between the feature vectors at position (i, j) is obtained. Since it is expected that the two features are as similar as possible, it is expected that each value in S is as close to 1 as possible.
[0087] In the above formula, the loss function L3 is used to constrain the normal feature filter so that it filters out normal features that are misjudged as abnormal by the abnormal feature filter. The loss function L4 can ensure that the normal feature filter will not miss important abnormal signals while enhancing the model's understanding of normal data. This can prevent the normal feature filter from over-suppressing the real abnormal features, causing the model to miss the real abnormal samples.
[0088] In one embodiment, the anomaly detection model constructed based on the training of the data set includes:
[0089] S201, constructing a first loss function for the normal feature filter and a second loss function for the abnormal feature filter; the first loss function is used to filter out normal features that are misjudged as abnormal by the abnormal feature filter, and to highlight normal features and abnormal features; the second loss function is used to highlight normal features and abnormal features, and to ensure that the first feature of the abnormality detection model is close to the reconstructed feature;
[0090] S202, training the abnormal feature filter N1 times based on the image samples in the data set, and updating the parameters of the abnormal feature filter;
[0091] S203, training the normal feature filter N2 times based on the image samples in the data set, and updating the parameters of the normal feature filter;
[0092] Repeat step S202 to step S203 until the first loss function of the abnormal feature filter and the second loss function of the normal feature filter converge, and the training is completed to obtain the trained abnormality detection model.
[0093] It should be noted that when reconstructing Figure 3 and Figure 4When the abnormal detection model shown is used, the abnormal feature filter and the normal feature filter need to be alternately trained. The alternating training method can be that the abnormal feature filter is first trained N1 times using the image samples in the data set, and the model parameters of the abnormal feature filter are updated in each iteration; then the normal feature filter is trained N2 times using the image samples in the data set, and the parameters of the normal feature filter are updated in each iteration; and the above steps are repeated until the first loss function of the abnormal feature filter and the second loss function of the normal feature filter converge to complete the training, and the trained abnormal detection model is obtained. It can also be that the normal feature filter is first trained N2 times using the image samples in the data set, and the parameters of the normal feature filter are updated in each iteration; then the abnormal feature filter is trained N1 times using the image samples in the data set, and the model parameters of the abnormal feature filter are updated in each iteration; and the above steps are repeated until the first loss function of the abnormal feature filter and the second loss function of the normal feature filter converge to complete the training, and the trained abnormal detection model is obtained. The values of N1 and N2 can be set by yourself, for example, N1 can be set to 5, and N2 can be set to 1.
[0094] In one embodiment, the calculation formulas of the first loss functions L3 and L4 are:
[0095]
[0096]
[0097] In the formula, f I_n and f o The dimensions of f are all [c, h, w], where c represents the number of channels of the feature, h and w represent the width and height of the feature respectively; define f I_n_mean [:,i,j],f o_mean [:,i,j] and f I ' _n_mean [:,i,j] are the features f I_n 、f o and f I ' _n The result of normalization of the c-dimensional feature vector at position [i, j], 1≤k≤c; f I_n The feature data output by the normal feature filter; f I_e is the feature data output by the encoder; f o is the feature data output by the decoder; f I ' _n is the feature obtained after the noise sample passes through the normal feature filter; S[i,j] represents f I_n_mean [:,i,j] and f o_mean Cosine similarity of [:,i,j].
[0098] Since the anomaly graph S obtained by the above formula is composed of the feature f I_n and f o The cosine similarity between the feature vectors at position (i, j) is obtained. Since it is expected that the two features are as similar as possible, it is expected that each value in S is as close to 1 as possible.
[0099] The loss function L3 is used to constrain the normal feature filter so that it filters out normal features that are misjudged as abnormal by the abnormal feature filter. The loss function L4 ensures that the normal feature filter will not miss important abnormal signals while enhancing the model's understanding of normal data. This prevents the normal feature filter from over-suppressing the real abnormal features, causing the model to miss real abnormal samples.
[0100] In one embodiment, the calculation formulas of the second loss functions L1 and L2 are:
[0101]
[0102] In the formula, f I_a and f I ' _a The dimensions of f are all [c, h, w], where c represents the number of channels of the feature, h and w represent the width and height of the feature respectively; define f I_a_mean [:,i,j] and f I ' _a_mean [:,i,j] are the features f I_a and f I ' _a The result of normalization of the c-dimensional feature vector at position [i, j]. I_a is the feature data output by the positive sample after the abnormal feature filter; f I_e is the feature data output by the encoder; f o is the feature data output by the decoder; f I ' _a It is the characteristic data obtained after the noise sample passes through the abnormal feature filter.
[0103] Among them, the loss function L1 is used to improve the performance of the model when processing noisy features and normal features. The loss function L2 is used to ensure the overall data reconstruction quality of the model to ensure that the decoded output is as close to the original input as possible.
[0104] In a specific application example, MVTec can be used as a data set for training the model. The data set contains 15 types of real data used for anomaly detection, of which 5 types are texture data and 10 types are object data. The data set is divided into a training set and a test set. There are 3629 non-anomaly samples in the training set and 1725 samples with or without various anomalies in the test set.
[0105] In this application example, all images are scaled to 256×256. Only 50 images in the training data set are sampled for each training to simulate the situation where positive samples are sparse. The schemes used for experimental comparison are anomaly detection models in two existing technical schemes, including the reconstruction-based unsupervised anomaly detection network RD and RD++. The encoders are uniformly pre-trained WideResNet50.
[0106] The experimental results are shown in Table 1 below: The experimental data is the average AUROC value of anomaly detection pixel level after 5 random sampling trainings. The experimental results show that this method can effectively improve the accuracy of anomaly detection under sparse positive samples.
[0107] Table 1 Comparison of pixel-level AUROC mean values of anomaly detection between the present invention and the comparative scheme
[0108]
[0109]
[0110] Embodiment 2
[0111] Figure 6 This is a schematic diagram of the structure of an unsupervised anomaly detection device for an image provided by Embodiment 3 of the present invention. Figure 6 As shown, the device comprises:
[0112] A data set construction unit 601 is used to construct a data set using a plurality of normal image samples and a plurality of abnormal samples;
[0113] A model building unit 602 is used to build an abnormality detection model for an image, wherein the abnormality detection model includes a normal feature filter, wherein the normal feature filter is used to filter normal features that are easily misjudged and strengthen the features;
[0114] A training unit 603 is used to train the constructed anomaly detection model based on the data set to obtain the trained anomaly detection model;
[0115] The detection unit 604 is used to input the image to be predicted into the trained anomaly detection model and output the detection result.
[0116] In one embodiment, the training unit 603 is also used to train the abnormality detection model by adding the normal feature filter based on the image samples in the data set, and update the parameters of the normal feature filter until the training is completed when the first loss function converges, thereby obtaining the trained abnormality detection model.
[0117] In one embodiment, the training unit 603 is further used to construct a first loss function for the normal feature filter and a second loss function for the abnormal feature filter; the first loss function is used to filter out normal features that are misjudged as abnormal by the abnormal feature filter, and to highlight normal features and abnormal features; the second loss function is used to highlight normal features and abnormal features, and to ensure that the first feature of the abnormality detection model is close to the reconstructed feature;
[0118] Training the abnormal feature filter N1 times based on the image samples in the data set, and updating the parameters of the abnormal feature filter;
[0119] Training the normal feature filter N2 times based on the image samples in the data set, and updating the parameters of the normal feature filter;
[0120] The above training steps are repeated until the first loss function of the abnormal feature filter and the second loss function of the normal feature filter converge, and the training is completed to obtain the trained abnormality detection model.
[0121] The image unsupervised anomaly detection method device provided in the embodiment of the present invention can execute the image unsupervised anomaly detection method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0122] Embodiment 3
[0123] Figure 7 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0124] like Figure 7As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0125] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0126] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as an image unsupervised anomaly detection method.
[0127] In some embodiments, an image unsupervised anomaly detection method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the image unsupervised anomaly detection method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform an image unsupervised anomaly detection method in any other appropriate manner (e.g., by means of firmware).
[0128] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0129] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0130] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0131] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0132] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0133] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0134] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0135] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. An unsupervised anomaly detection method for an image, characterized in that: include: A dataset is constructed using a variety of normal image samples and a variety of abnormal samples; Constructing an abnormality detection model for an image, wherein the abnormality detection model includes a normal feature filter, wherein the normal feature filter is used to filter normal features that are easily misjudged and strengthen the features; The anomaly detection model constructed by training based on the data set is obtained to obtain the trained anomaly detection model; The image to be predicted is input into the trained anomaly detection model, and the detection result is output.
2. The unsupervised anomaly detection method for images according to claim 1, characterized in that: The anomaly detection model includes an encoder, a normal feature filter, an abnormal feature filter and a decoder; The encoder is used to extract a first feature of the input image data; The normal feature filter is used to perform feature adjustment on the first feature to enhance feature information; The abnormal feature filter is used to identify and suppress abnormal features while retaining normal data features, and the input of the abnormal feature filter is the adjusted feature plus the first feature; The decoder is used to reconstruct the feature data after filtering by the abnormal feature filter.
3. The unsupervised anomaly detection method for images according to claim 2, characterized in that: The normal feature filter uses a residual network module to convert the input first feature into a residual feature, and outputs the residual feature plus the first feature.
4. The unsupervised anomaly detection method for images according to claim 2, characterized in that: If the normal feature filter is added on the basis of the trained unsupervised anomaly detection model, the anomaly detection model constructed based on the training of the data set includes: The abnormality detection model with the normal feature filter added is trained based on the image samples in the data set, and the parameters of the normal feature filter are updated until the training is completed when the first loss function converges, thereby obtaining the trained abnormality detection model.
5. The unsupervised anomaly detection method for images according to claim 2, characterized in that: The anomaly detection model constructed based on the training of the data set includes: S201, constructing a first loss function for the normal feature filter and a second loss function for the abnormal feature filter; the first loss function is used to filter out normal features that are misjudged as abnormal by the abnormal feature filter, and to highlight normal features and abnormal features; the second loss function is used to highlight normal features and abnormal features, and to ensure that the first feature of the abnormality detection model is close to the reconstructed feature; S202, training the abnormal feature filter N1 times based on the image samples in the data set, and updating the parameters of the abnormal feature filter; S203, training the normal feature filter N2 times based on the image samples in the data set, and updating the parameters of the normal feature filter; Repeat step S202 to step S203 until the first loss function of the abnormal feature filter and the second loss function of the normal feature filter converge, and the training is completed to obtain the trained abnormality detection model.
6. The unsupervised anomaly detection method for images according to claim 5, characterized in that: The calculation formula of the second loss function L1 and L2 is: In the formula, f I_a and f I ' _a The dimensions of f are all [c, h, w], where c represents the number of channels of the feature, h and w represent the width and height of the feature respectively; define f I_a_mean [:,i,j] and f I ' _a_mean [:,i,j] are the features f I_a and f I ' _a The result of normalization of the c-dimensional feature vector at position [i, j]. I_a is the feature data output by the positive sample after the abnormal feature filter; f I_e is the feature data output by the encoder; f o is the feature data output by the decoder; f I ' _a It is the characteristic data obtained after the noise sample passes through the abnormal feature filter.
7. The unsupervised anomaly detection method for images according to claim 4 or 5, characterized in that: The calculation formula of the first loss function L3 and L4 is: In the formula, f I_n and f o The dimensions of f are all [c, h, w], where c represents the number of channels of the feature, h and w represent the width and height of the feature respectively; define f I_n_mean [:,i,j],f o_mean [:,i,j] and f I ' _n_mean [:,i,j] are the features f I_n 、f o and f I ' _n The result of normalization of the c-dimensional feature vector at position [i, j], 1≤k≤c; f I_n The feature data output by the normal feature filter; f I_e is the feature data output by the encoder; f o is the feature data output by the decoder; f I ' _n is the feature obtained after the noise sample passes through the normal feature filter; S[i,j] represents f I_n_mean [:,i,j] and f o_mean Cosine similarity of [:,i,j].
8. An unsupervised anomaly detection device for an image, characterized in that: include: A data set construction unit, used for constructing a data set using a plurality of non-abnormal image samples and a plurality of abnormal samples; A model building unit, used to build an abnormality detection model for an image, wherein the abnormality detection model includes a normal feature filter, wherein the normal feature filter is used to filter normal features that are easily misjudged and strengthen the features; A training unit, configured to train the constructed anomaly detection model based on the data set to obtain the trained anomaly detection model; The detection unit is used to input the image to be predicted into the trained anomaly detection model and output the detection result.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the image unsupervised anomaly detection method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the image unsupervised anomaly detection method according to any one of claims 1 to 7 when executed.