Industrial anomaly detection method and system

By using a combination of backbone network, pooling layer, cascade flow, twin flow and constant flow in industrial anomaly detection, the problem of low detection and positioning accuracy in the existing technology is solved, and more precise positioning and positioning of industrial anomalies are achieved. detection.

CN118470014BActive Publication Date: 2024-09-24NANJING UNIV OF INFORMATION SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410925191.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-11
Publication Date
2024-09-24
Estimated Expiration
2044-07-11

AI Technical Summary

Technical Problem

Existing probability distribution anomaly detection algorithms have problems with poor generalization ability, unstable detection accuracy, and inaccurate positioning when detecting and locating industrial anomalies, especially when the anomaly size changes are not uniform.

Method used

An industrial anomaly detection method is adopted, including backbone network, pooling layer, cascade flow, twin sub-flow and constant flow. The sub-network is kept stable through the traceable mask convolution layer in the cascade flow, and the global capture module in the twin sub-flow And the proximity search module extracts the contextual relationship of the image, and the constant flow keeps the probability distribution unchanged, thereby improving detection and positioning accuracy.

Benefits of technology

It improves the accuracy of anomaly detection and location, enhances the generalization ability of the model, and ensures accurate detection and location of anomalies that vary in size.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118470014B
    Figure CN118470014B
Patent Text Reader

Abstract

The present invention discloses an industrial anomaly detection method and system, comprising: acquiring an image to be detected for anomaly; detecting and locating anomalies based on the acquired image and a pre-trained anomaly detection model; the anomaly detection model comprises: a backbone network, a pooling layer, a cascade flow, a twin flow and a constant flow; the cascade flow comprises a number of flow blocks arranged in sequence. The present invention makes the difference between abnormal data features and normal data features more obvious, thereby improving the effect of locating anomalies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of anomaly detection, and in particular relates to an industrial anomaly detection method and system. Background Art

[0002] Image anomaly detection is to detect and identify abnormal data that deviates from normal data by analyzing image data. However, it is very difficult to obtain abnormal samples, and in actual situations, unpredictable anomalies are gradually increasing, so unsupervised anomaly detection algorithms are usually used to solve this problem. This algorithm can be used in data sets with no abnormal samples or only a few abnormal samples. Since it is impossible to learn the characteristics of abnormal samples, the idea based on probability distribution is adopted, that is, normal samples are preprocessed and then generated into probability distribution through probability model. By comparing the difference in probability likelihood values ​​between normal pictures and abnormal pictures, it is possible to distinguish whether the current picture is an abnormal picture, and then further locate the anomaly.

[0003] During the training process, these probability models put normal samples into the model so that the probability distribution generated by the model is as similar as possible to the probability distribution of normal sample data. During the detection process, if an abnormal sample is encountered, the generated probability distribution is different from the normal sample, so the abnormality is detected. However, in practical applications, due to the unpredictable and non-uniform size of the abnormality in the image, the existing probability distribution model cannot accurately locate every abnormality.

[0004] In summary, the existing probability distribution anomaly detection algorithm has some defects:

[0005] 1) Existing methods try to make the generated probability distribution as similar as possible to that of normal samples, which damages the sub-network in the model, resulting in poor generalization ability and ultimately causing a decrease in detection and positioning accuracy.

[0006] 2) In order to improve the accuracy, the existing probability distribution method is implemented by stacking multiple modules, but it leads to unstable detection accuracy.

[0007] 3) Existing probability distribution methods are not accurate in locating anomalies of varying sizes in images, resulting in poor detection and localization accuracy. Summary of the invention

[0008] In order to solve the problems existing in the prior art, the present invention provides an industrial anomaly detection method and system, which can more accurately locate industrial anomalies.

[0009] The technical problem to be solved by the present invention is achieved through the following technical solutions:

[0010] In a first aspect, an industrial anomaly detection method is provided, comprising: acquiring an image to be detected for anomalies.

[0011] According to the acquired images, the anomalies are detected and located based on the pre-trained anomaly detection model.

[0012] The anomaly detection model includes: a backbone network, a pooling layer, a cascade flow, a twin flow and a constant flow.

[0013] The cascade stream includes a plurality of stream blocks arranged in sequence.

[0014] In combination with the first aspect, further, the backbone network adopts WideResNet50.

[0015] In combination with the first aspect, further, based on the backbone network, the image to be detected for abnormality is taken as input to obtain a feature map.

[0016] Based on the pooling layer, the feature map is used as input to obtain the compressed feature map .

[0017] Based on the cascade flow, the compressed feature map As input, we get the feature map A after cascade flow processing with stable values.

[0018] Based on the twin stream, the feature map A after cascade stream processing is used as input to further extract features, and the feature map with enriched contextual relationship is obtained after twin stream processing. .

[0019] Based on the constant flow, the feature map output after the dual stream processing As input, we get the feature map output after constant flow processing. .

[0020] The feature map output after constant flow processing Get the final located exception.

[0021] In combination with the first aspect, further, the flow block includes two parallel cascade sub-networks, and the cascade sub-networks include a convolution layer, a hierarchical normalization layer, an activation function ReLU, a traceable mask convolution layer, a hierarchical normalization layer and an activation function ReLU arranged in sequence.

[0022] Based on the stream block, the compressed feature map As input, the feature map After being split into two feature maps along the channel, they are input into two cascaded sub-networks respectively, and then the outputs of the two cascaded sub-networks are spliced ​​as the input of the next stream block, and so on, and finally the feature map A output after cascade stream processing is obtained. The expression is as follows:

[0023]

[0024]

[0025]

[0026] in, Represents cascade flow The i-th stream block in, m represents the number of stream blocks, represents the cascaded sub-network in each flow block, Indicates that the convolution kernel is 3 3 convolutional layers of different sizes, is the hierarchical normalization layer, is the activation function, It is a traceable masked convolutional layer.

[0027] In combination with the first aspect, further, the traceable mask convolution layer processes the feature map output by the activation function ReLU of the previous layer. Split it into 4 new feature maps along the channel , , , , convolve each feature map with a masked convolution kernel to obtain 4 new feature maps , , , , where the mask positions of the four mask convolution kernels are the upper left corner, the upper right corner, the lower left corner, and the lower right corner. Finally, the four feature maps obtained are , , , Merge along the channel to get the masked feature map .

[0028] In combination with the first aspect, further, the dual substream includes a global capture module and a neighbor search module.

[0029] The global capture module is used to process structure data, and the neighbor search module is used to process texture data.

[0030] The global capture module includes: a downsampling layer, a first global sub-network, a second global sub-network, an upsampling layer and a jump connection; the first global sub-network includes a convolutional layer, a hierarchical normalization layer, an activation function ReLU and a convolutional layer arranged in sequence, and the first global sub-network has the same structure as the second global sub-network.

[0031] When the processed data is structured data, based on the downsampling layer, feature map A is used as input to obtain the downsampled feature map D, and then feature map D is split into two new feature maps a and b along the channel. A and b are input into the first global sub-network and the second global sub-network respectively. In the first global sub-network and the second global sub-network, feature maps a and b are split along the channel respectively to obtain two new feature maps. , as well as , , and then , The output after the first global sub-network is concatenated to obtain the feature map a'. , The output after the second global sub-network is spliced ​​to obtain feature map b', and then the feature maps a' and b' are spliced ​​and upsampled by the upsampling module to obtain a feature map of the same size as feature map A. .

[0032] The expression is as follows:

[0033]

[0034]

[0035]

[0036] in, Represents the global capture module, and denote the first global subnetwork and the second global subnetwork respectively, is the upsampling layer, is the downsampling layer, Indicates that the convolution kernel is 3 3 convolutional layers of different sizes, is the hierarchical normalization layer, is the activation function ReLU, Represents a skip connection.

[0037] The neighbor search module includes a neighbor sub-network and a convolution layer; the neighbor sub-network includes a parameter initialization layer and a convolution layer.

[0038] When the processed data is texture data, the feature map A is input into the neighboring search module, and two new feature maps r and s are split along the channel. The new feature maps r and s are then passed through the neighboring sub-network and convolutional layer in turn and then spliced ​​to obtain a new feature map. , the expression is as follows:

[0039]

[0040]

[0041] in, represents the neighbor search module, is the initial layer of parameters; For the output of the twin stream, when processing structured data, Corresponding to the output of the global capture module; when processing texture data Corresponding to the output of the neighbor search module.

[0042] In combination with the first aspect, further, the constant flow includes a plurality of constant flow blocks connected in sequence, and each constant flow block includes two constant sub-networks.

[0043] The constant subnetwork includes convolution kernels arranged in sequence as 1 1 convolution layer with a convolution kernel of 3 3-size convolutional layers, hierarchical normalization layers, activation function LeakyReLU, downsampling layers, hierarchical normalization layers, convolution kernel size 3 3-size convolutional layers, LeakyReLU activation function, upsampling layers, and skip connections.

[0044] Based on the constant flow block, the feature map of the output of the two sub-streams After being split into two feature maps along the channel, they are input into two constant sub-networks respectively, and then the outputs of the two constant sub-networks are spliced ​​as the input of the next constant flow block, and so on, finally obtaining the feature map output after constant flow processing. , the expression is as follows:

[0045]

[0046]

[0047]

[0048] in, Indicates a steady flow The i-th constant flow block in , n represents the number of constant flow blocks, represents the constant subnetwork in each constant flow block, Indicates that the convolution kernel is 1 A convolutional layer of size 1, Represents the activation function LeakyReLU.

[0049] In combination with the first aspect, further, the feature map output after the constant flow processing The exceptions that get the final positioning include:

[0050] The feature map output after constant flow processing Upsample to the size of the original image to get the feature map ,pass The library function takes the maximum value of the last dimension and the second-to-last dimension respectively. The expression is as follows:

[0051]

[0052]

[0053] in, is the maximum value of the last dimension, is the maximum value of the second-to-last dimension, for The maximum value function in the library function; then the feature map minus Get feature map , as shown below:

[0054]

[0055] make , is an exponential function, Applied to the exponential function, we get a new feature map , the expression is as follows:

[0056]

[0057] Finally, the final anomaly map is obtained according to the following formula .

[0058]

[0059] The abnormal graph The maximum pixel value in is taken as the anomaly score, and the points with anomaly scores exceeding the threshold are taken as outliers.

[0060] In a second aspect, an industrial anomaly detection system is provided, comprising:

[0061] The data acquisition module is used to acquire images to be detected for abnormalities.

[0062] The anomaly detection module is used to detect and locate anomalies based on the acquired images and the pre-trained anomaly detection model.

[0063] The anomaly detection model includes: a backbone network, a pooling layer, a cascade flow, a twin flow and a constant flow.

[0064] The cascade stream includes a plurality of stream blocks arranged in sequence.

[0065] In combination with the second aspect, further, the operation performed by the anomaly detection module includes:

[0066] The image to be detected for anomaly is taken as input to obtain the feature map.

[0067] Based on the pooling layer, the feature map is used as input to obtain the compressed feature map .

[0068] Based on the cascade flow, the compressed feature map As input, we get the feature map A after cascade flow processing with stable values.

[0069] Based on the twin stream, the feature map A after cascade stream processing is used as input to further extract features, and the feature map with enriched contextual relationship is obtained after twin stream processing. .

[0070] Based on the constant flow, the feature map output after the dual stream processing As input, we get the feature map output after constant flow processing. .

[0071] The feature map output after constant flow processing Get the final located exception.

[0072] Beneficial effects: The present invention is based on anomaly detection models. The traceable mask convolution layer in the cascade flow ensures the stability of the sub-network of the model, improves the generalization ability, and thus improves the detection and positioning accuracy. The global capture module in the dual sub-stream pays more attention to the global information and local information in the image, that is, the structural details, while the neighboring search module pays more attention to the texture details. The constant flow keeps the probability distribution volume unchanged, so that there is a more obvious difference between the abnormal data features and the normal data features, thereby improving the effect of locating anomalies. BRIEF DESCRIPTION OF THE DRAWINGS

[0073] Figure 1 is a flow chart of anomaly detection in the present invention;

[0074] Figure 2 This is a training flow chart of the anomaly detection model in the present invention;

[0075] Figure 3 This is a schematic diagram of the partial structure of the traceable masked convolutional layer in the present invention. DETAILED DESCRIPTION

[0076] In order to make the objectives, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments.

[0077] Example 1.

[0078] like Figure 1-Figure 3 As shown, the present invention provides an industrial anomaly detection method, which mainly includes the following steps:

[0079] Step 1: Data acquisition.

[0080] Used to obtain images for anomaly detection.

[0081] Step 2: Anomaly detection.

[0082] The image to be detected is input into the pre-trained anomaly detection model to detect and locate the anomaly.

[0083] Among them, the anomaly detection model includes: a backbone network, a pooling layer, a cascade flow, a twin flow and a constant flow, and the backbone network adopts WideResNet50.

[0084] The role of the cascade flow is mainly to slow down the process of minimizing the log-likelihood, thereby maintaining numerical stability.

[0085] The main function of the dual stream is to further extract features and obtain richer contextual relationships, which is beneficial to subsequent anomaly detection and positioning.

[0086] The role of the constant flow is to keep the volume of the probability distribution unchanged, which effectively simplifies the optimization objective.

[0087] The cascade flow includes a number of sequentially arranged flow blocks, the number of flow blocks is set according to experience, each flow block includes two parallel cascade sub-networks, and the cascade sub-network includes 3 sequentially arranged convolution kernels. 3 size, stride size 1, convolutional layer with padding size 1, hierarchical normalization layer, activation function ReLU, convolution kernel 3 3-size traceable masked convolution layer InPaddedConv, hierarchical normalization layer, and activation function ReLU.

[0088] The dual substream includes a global capture module and a neighbor search module.

[0089] The global capture module is used to process structure data, and the neighbor search module is used to process texture data;

[0090] The global capture module includes: a downsampling layer, a first global sub-network, a second global sub-network, an upsampling layer and a jump connection; the first global sub-network includes a convolutional layer, a hierarchical normalization layer, an activation function ReLU and a convolutional layer arranged in sequence, and the first global sub-network has the same structure as the second global sub-network.

[0091] The neighbor search module includes a neighbor sub-network and a convolution layer; the neighbor sub-network includes a parameter initialization layer and a convolution layer.

[0092] The constant flow includes a plurality of constant flow blocks connected in sequence, the number of flow blocks is set based on experience, and each constant flow block includes two constant sub-networks.

[0093] The constant subnetwork includes convolution kernels arranged in sequence as 1 1 convolution layer with a convolution kernel of 3 3-size convolutional layers, hierarchical normalization layers, activation function LeakyReLU, downsampling layers, hierarchical normalization layers, convolution kernel size 3 3-size convolutional layers, LeakyReLU activation function, upsampling layers, and skip connections.

[0094] The specific process of anomaly detection is as follows:

[0095] First, based on the pooling layer, the feature map is used as input to obtain the compressed feature map .

[0096] Secondly, the compressed feature map As input, the feature map After being split into two feature maps along the channel, they are input into two cascaded sub-networks respectively, and then the outputs of the two cascaded sub-networks are spliced ​​as the input of the next stream block, and so on, and finally the feature map A output after cascade stream processing is obtained. The expression is as follows:

[0097]

[0098]

[0099]

[0100] in, Represents cascade flow The i-th stream block in, m represents the number of stream blocks, represents the cascaded sub-network in each flow block, Indicates that the convolution kernel is 3 3 convolutional layers of different sizes, is the hierarchical normalization layer, is the activation function, It is a traceable masked convolutional layer.

[0101] The process of the traceable mask convolutional layer is as follows: Figure 3 As shown. The feature map of the output of the activation function ReLU of the previous layer can be traced back to the masked convolution layer Split along the channel into 4 new feature maps , , , , convolve each feature map with a masked convolution kernel to obtain 4 new feature maps , , , , where some features cannot be extracted by masking some areas of the convolution kernel, thus reducing the process of converting to the target distribution to a certain extent. The mask positions of the four convolution kernels are the upper left corner, the upper right corner, the lower left corner, and the lower right corner. Finally, the four feature maps are obtained , , , Merge along the channel to get the masked feature map Then input to the hierarchical normalization layer .

[0102] When the processed data is structured data, based on the downsampling layer, feature map A is used as input to obtain the downsampled feature map D, and then feature map D is split along the channel into two new feature maps a ( , the three numbers are the channel, width and height of the feature map), b ( ), input a and b into the first global sub-network and the second global sub-network respectively, split the feature maps a and b along the channels in the first global sub-network and the second global sub-network respectively, and obtain two new feature maps respectively. , as well as , , and then , The output after the first global sub-network is concatenated to obtain the feature map a'. , The output after the second global sub-network is spliced ​​to obtain feature map b', and then the feature maps a' and b' are spliced ​​and upsampled by the upsampling module to obtain a feature map of the same size as feature map A. .

[0103] The expression is as follows:

[0104]

[0105]

[0106]

[0107] in, Represents the global capture module, and denote the first global subnetwork and the second global subnetwork respectively, is the upsampling layer, is the downsampling layer, Indicates that the convolution kernel is 3 3 convolutional layers of different sizes, is the hierarchical normalization layer, is the activation function ReLU, Represents a skip connection.

[0108] When the processed data is texture data, the feature map A is input into the neighbor search module, and two new feature maps r are split along the channel ( , , , Represent the channel, height, and width of the feature map) and s respectively, and then the new feature maps r and s are sequentially passed through the adjacent sub-network and convolutional layer and then spliced ​​to obtain a new feature map , the expression is as follows:

[0109]

[0110]

[0111] in, represents the neighbor search module, is the initial layer of parameters; For the output of the twin stream, when processing structured data, Corresponding to the output of the global capture module; when processing texture data Corresponding to the output of the neighbor search module.

[0112] After the twin substreams are processed, the output results are input to the constant stream for further processing. Based on the constant stream block, the feature graph of the output of the twin substreams is After being split into two feature maps along the channel, they are input into two constant sub-networks respectively, and then the outputs of the two constant sub-networks are spliced ​​as the input of the next constant flow block, and so on, finally obtaining the feature map output after constant flow processing. , the expression is as follows:

[0113]

[0114]

[0115]

[0116] in, Indicates a steady flow The i-th constant flow block in , n represents the number of constant flow blocks, represents the constant subnetwork in each constant flow block, Indicates that the convolution kernel is 1 A convolutional layer of size 1, Represents the activation function LeakyReLU.

[0117] Finally, the feature map output after constant flow processing Upsample to the size of the original image to get the feature map , through the pytorch framework The library function takes the maximum value of the last dimension and the second-to-last dimension respectively. The expression is as follows:

[0118]

[0119]

[0120] in, is the maximum value of the last dimension, is the maximum value of the second-to-last dimension, for The maximum value function in the library function; then the feature map minus Get feature map , as shown below:

[0121]

[0122] make , is an exponential function, Applied to the exponential function, we get a new feature map , the expression is as follows:

[0123]

[0124] Finally, the final anomaly map is obtained according to the following formula ,

[0125]

[0126] The abnormal graph The maximum pixel value in is taken as the anomaly score. In this paper, 0.3 is taken. According to the empirical setting, the points with anomaly scores exceeding the threshold are regarded as anomalies. The splicing and splitting operations in this paper are implemented by the pytorch framework functions split and cat.

[0127] Example 2.

[0128] The present invention also provides an anomaly detection method, the main steps of which are the same as those in Example 1, except that three feature maps of different scales are extracted for calculation in the initial feature extraction, which is beneficial to further improve the final anomaly detection accuracy.

[0129] According to the three feature maps of different scales, three feature maps can be obtained by compressing them through the pooling layer: , , , concatenate the three input streams to obtain three new feature maps of different scales , as shown below

[0130]

[0131] Then three new feature maps of different scales are Input into the twin stream.

[0132] If the data being processed is structural data, the three feature maps A ( ), B( ), C ( ) is input into the global capture module. The three feature maps ( , , ) are concatenated along the channel into a new feature map and input into the downsampling layer, making the image height and width , and get a new feature map D again ( ). Then it is split into two new feature maps a along the channel of feature map D ( ), b( ), which is input into two global sub-networks.

[0133] In the global sub-network, the two feature maps a and b are further split along the channels to obtain two new feature maps ( )and( ), and then pass through the 4 layers in the global sub-network in turn. At the final output, it is spliced ​​along the channel, and then split into three feature maps along the channel and upsampled to the same level as the original feature map A ( ), B( ), C ( ) are the same size.

[0134] The overall process is as follows:

[0135] Enter a The size feature map (feature map a) is split into two new ones along the channel Size feature map ( ), and then pass through the global sub-network 4 layers in sequence. When outputting, it is spliced ​​along the channel to output a Size feature map (feature map a').

[0136] Enter a The size feature map (feature map b) is split into two new ones along the channel Size feature map ( ), and then pass through the global sub-network 4 layers in sequence. When outputting, it is spliced ​​along the channel to output a Size feature map) (feature map b').

[0137] (Splicing, splitting) Feature map a' and feature map b' are spliced ​​into one feature map, then split into three feature maps, upsampled to the original size, and finally output three feature maps, respectively. Size feature map , Size feature map , Size feature map .

[0138] Based on the above, three feature maps ( , , ) outputs another three feature maps through the global capture module in the twin stream ( , , ). Its expression is as follows:

[0139]

[0140] When the processed data is texture data, the three feature maps A ( ), B( ), C ( ) are input into the neighboring search module respectively, and each is split along the channel to produce two new feature maps denoted as and (i=1,2,3, where and Indicates the two new feature maps generated by the i-th feature map, a total of 6 new feature maps (A -> ( and ), B -> ( and ), C -> ( and )), and and Enter into the neighboring subnetwork.

[0141] Finally and Then splice along the channel to get a new feature map of the same size as the original feature map.

[0142] The overall process is as follows:

[0143] Enter a Size feature map (feature map ), output a Size feature map (when ,when ,when )

[0144] Enter a Size feature map (feature map ), output a Size feature map (when ,when ,when )

[0145] Will and Three new feature maps are obtained by splicing along the channel, namely Size feature map , Size feature map , Size feature map .

[0146] Based on the above, three feature maps ( , , ) outputs another three feature maps through the neighbor search module in the dual stream ( , , ). Its expression is as follows:

[0147]

[0148] The feature map output from the global capture module or the neighbor search module ( , , ) is again input to the constant flow ( Figure 2 The middle dotted box) is further processed to finally obtain three new feature maps ( , , ).

[0149] The process is as follows:

[0150] enter Size feature map (feature map ), output Size feature map (feature map ).

[0151] enter Size feature map (feature map ), output Size feature map (feature map ).

[0152] enter Size feature map (feature map ), output Size feature map (feature map ).

[0153] Based on the above, three feature maps ( , , ) outputs the final output through a constant flow ( , , ). Its expression is as follows:

[0154]

[0155] The loss function calculation for training anomaly detection model is as follows:

[0156]

[0157] Where n is the number of feature maps of different scales, N is the batch size, H, W and C represent the height, width and number of channels of each feature map respectively. represents the i-th batch, j-th row, k-th column, For each sample, the elements in all dimensions are squared and summed, and finally multiplied by Get the loss value.

[0158] The Jacobian (probability distribution) of each feature map (feature maps in the constant flow are not calculated) is calculated as follows

[0159]

[0160] in is the number of multi-scale feature maps, is the input feature map, and is the output feature map, Represents a matrix, that is, each element in the matrix represents The corresponding elements in The partial derivatives of the corresponding elements in . represents the calculation of the determinant of the matrix, Denotes taking the logarithm of the determinant.

[0161] Minimizing the negative log-likelihood is as follows:

[0162]

[0163] According to the above formula, the final total loss can be obtained for:

[0164]

[0165] in, Negative log-likelihood The value of the i-th element in .

[0166] In this embodiment, the MVTec AD dataset is used, which contains a total of 5354 color and gray images of 15 different types of objects (such as transistors, tiles, etc.). Each type contains a training set and a test set, in which the training set contains all normal images, while the test set contains normal images and some abnormal images. The purpose of this dataset is to train the model with the training set so that the model can recognize abnormal images from the test set during the test phase. In addition, the 15 different objects in the dataset are divided into two types, some of which are structural types and the other are texture types. Among them, the former is used for the global capture module, and the latter is used for the neighboring search module. Each category is tested separately, that is, after the model is trained, the model is tested immediately. When the test of this category is completed, continue to train the next category and then test it, and so on, until all 15 categories are detected.

[0167] The specific process of the anomaly detection training model stage is as follows:

[0168] (1) Sample acquisition and preprocessing: The MVTec AD dataset is used to obtain samples. The dataset is divided into a training set and a test set. In the training phase, samples are retrieved from the training set, and after a simple transformation, the samples are input into the pre-trained network WideResNet50 for feature extraction. Finally, the samples are input into the uniform pooling layer to obtain a multi-scale feature map.

[0169] (2) Model construction: Based on the probability distribution method, a back-tracing masked three-stream anomaly detection model is constructed, which consists of a cascade stream, a twin stream and a constant stream.

[0170] (3) Model compilation: The number of model training iterations is set to 100 and the batch size is 8. The model is trained using the AdamW optimizer with a learning rate of 0.0001 and an optimization objective of minimizing the negative log-likelihood.

[0171] (4) Model training and evaluation: The model is trained based on the above hyperparameters and, according to the above optimization objectives, the model is evaluated on the test set every 10 times to determine the performance of anomaly detection and localization.

[0172] Example 3.

[0173] The present invention also provides an industrial anomaly detection system, comprising:

[0174] The data acquisition module is used to acquire images to be detected for abnormalities.

[0175] The anomaly detection module is used to detect and locate anomalies based on the acquired images and the pre-trained anomaly detection model.

[0176] The anomaly detection model includes: a backbone network, a pooling layer, a cascade flow, a twin flow and a constant flow.

[0177] The cascade stream includes a plurality of stream blocks arranged in sequence.

[0178] The operations performed by the anomaly detection module include:

[0179] The image to be detected for anomaly is taken as input to obtain the feature map.

[0180] Based on the pooling layer, the feature map is used as input to obtain the compressed feature map .

[0181] Based on the cascade flow, the compressed feature map As input, we get the feature map A after cascade flow processing with stable values.

[0182] Based on the twin stream, the feature map A after cascade stream processing is used as input to further extract features, and the feature map with enriched contextual relationship is obtained after twin stream processing. .

[0183] Based on the constant flow, the feature map output after the dual stream processing As input, we get the feature map output after constant flow processing. .

[0184] The feature map output after constant flow processing Get the final located exception.

[0185] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0186] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0187] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0188] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. An industrial anomaly detection method, characterized in that: include: Acquire an image to be detected for anomalies; According to the acquired images, the anomalies are detected and located based on the pre-trained anomaly detection model; The anomaly detection model includes: a backbone network, a pooling layer, a cascade flow, a twin flow and a constant flow; The cascade flow includes a plurality of flow blocks arranged in sequence; The backbone network adopts WideResNet50; Based on the backbone network, the image to be detected for anomalies is taken as input to obtain a feature map; Based on the pooling layer, the feature map is used as input to obtain the compressed feature map ; Based on the cascade flow, the compressed feature map As input, obtain the feature map A after cascade flow processing with stable values; Based on the twin stream, the feature map A after cascade stream processing is used as input to further extract features, and the feature map with enriched contextual relationship is obtained after twin stream processing. ; Based on the constant flow, the feature map output after the dual stream processing As input, we get the feature map output after constant flow processing. ; The feature map output after constant flow processing Get the final located exception; Based on the backbone network, the image to be detected for anomalies is taken as input to obtain a feature map; Based on the pooling layer, the feature map is used as input to obtain the compressed feature map ; Based on the cascade flow, the compressed feature map As input, obtain the feature map A after cascade flow processing with stable values; Based on the twin stream, the feature map A after cascade stream processing is used as input to further extract features, and the feature map with enriched contextual relationship is obtained after twin stream processing. ; Based on the constant flow, the feature map output after the dual stream processing As input, we get the feature map output after constant flow processing. ; The feature map output after constant flow processing Get the final located exception; The stream block includes two parallel cascade sub-networks, and the cascade sub-network includes a convolution layer, a hierarchical normalization layer, an activation function ReLU, a traceable mask convolution layer, a hierarchical normalization layer, and an activation function ReLU arranged in sequence; Based on the stream block, the compressed feature map As input, the feature map After being split into two feature maps along the channel, they are input into two cascaded sub-networks respectively, and then the outputs of the two cascaded sub-networks are spliced ​​as the input of the next stream block, and so on, and finally the feature map A output after cascade stream processing is obtained. The expression is as follows: ; ; ; in, Represents cascade flow The i-th stream block in, m represents the number of stream blocks, represents the cascaded subnetwork in each flow block, Indicates that the convolution kernel is 3 3 convolutional layers of different sizes, is the hierarchical normalization layer, is the activation function, It is a traceable mask convolution layer; The traceable mask convolution layer processes the feature map output by the activation function ReLU of the previous layer. Split it into 4 new feature maps along the channel , , , , convolve each feature map with a masked convolution kernel to obtain 4 new feature maps , , , , where the mask positions of the four mask convolution kernels are the upper left corner, the upper right corner, the lower left corner, and the lower right corner. Finally, the four feature maps obtained are , , , Merge along the channel to get the masked feature map ; The dual substream includes a global capture module and a neighbor search module; The global capture module is used to process structure data, and the neighbor search module is used to process texture data; The global capture module includes: a downsampling layer, a first global sub-network, a second global sub-network, an upsampling layer and a skip connection; the first global sub-network includes a convolutional layer, a hierarchical normalization layer, an activation function ReLU and a convolutional layer arranged in sequence, and the first global sub-network has the same structure as the second global sub-network; When the processed data is structured data, based on the downsampling layer, feature map A is used as input to obtain the downsampled feature map D, and then feature map D is split into two new feature maps a and b along the channel. A and b are input into the first global sub-network and the second global sub-network respectively. In the first global sub-network and the second global sub-network, feature maps a and b are split along the channel respectively to obtain two new feature maps. , as well as , , and then , The output after the first global sub-network is concatenated to obtain the feature map a'. , The output after the second global sub-network is spliced ​​to obtain feature map b', and then the feature maps a' and b' are spliced ​​and upsampled by the upsampling module to obtain a feature map of the same size as feature map A. ; The expression is as follows: ; ; ; in, Represents the global capture module, and denote the first global subnetwork and the second global subnetwork respectively, is the upsampling layer, is the downsampling layer, Indicates that the convolution kernel is 3 3 convolutional layers of different sizes, is the hierarchical normalization layer, is the activation function ReLU, represents a skip connection; The neighbor search module includes a neighbor sub-network and a convolution layer; the neighbor sub-network includes a parameter initialization layer and a convolution layer; When the processed data is texture data, the feature map A is input into the neighboring search module, and two new feature maps r and s are split along the channel. The new feature maps r and s are then passed through the neighboring sub-network and convolutional layer in turn and then spliced ​​to obtain a new feature map. , the expression is as follows: ; ; in, represents the neighbor search module, is the initial layer of parameters; For the output of the twin stream, when processing structured data, Corresponding to the output of the global capture module; when processing texture data The output of the corresponding neighbor search module; The constant flow includes a plurality of constant flow blocks connected in sequence, and each constant flow block includes two constant subnetworks; The constant subnetwork includes convolution kernels arranged in sequence as 1 1 convolution layer with a convolution kernel of 3 3-size convolutional layers, hierarchical normalization layers, activation function LeakyReLU, downsampling layers, hierarchical normalization layers, convolution kernel size 3 3 convolutional layers, LeakyReLU activation function, upsampling layers, and skip connections; Based on the constant flow block, the feature map of the output of the two sub-streams After being split into two feature maps along the channel, they are input into two constant sub-networks respectively, and then the outputs of the two constant sub-networks are spliced ​​as the input of the next constant flow block, and so on, finally obtaining the feature map output after constant flow processing. , the expression is as follows: ; ; ; in, Indicates a steady flow The i-th constant flow block in , n represents the number of constant flow blocks, represents the constant subnetwork in each constant flow block, Indicates that the convolution kernel is 1 A convolutional layer of size 1, Represents the activation function LeakyReLU; The feature map output after constant flow processing The exceptions that get the final positioning include: The feature map output after constant flow processing Upsample to the size of the original image to get the feature map ,pass The library function takes the maximum value of the last dimension and the second-to-last dimension respectively. The expression is as follows: ; ; in, is the maximum value of the last dimension, is the maximum value of the second-to-last dimension, for The maximum value function in the library function; then the feature map minus Get feature map , as shown below: ; make , is an exponential function, Applied to the exponential function, we get a new feature map , the expression is as follows: ; Finally, the final anomaly map is obtained according to the following formula ; ; The abnormal graph The maximum pixel value in is taken as the anomaly score, and the points with anomaly scores exceeding the threshold are taken as outliers.

2. An industrial anomaly detection system, characterized in that: include: A data acquisition module, used to acquire images to be detected for abnormalities; Anomaly detection module, used to detect and locate anomalies based on the acquired images and the pre-trained anomaly detection model; The anomaly detection model includes: a backbone network, a pooling layer, a cascade flow, a twin flow and a constant flow; The cascade flow includes a plurality of flow blocks arranged in sequence; The backbone network adopts WideResNet50; Based on the backbone network, the image to be detected for anomalies is taken as input to obtain a feature map; Based on the pooling layer, the feature map is used as input to obtain the compressed feature map ; Based on the cascade flow, the compressed feature map As input, obtain the feature map A after cascade flow processing with stable values; Based on the twin stream, the feature map A after cascade stream processing is used as input to further extract features, and the feature map with enriched contextual relationship is obtained after twin stream processing. ; Based on the constant flow, the feature map output after the dual stream processing As input, we get the feature map output after constant flow processing. ; The feature map output after constant flow processing Get the final located exception; Based on the backbone network, the image to be detected for anomalies is taken as input to obtain a feature map; Based on the pooling layer, the feature map is used as input to obtain the compressed feature map ; Based on the cascade flow, the compressed feature map As input, obtain the feature map A after cascade flow processing with stable values; Based on the twin stream, the feature map A after cascade stream processing is used as input to further extract features, and the feature map with enriched contextual relationship is obtained after twin stream processing. ; Based on the constant flow, the feature map output after the dual stream processing As input, we get the feature map output after constant flow processing. ; The feature map output after constant flow processing Get the final located exception; The stream block includes two parallel cascade sub-networks, and the cascade sub-network includes a convolution layer, a hierarchical normalization layer, an activation function ReLU, a traceable mask convolution layer, a hierarchical normalization layer, and an activation function ReLU arranged in sequence; Based on the stream block, the compressed feature map As input, the feature map After being split into two feature maps along the channel, they are input into two cascaded sub-networks respectively, and then the outputs of the two cascaded sub-networks are spliced ​​as the input of the next stream block, and so on, and finally the feature map A output after cascade stream processing is obtained. The expression is as follows: ; ; ; in, Represents cascade flow The i-th stream block in, m represents the number of stream blocks, represents the cascaded subnetwork in each flow block, Indicates that the convolution kernel is 3 3 convolutional layers of different sizes, is the hierarchical normalization layer, is the activation function, It is a traceable mask convolution layer; The traceable mask convolution layer processes the feature map output by the activation function ReLU of the previous layer. Split it into 4 new feature maps along the channel , , , , convolve each feature map with a masked convolution kernel to obtain 4 new feature maps , , , , where the mask positions of the four mask convolution kernels are the upper left corner, the upper right corner, the lower left corner, and the lower right corner. Finally, the four feature maps obtained are , , , Merge along the channel to get the masked feature map ; The dual substream includes a global capture module and a neighbor search module; The global capture module is used to process structure data, and the neighbor search module is used to process texture data; The global capture module includes: a downsampling layer, a first global sub-network, a second global sub-network, an upsampling layer and a skip connection; the first global sub-network includes a convolutional layer, a hierarchical normalization layer, an activation function ReLU and a convolutional layer arranged in sequence, and the first global sub-network has the same structure as the second global sub-network; When the processed data is structured data, based on the downsampling layer, feature map A is used as input to obtain the downsampled feature map D, and then feature map D is split into two new feature maps a and b along the channel. A and b are input into the first global sub-network and the second global sub-network respectively. In the first global sub-network and the second global sub-network, feature maps a and b are split along the channel respectively to obtain two new feature maps. , as well as , , and then , The output after the first global sub-network is concatenated to obtain the feature map a'. , The output after the second global sub-network is spliced ​​to obtain feature map b', and then the feature maps a' and b' are spliced ​​and upsampled by the upsampling module to obtain a feature map of the same size as feature map A. ; The expression is as follows: ; ; ; in, Represents the global capture module, and denote the first global subnetwork and the second global subnetwork respectively, is the upsampling layer, is the downsampling layer, Indicates that the convolution kernel is 3 3 convolutional layers of different sizes, is the hierarchical normalization layer, is the activation function ReLU, represents a skip connection; The neighbor search module includes a neighbor sub-network and a convolution layer; the neighbor sub-network includes a parameter initialization layer and a convolution layer; When the processed data is texture data, the feature map A is input into the neighboring search module, and two new feature maps r and s are split along the channel. The new feature maps r and s are then passed through the neighboring sub-network and convolutional layer in turn and then spliced ​​to obtain a new feature map. , the expression is as follows: ; ; in, represents the neighbor search module, is the initial layer of parameters; For the output of the twin stream, when processing structured data, Corresponding to the output of the global capture module; when processing texture data The output of the corresponding neighbor search module; The constant flow includes a plurality of constant flow blocks connected in sequence, and each constant flow block includes two constant subnetworks; The constant subnetwork includes convolution kernels arranged in sequence as 1 1 convolution layer with a convolution kernel of 3 3-size convolutional layers, hierarchical normalization layers, activation function LeakyReLU, downsampling layers, hierarchical normalization layers, convolution kernel size 3 3 convolutional layers, LeakyReLU activation function, upsampling layers, and skip connections; Based on the constant flow block, the feature map of the output of the two sub-streams After being split into two feature maps along the channel, they are input into two constant sub-networks respectively, and then the outputs of the two constant sub-networks are spliced ​​as the input of the next constant flow block, and so on, finally obtaining the feature map output after constant flow processing. , the expression is as follows: ; ; ; in, Indicates a steady flow The i-th constant flow block in , n represents the number of constant flow blocks, represents the constant subnetwork in each constant flow block, Indicates that the convolution kernel is 1 A convolutional layer of size 1, Represents the activation function LeakyReLU; The feature map output after constant flow processing The exceptions that get the final positioning include: The feature map output after constant flow processing Upsample to the size of the original image to get the feature map ,pass The library function takes the maximum value of the last dimension and the second-to-last dimension respectively. The expression is as follows: ; ; in, is the maximum value of the last dimension, is the maximum value of the second-to-last dimension, for The maximum value function in the library function; then the feature map minus Get feature map , as shown below: ; make , is an exponential function, Applied to the exponential function, we get a new feature map , the expression is as follows: ; Finally, the final anomaly map is obtained according to the following formula ; ; The abnormal graph The maximum pixel value in is taken as the anomaly score, and the points with anomaly scores exceeding the threshold are taken as outliers.