Image anomaly detection method and system based on sparse completion network
Through the sparse tensor and sparse convolution technology of the sparse completion network, the problem of high computing resources of the existing image completion model is solved, and efficient image anomaly detection is achieved. It is especially suitable for shape anomaly detection, reducing calculation and storage overhead .
Patent Information
- Application Number
- CN202210602702.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-30
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2042-05-30
AI Technical Summary
The existing anomaly detection model based on image completion has high computational volume and memory overhead when computing resources are limited, making it difficult to effectively apply to shape anomaly detection.
Using a sparse completion network-based method, the selected pixels in the image are stored by sparse tensors and calculated using sparse convolution, an asymmetric autoencoder is constructed, and features are extracted only for effective pixels in the encoding stage and in the decoding stage. Decode only in the mask area, reducing calculation and storage overhead.
It significantly reduces the hardware calculation and storage overhead of the model, improves detection efficiency, and is suitable for visual abnormality tasks, especially in shape abnormality detection scenarios, and is effectively applicable to other image completion tasks.
Smart Images

Figure CN115049597B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of unsupervised anomaly detection, and in particular relates to an image anomaly detection method and system based on a sparse completion network. Background Art
[0002] Anomaly detection refers to finding abnormal samples or novel samples mixed in normal samples. It has a wide range of application scenarios, especially in situations where normal samples are easier to collect but abnormal samples are difficult to obtain. A typical application is automated product appearance defect detection. On a qualified production line, there are usually a large number of good products, but the defective samples and types that can be collected are often very scarce, making it difficult to train traditional supervised defect detection models; in addition, once a new type of defect appears on the production line, it is very likely to cause the supervised model to fail because it has not been seen during training. The anomaly detection model can solve this problem well: the model only needs normal samples during training and only captures the distribution of normal samples. When the sample to be tested deviates significantly from the distribution of normal samples, it will be regarded as an anomaly, so that it can theoretically be generalized to the detection of all types of defects.
[0003] Image reconstruction is widely used in the field of image anomaly detection. Its core assumption is that the reconstruction model trained on normal samples cannot accurately reconstruct abnormal samples, so anomaly detection and positioning are achieved by comparing reconstruction errors. This type of model usually uses a generative network. In order to ensure that the model can learn high semantic information of the image during the reconstruction process and avoid the generation of identity mapping, relevant scholars proposed to use image completion to construct an image reconstruction model: the image is covered by multiple masks in turn, and the network is trained to complete the mask area. Through image completion, the network only obtains a partial reconstructed image each time, and then replaces the mask until the sum of all masks can cover the entire image, thereby obtaining a complete image reconstruction result. Although the existing anomaly detection model based on image completion has been proven to be effective in multiple data sets, the high computational complexity and memory overhead of this type of model still restrict its application and expansion under limited computing resources. On the one hand, generative deep convolutional models usually have more convolutional layers to ensure the quality of reconstructed images; on the other hand, image completion models can only reconstruct part of the content of the image each time. Therefore, multiple calculations are required to reconstruct a complete image, whether in the training phase or the testing phase, which doubles the amount of calculation. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide an image anomaly detection method and system based on a sparse completion network in view of the deficiencies in the above-mentioned prior art. Sparse tensors are used to store selected pixels in the image. At the same time, sparse convolution is used to calculate only the specified pixels, which greatly reduces the calculation and storage overhead. The present invention particularly proposes an efficient shape completion network for shape anomaly detection and gives a corresponding anomaly evaluation method.
[0005] The present invention adopts the following technical solutions:
[0006] An image anomaly detection method based on sparse completion network.
[0007] A method for image anomaly detection based on a sparse completion network comprises the following steps:
[0008] S1. Construct a sparse completion network including an asymmetric autoencoder.
[0009] S2, using the training set images to train the sparse completion network built in step S1, and training the image completion task in a self-supervised manner on normal image samples based on the loss function of the sparse completion network in step S1;
[0010] S3. Input the test set image into the sparse completion network trained in step S2. Based on the anomaly scoring function of the sparse completion network in step S1, image-level anomaly detection and pixel-level anomaly location are achieved by measuring the accuracy of image completion.
[0011] Specifically, in step S1, constructing a sparse completion network including an asymmetric autoencoder is specifically as follows:
[0012] S101, constructing a sparse tensor using a dense image and an edge image, using the sparse tensor to store selected pixels in the image, and defining a sparse convolution to calculate the specified pixels;
[0013] S102, building a sparse autoencoder including an encoder, a decoder, and a long connection, using the sparse tensor and sparse convolution constructed in step S101 to extract features from valid pixels in the encoding stage; and decoding the content in the coverage mask area in the decoding stage;
[0014] S103. In the training phase, a loss function is designed to calculate the loss between the original image and the reconstructed image in step S102, and the sparse autoencoder in step S102 is trained by a back propagation algorithm. In the testing phase, an anomaly score function is designed to calculate the difference between the original image and the reconstructed image to obtain an anomaly score graph.
[0015] Furthermore, in step S101, the dense image is used to construct a sparse tensor as follows:
[0016] Cover the input image with a predefined mask, and use a sparse tensor to represent the input image covered with the mask. The sparse tensor only stores the uncovered pixels in the image, and the input sparse tensor T is obtained. 0 , when there is a flat background area in the image, remove T 0 The background pixels in the 0 Contains foreground pixels not covered by the mask;
[0017] The specific method of using edge images to construct sparse tensors is:
[0018] When the shape feature of the object to be tested is used as the basis for judging whether the product is abnormal, the edge pixels in the image are retained to simplify the original image and remove the sparse tensor T 0 Pixels in the non-edge area.
[0019] Furthermore, the input sparse tensor T 0 :
[0020] T 0 ={(x i ,y i ,f i )|(x i ,y i )∈C 0 ,f i ∈F 0}
[0021] Among them, C 0 is the pixel coordinate set, F 0 is a feature set, (x i ,y i ) is T 0 The two-dimensional coordinates of any pixel i in i T 0 The feature vector of any pixel i in .
[0022] Furthermore, in step S101, the sparse convolution is specifically:
[0023]
[0024] in, W is the feature vector of the input and output sparse tensor at coordinate u = (x, y); i is the weight value in the two-dimensional convolution kernel, i is the weight coordinate offset, is the feature vector of the input sparse tensor at the offset coordinate u+i, C in , C out are the coordinate sets of the input and output sparse tensors respectively.
[0025] Furthermore, in step S102, a long connection S is defined. skip as follows:
[0026] S skip =T n ∪S n
[0027] Among them, T n is the output tensor of the encoder module, S nis the output result of the decoding module.
[0028] Furthermore, the output tensor T of the encoder module n It is expressed as:
[0029] T n =E n (…E 2 (E 1 (T 0 )))
[0030] The output of the decoding module S n It is expressed as:
[0031] S n =D n-m (…E n-2 (E n-1 (T n )))
[0032] Where n>1, 1≤m <n,E n For each encoding module, T 0 is a sparse tensor, D n-m For each decoding module.
[0033] Furthermore, in step S103, for the dense image, a loss function L is constructed, and the reconstructed image obtained by the sparse completion network is compared with the original training image for loss calculation, and finally the multi-scale gradient similarity loss L is used. G Calculate the pixel-level anomaly localization map and take the maximum value in the localization map as the image-level anomaly detection map;
[0034] The loss function L is:
[0035] L=λ G L G +λ S L S +L2
[0036] Among them, λ G ,λ S is an adjustable hyperparameter, L G is the multi-scale gradient similarity loss, L S is the structural similarity loss.
[0037] Furthermore, in step S103, for the edge image, a loss function L is constructed, and the reconstructed edge image obtained by the sparse completion network The edge map I with the original training image e Loss calculation is performed, and morphological processing is used for abnormal evaluation, and the OTSU algorithm is used to extract with I e The edge point coordinate set C and Cr , and then the residual is calculated by the regional difference model to obtain the residual map P, and then the distance less than the hyperparameter S is closed by morphological closing operation clo The edge residuals of the image are connected, and the 8-neighborhood discrimination condition is used to divide the image into multiple connected domains. The areas where the area of the connected domain is smaller than the hyperparameter τ are regarded as noise and filtered out. In the final residual image, the eigenvalues of the points in the retained area are recorded as 1, and the remaining areas are recorded as 0, and the final abnormal distribution map is obtained;
[0038] The loss function L is:
[0039]
[0040] The residual graph P is:
[0041]
[0042] Where Dil(·) is a morphological dilation operation.
[0043] In a second aspect, an embodiment of the present invention provides an image anomaly detection system based on a sparse completion network, comprising:
[0044] The network module builds a sparse completion network including an asymmetric autoencoder;
[0045] The training module uses the training set images to train the sparse completion network built by the network module, and trains the image completion task in a self-supervised manner on normal image samples based on the loss function of the sparse completion network of the network module;
[0046] The detection module inputs the test set images into the sparse completion network trained by the training module. Based on the anomaly scoring function of the sparse completion network of the network module, it realizes image-level anomaly detection and pixel-level anomaly location by measuring the accuracy of image completion.
[0047] Compared with the prior art, the present invention has at least the following beneficial effects:
[0048] The present invention discloses an image anomaly detection method based on a sparse completion network, which uses sparse tensors and sparse convolutions to construct an asymmetric self-encoding image restoration network; in the training phase, the network only trains the image completion task in a self-supervised manner on normal image samples; in the testing phase, image-level anomaly detection and pixel-level anomaly positioning are achieved by measuring the accuracy of image completion; the core of the present invention is to use sparse tensors and sparse convolutions to extract features only from valid pixels in the encoding phase; and only decode the content in the coverage mask area in the decoding phase. The asymmetric self-encoder constructed in this way greatly reduces the hardware calculation and storage overhead of the model; it can be effectively applied to visual anomaly tasks. Compared with the traditional image completion network, the present invention uses sparse tensors and sparse convolutions to only calculate specific pixels, thereby improving the detection efficiency.
[0049] Furthermore, since the image area covered by the mask no longer has valid information in the encoding stage, the encoder of the present invention only encodes the pixels in the non-masked area; in the decoding stage, since only the repaired masked area needs to be retained in the end, the decoder of the present invention only projects the potential representation output by the encoder to the masked area. Through such an asymmetric autoencoder setting, the computational redundancy of the traditional autoencoder in the image completion task is reduced.
[0050] Furthermore, compared to the traditional two-dimensional matrix image representation, using sparse tensors to represent dense images can avoid storing redundant pixels, including mask pixels and flat background pixels in the original covered image. When performing anomaly detection through edge images, since sparse tensors only store uncovered edge pixels, the number of pixels in the image is further reduced.
[0051] Furthermore, the sparse tensor is represented as pixel coordinates and eigenvalues at the corresponding coordinates, so that sparse convolution can be used to perform operations only on specific coordinates, thereby improving detection efficiency.
[0052] Furthermore, sparse convolution only performs convolution operations on pixels at specified coordinates, avoiding redundant calculations of traditional convolution when processing sparse data.
[0053] Furthermore, the design of long connections can promote network convergence and avoid gradient vanishing; at the same time, it can effectively integrate multi-layer semantic features and improve its performance on fine-grained tasks.
[0054] Furthermore, the encoder uses sparse submanifold convolution and sparse strided convolution to output the tensor T in the process of continuous convolution and downsampling. n No additional pixels will be included; the decoder uses sparse deconvolution to make S nIt will only fall in the mask area, thereby avoiding the generation of additional decoding content. Compared with the traditional encoder and decoder output, the encoder and decoder output of the present invention has the advantages of outputting feature maps and smaller calculation amount, that is, reducing memory and floating point operation consumption.
[0055] Furthermore, the loss function can effectively improve the fidelity of image reconstruction. In particular, multi-scale gradient loss, as a regional metric function, can better help the model focus on local structural information rather than the difference of a single pixel. At the same time, under the guidance of gradient information, the network can more effectively reconstruct high-frequency detail areas. At the same time, using multi-scale gradient functions to calculate anomaly localization maps can effectively adapt to anomaly detection tasks in different scenarios, because multi-scale gradient information can effectively reflect the structural information of the object.
[0056] Furthermore, for edge images, since their features are simple, L2 loss can be used to effectively guide network training; the anomaly assessment algorithm designed by the present invention reduces the reconstruction error by binarizing the reconstruction results, and avoids the influence of reconstruction artifact areas through morphological processing. It has been verified that the loss function and anomaly assessment function proposed by the method can be effectively applied to the detection of shape abnormal images.
[0057] It can be understood that the beneficial effects of the second aspect mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.
[0058] In summary, the detection method of the present invention is applied to visual anomaly detection tasks, and has the advantages of good detection effect, high detection efficiency, and easy introduction of prior knowledge (such as shape anomaly detection); at the same time, the completion network proposed in the invention is not only suitable for anomaly detection, but can also be applied to other image completion tasks in the future.
[0059] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 Design a flow chart for the sparse completion network of the present invention;
[0061] Figure 2 It is a detection flow chart of the present invention;
[0062] Figure 3 Create a flow graph for sparse tensors;
[0063] Figure 4 This is a schematic diagram of the edge difference between a normal printed product and a defective printed product;
[0064] Figure 5 Schematic diagram of the offset in a 3×3 standard convolution kernel;
[0065] Figure 6A comparison chart between traditional convolutional autoencoders and sparse completion networks;
[0066] Figure 7 This is a comparison chart between ordinary convolution and sparse convolution;
[0067] Figure 8 Schematic diagram of abnormality evaluation for edge images, where (a) is the original dense image, (b) is the original edge image, (c) is the reconstructed edge image, (d) is the residual result image, (e) is the result image after morphological closing operation, and (f) is the final detection result image. DETAILED DESCRIPTION
[0068] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are 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 are within the scope of protection of the present invention.
[0069] In the description of the present invention, it should be understood that the terms “include” and “comprises” indicate the presence of described features, wholes, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or collections thereof.
[0070] It should also be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0071] It should be further understood that the term "and / or" used in the present specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes these combinations. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects are in an "or" relationship.
[0072] It should be understood that, although the terms first, second, third, etc. may be used to describe preset ranges, etc. in the embodiments of the present invention, these preset ranges should not be limited to these terms. These terms are only used to distinguish preset ranges from each other. For example, without departing from the scope of the embodiments of the present invention, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.
[0073] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0074] Various structural schematic diagrams of the embodiments disclosed in the present invention are shown in the accompanying drawings. These figures are not drawn to scale, and some details are magnified and some details may be omitted for the purpose of clear expression. The shapes of various regions and layers shown in the figures and the relative sizes and positional relationships therebetween are only exemplary, and may deviate in practice due to manufacturing tolerances or technical limitations, and those skilled in the art may additionally design regions / layers with different shapes, sizes, and relative positions according to actual needs.
[0075] The present invention provides an image anomaly detection method based on a sparse completion network, which uses sparse tensors and sparse convolutions to construct an asymmetric self-encoding image restoration network; in the training phase, the network only trains the image completion task in a self-supervised manner on normal image samples; in the testing phase, image-level anomaly detection and pixel-level anomaly positioning are achieved by measuring the accuracy of image completion; the core of the present invention is to use sparse tensors and sparse convolutions to extract features only from valid pixels in the encoding phase; in the decoding phase, only the content is decoded in the coverage mask area. The asymmetric autoencoder constructed in this way greatly reduces the hardware calculation and storage overhead of the model; in addition, for shape anomaly detection, the present invention uses sparse convolutions and edge images to design an edge completion network, which further improves the detection efficiency of the model in specific scenarios.
[0076] The present invention provides an image anomaly detection method based on a sparse completion network, and the specific steps are as follows:
[0077] S1. Construct a sparse completion network. The sparse completion network uses an asymmetric autoencoder. In the encoding stage, only the uncovered, non-background pixels, and even non-edge pixels (only the pixels of the shape anomaly detection scene) are encoded; in the decoding stage, only the representation extracted by the encoder is decoded in the covered mask area;
[0078] See also Figure 1 , the sparse completion network includes: sparse tensor I, sparse autoencoder II, and loss function and anomaly scoring function III. Among them, sparse tensor I and loss function and anomaly scoring function III both consider dense images and edge images, and sparse autoencoder II includes encoder, decoder, and long connection module.
[0079] S101, constructing a sparse tensor and a sparse convolution, using the sparse tensor to store selected pixels in the image, and using the sparse convolution to calculate the specified pixels;
[0080] Use dense images to construct sparse tensor I, specifically:
[0081] For an input image, first cover the input image with a predefined mask;
[0082] Since natural images are information-intensive, they are usually represented as two-dimensional matrices or two-dimensional tensors. When an image is covered with a mask, the covered pixels no longer have valid information, so the traditional matrix or tensor representation becomes redundant. Therefore, a sparse tensor is used to represent the input image covered with a mask. The sparse tensor only stores the uncovered pixels in the image, such as Figure 3 As shown in Ⅰ, it specifically includes the pixel coordinate set C 0 and the feature set F under the corresponding coordinates 0 , thus obtaining the input sparse tensor T 0 :
[0083] T 0 ={(x i ,y i ,f i )|(x i ,y i )∈C 0 ,f i ∈F 0} (1)
[0084] In certain scenarios, for the sparse tensor T 0 When the original image has a relatively flat background, since the differences between these background pixels are small and contain less information, the present invention proposes to remove T 0 To further improve the computational efficiency, Figure 3 As shown in Ⅱ.
[0085] This operation is implemented by grayscale thresholding. At this time, the sparse tensor T 0 Only foreground pixels not covered by the mask are retained.
[0086] Experiments have shown that even if features are extracted only from foreground pixels, the network can still effectively reconstruct the complete image while reducing computational and storage consumption.
[0087] Use the edge image to create a sparse tensor I, specifically:
[0088] When the shape feature of the object to be tested can be used as the main basis for judging whether the product is abnormal, the edge pixels in the image are retained to simplify the original image, that is, the sparse tensor T is removed. 0The non-edge area pixels in Figure 3 As shown in Figure III.
[0089] At this time, the sparse tensor T 0 Only edge pixels not covered by the mask are included in the image, which greatly reduces the corresponding amount of calculation. This method is suitable for anomaly detection in the printing industry or object shape anomaly detection under backlight imaging.
[0090] See also Figure 4 , showing several printed defects, reflecting that edge differences can be the main basis for identifying printed defects.
[0091] The definition of sparse convolution in the sparse completion network is as follows:
[0092] Unlike traditional convolution, which calculates the entire image, sparse convolution only calculates specified pixels. Here, the general sparse convolution expression in the two-dimensional plane is used:
[0093]
[0094] in, is the feature vector of the input and output sparse tensor at coordinate u = (x, y); W i is the weight value in the two-dimensional convolution kernel, and i is the weight coordinate offset.
[0095] For example, for a standard 3×3 convolution kernel, there will be nine offsets, specifically {(-1,-1),(-1,0),…,(1,0),(0,1)}, such as Figure 5 As shown. Only the calculation exists in O(u,C in ) in the .
[0096] O(u,C in ) is restricted to the coordinates of the input pixels:
[0097] O(u,C in )={i|u+i∈C in} (3)
[0098] At the same time, because u∈C out , so O(u,C in ) is also limited to the output coordinates. That is, if the output coordinates are specified in advance, sparse convolution will only produce calculation results under those coordinates.
[0099] S102, building a sparse autoencoder including an encoder, a decoder, and a long connection, using the sparse tensor and sparse convolution constructed in step S101 to extract features from valid pixels in the encoding stage; and decoding the content in the coverage mask area in the decoding stage;
[0100] The specific structure of sparse autoencoder II is:
[0101] See also Figure 6 Compared with the traditional convolutional autoencoder, the sparse completion network uses sparse convolution and sparse tensor to construct an asymmetric autoencoder. The traditional convolutional autoencoder calculates the entire image in both the encoding and decoding stages, which results in a lot of computational redundancy:
[0102] During the encoding stage, the traditional encoder calculates the covered mask area, but the mask pixels actually have no valid information;
[0103] In the decoding stage, the traditional decoder projects the latent representation onto the entire image, while the ultimate goal of the image completion task is only to repair the area covered by the mask, not the entire image.
[0104] In contrast, the network proposed in this invention only calculates specific pixels in both the encoding and decoding stages:
[0105] When encoding, only non-masked pixels are calculated; when decoding, only masked pixels are fitted.
[0106] This greatly improves the detection efficiency. To achieve this function, three types of sparse convolution are used, including sparse submanifold convolution, sparse strided convolution, and sparse deconvolution. The comparison between them and the corresponding ordinary convolution is as follows: Figure 7 shown.
[0107] The sparse encoder is specifically:
[0108] Since the pixels in the mask area do not have effective features, the sparse encoder only extracts T 0 We use sparse submanifold convolution and sparse strided convolution to construct each encoder module E n (·). For sparse submanifold convolution, the input feature coordinates are always equal to the output feature coordinates, that is, C out =C in ,like Figure 6 As shown in Ⅰ, the convolution can maintain the sparse structure of the feature map. For sparse strided convolution, it only downsamples the valid pixels, as shown in Figure 6 As shown in Ⅱ, this convolution will reduce the output coordinates while expanding the receptive field corresponding to each coordinate; finally, the output tensor T of each encoder module n It is expressed as:
[0109] T n =E n (…E 2 (E 1 (T0 ))),n>1 (4)
[0110] The sparse decoder is specifically:
[0111] Since the image completion model ultimately retains only the inpainted area, the sparse decoder only projects the potential representation extracted by the encoder onto the covered pixel coordinates C M Place.
[0112] Specifically, for each decoding module D(·), features are only decoded at mask coordinates with the same downsampling ratio as it. Where Figure 6 The specific implementation method is to replace Set to:
[0113]
[0114] Finally, the output result S of each decoding module is n It is expressed as:
[0115] S n =D n-m (…E n-2 (E n-1 (T n ))),1≤m <n (6)
[0116] The specific long connection is:
[0117] Since the encoder and decoder proposed in the present invention are asymmetric, the design of the skip connection in the present invention is different from that of the traditional U-Net network. For the sparse tensor T in equations (4) and (6), n , S n , long connection module design is realized by merging its collections, such as:
[0118] S skip =T n ∪S n (7)
[0119] If there are overlapping pixels (due to rounding during downsampling), add the eigenvalues at the same coordinates.
[0120] S103, loss function and anomaly scoring function.
[0121] For dense images, the reconstructed image obtained by the sparse completion network is compared with the original training image for loss calculation. Here, the multi-scale gradient similarity (MSGMS) loss L is used. G , structural similarity (SSIM) loss L S , and L2 loss to construct the network loss function L, we have:
[0122] L=λ G L G +λ S L S +L2 (8)
[0123] Among them, λ G ,λ S is an adjustable hyperparameter.
[0124] Finally through L G Calculate the pixel-level anomaly localization map and take the maximum value in the localization map as the image-level anomaly detection map
[0125] For edge images, the reconstructed edge map obtained by the sparse completion network The edge map I with the original training image e To calculate the loss, only L2 loss is used here, specifically:
[0126]
[0127] For abnormal evaluation, morphological processing is used. First, the OTSU algorithm is used to extract with I e The edge point coordinate set C and C r , and then calculate their residuals through the regional difference model. For any coordinate set C1 and C2, the regional difference operation It is expressed as:
[0128]
[0129] The residual graph P is obtained as follows:
[0130]
[0131] Among them, Dil(·) is a morphological dilation operation, the purpose of which is to eliminate reconstruction artifacts at the edge; then the morphological closing operation is used to close the distance less than the hyperparameter S clo The edge residual connection is connected, and the image is divided into multiple connected domains using the 8-neighborhood discrimination condition. The areas where the area of the connected domain is smaller than the hyperparameter τ are regarded as noise and filtered out. In the final residual image obtained, the eigenvalues of the points in the retained area are recorded as 1, and the remaining areas are recorded as 0, and the final abnormal distribution map is obtained; the whole process is as follows Figure 8 shown.
[0132] S2, using the training set images to train the sparse completion network built in step S1, and training the image completion task in a self-supervised manner on normal image samples based on the loss function of the sparse completion network in step S1;
[0133] See also Figure 2 , the training phase process is as follows:
[0134] Cover the original training set image with a mask, use the autoencoder network to repair the masked area of the image, and keep the repair result as the image reconstruction content. Calculate the loss of the reconstructed image and the original image, and train the network through back propagation.
[0135] S3. Input the test set image into the sparse completion network trained in step S2. Based on the anomaly scoring function of the sparse completion network in step S1, image-level anomaly detection and pixel-level anomaly location are achieved by measuring the accuracy of image completion.
[0136] See also Figure 2 , the specific process of the testing phase is:
[0137] The image to be tested is covered with a mask, and the mask is repaired through the trained repair network. The repaired area is retained as the reconstructed image, and the difference between the original image to be tested and the reconstructed image to be tested is calculated through the anomaly evaluation function, and the difference value is used as the anomaly detection result.
[0138] In another embodiment of the present invention, a sparse completion network-based image anomaly detection system is provided, which can be used to implement the above-mentioned sparse completion network-based image anomaly detection method. Specifically, the sparse completion network-based image anomaly detection system includes a network module, a training module and a detection module.
[0139] Among them, the network module builds a sparse completion network including an asymmetric autoencoder;
[0140] The training module uses the training set images to train the sparse completion network built by the network module, and trains the image completion task in a self-supervised manner on normal image samples based on the loss function of the sparse completion network of the network module;
[0141] The detection module inputs the test set images into the sparse completion network trained by the training module. Based on the anomaly scoring function of the sparse completion network of the network module, it realizes image-level anomaly detection and pixel-level anomaly location by measuring the accuracy of image completion.
[0142] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions 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 part of the embodiments of the present invention, rather than all of the embodiments. The components of the embodiments of the present invention described and shown in the drawings here can usually be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0143] The present invention has been verified on the public dataset MVTec AD and has been proven to be effective. The results of anomaly detection and localization are shown in Table 1. The evaluation standard selected is ROC AUC% (Area under receiver operating characteristic), which is a common standard in the field of anomaly detection. At the same time, in terms of detection efficiency, compared with the previous optimal model based on image completion anomaly detection, this method only uses less than one-seventh of the floating-point operations and less than one-quarter of the memory consumption.
[0144] Table 1. Comparison of the results of anomaly detection tasks on the MVTec AD dataset using the proposed method and the existing optimal anomaly detection algorithm based on image completion
[0145]
[0146]
[0147] Table 2. Comparison of the anomaly segmentation task results of the proposed method and the existing optimal anomaly detection algorithm based on image completion on the MVTec AD dataset
[0148]
[0149]
[0150] As can be seen from Table 2, the algorithm proposed in the present invention is superior to the existing optimal anomaly detection model based on image completion, which proves the effectiveness of the present invention.
[0151] In summary, the present invention provides an image anomaly detection method and system based on a sparse completion network, which is applied to visual anomaly detection tasks. The invention has the advantages of good detection effect, high detection efficiency, and convenient introduction of prior knowledge (such as shape anomaly detection). At the same time, the completion network proposed in the invention is not only suitable for anomaly detection, but can also be applied to other image completion tasks in the future.
[0152] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0153] The present application 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 box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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.
[0154] 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 comprising 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.
[0155] 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. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0156] The above contents are only for explaining the technical idea of the present invention and cannot be used to limit the protection scope of the present invention. Any changes made on the basis of the technical solution in accordance with the technical idea proposed by the present invention shall fall within the protection scope of the claims of the present invention.
Claims
1. An image anomaly detection method based on sparse completion network, It is characterized in that The following steps are involved: S1. Construct a sparse completion network including an asymmetric autoencoder. Construct a sparse completion network including an asymmetric autoencoder as follows: S101, constructing a sparse tensor using a dense image and an edge image, using the sparse tensor to store selected pixels in the image, and defining a sparse convolution to calculate the specified pixels; S102, building a sparse autoencoder including an encoder, a decoder, and a long connection, and using the sparse tensor and sparse convolution constructed in step S101 to extract features of effective pixels in the encoding stage; Decoding the content in the coverage mask area during the decoding phase; S103, in the training phase, a loss function is designed to calculate the loss of the original image and the reconstructed image in step S102, and the sparse autoencoder in step S102 is trained by a back propagation algorithm; In the test phase, an anomaly scoring function is designed to calculate the difference between the original image and the reconstructed image, and an anomaly scoring graph is obtained. For dense images, a loss function L is constructed, and the loss is calculated between the reconstructed image obtained by the sparse completion network and the original training image. Finally, the multi-scale gradient similarity loss L is used. G Calculate the pixel-level anomaly localization map and take the maximum value in the localization map as the image-level anomaly detection map; The loss function L is: L=λ G L G +λ S L S +L 2 Among them, λ G ,λ S is an adjustable hyperparameter, L G is the multi-scale gradient similarity loss, L S is the structural similarity loss; For the edge image, construct the loss function L, and the reconstructed edge map obtained by the sparse completion network The edge map I with the original training image e Loss calculation is performed, and morphological processing is used for abnormal evaluation, and the OTSU algorithm is used to extract with I e The edge point coordinate set C and C r , and then the residual is calculated through the regional difference model to obtain the residual map Then, the morphological closing operation is performed to close the distances less than the hyperparameter S clo The edge residuals of the image are connected, and the 8-neighborhood discrimination condition is used to divide the image into multiple connected domains. The areas where the area of the connected domain is smaller than the hyperparameter τ are regarded as noise and filtered out. In the final residual image, the eigenvalues of the points in the retained area are recorded as 1, and the remaining areas are recorded as 0, and the final abnormal distribution map is obtained; The loss function L is: Residual plot for: Among them, Dil(·) is the morphological dilation operation; S2, using the training set images to train the sparse completion network built in step S1, and training the image completion task in a self-supervised manner on normal image samples based on the loss function of the sparse completion network in step S1; S3. Input the test set image into the sparse completion network trained in step S2. Based on the anomaly scoring function of the sparse completion network in step S1, image-level anomaly detection and pixel-level anomaly location are achieved by measuring the accuracy of image completion.
2. The image anomaly detection method based on sparse completion network according to claim 1, It is characterized in that In step S101, the dense image is used to construct a sparse tensor as follows: Cover the input image with a predefined mask, and use a sparse tensor to represent the input image covered with the mask. The sparse tensor only stores the uncovered pixels in the image, and the input sparse tensor T is obtained. 0 , when there is a flat background area in the image, remove T 0 The background pixels in the 0 Contains foreground pixels not covered by the mask; The specific method of using edge images to construct sparse tensors is: When the shape feature of the object to be tested is used as the basis for judging whether the product is abnormal, the edge pixels in the image are retained to simplify the original image and remove the sparse tensor T 0 Pixels in the non-edge area.
3. The image anomaly detection method based on sparse completion network according to claim 2, It is characterized in that Input sparse tensor T 0 : T 0 ={(x i ,y i ,f i )|(x i ,y i )∈C 0 ,f i ∈F 0 } Among them, C 0 is the pixel coordinate set, F 0 is a feature set, (x i ,y i ) is f 0 The two-dimensional coordinates of any pixel i in i T 0 The feature vector of any pixel i in .
4. The image anomaly detection method based on sparse completion network according to claim 1, It is characterized in that In step S101, the sparse convolution is specifically as follows: in, is the feature vector of the input and output sparse tensor at coordinate u = (x, y); W i is the weight value in the two-dimensional convolution kernel, i is the weight coordinate offset, is the feature vector of the input sparse tensor at the offset coordinate u+i, C in , C out are the coordinate sets of the input and output sparse tensors respectively.
5. The image anomaly detection method based on sparse completion network according to claim 1, It is characterized in that In step S102, define a long connection S skip as follows: S skip =T n ∪S n Among them, T n is the output tensor of the encoder module, S n is the output result of the decoding module.
6. The image anomaly detection method based on sparse completion network according to claim 5, It is characterized in that The output tensor T of the encoder module n It is expressed as: T n =E n (…E 2 (E 1 (T 0 ))) The output of the decoding module S n It is expressed as: S n =D n-m (…E n-2 (E n-1 (T n ))) Where n>1, 1≤m<n, En is each encoding module, T 0 is a sparse tensor, D n-m For each decoding module.
7. An image anomaly detection system based on sparse completion network, It is characterized in that include: Network module, constructing a sparse completion network including an asymmetric autoencoder. The specific steps of constructing a sparse completion network including an asymmetric autoencoder are as follows: A sparse tensor is constructed using a dense image and an edge image, the sparse tensor is used to store selected pixels in the image, and a sparse convolution is defined to calculate the specified pixels; Build a sparse autoencoder including an encoder, a decoder, and a long connection, and use the constructed sparse tensor and sparse convolution to extract features from valid pixels in the encoding stage; Decoding the content in the coverage mask area during the decoding phase; In the training phase, a loss function is designed to calculate the loss of the original image and the reconstructed image, and the sparse autoencoder is trained through the back-propagation algorithm; In the test phase, an anomaly scoring function is designed to calculate the difference between the original image and the reconstructed image, and an anomaly scoring graph is obtained. For dense images, a loss function L is constructed, and the loss is calculated between the reconstructed image obtained by the sparse completion network and the original training image. Finally, the multi-scale gradient similarity loss L is used. G Calculate the pixel-level anomaly localization map and take the maximum value in the localization map as the image-level anomaly detection map; The loss function L is: L=λ G L G +λ S L S +L 2 Among them, λ G ,λ S is an adjustable hyperparameter, L G is the multi-scale gradient similarity loss, L S is the structural similarity loss; For the edge image, construct the loss function L, and the reconstructed edge map obtained by the sparse completion network The edge map I with the original training image e Loss calculation is performed, and morphological processing is used for abnormal evaluation, and the OTSU algorithm is used to extract with I e The edge point coordinate set C and C r , and then the residual is calculated through the regional difference model to obtain the residual map Then, the morphological closing operation is performed to close the distances less than the hyperparameter S clo The edge residuals of the image are connected, and the 8-neighborhood discrimination condition is used to divide the image into multiple connected domains. The areas where the area of the connected domain is smaller than the hyperparameter τ are regarded as noise and filtered out. In the final residual image, the eigenvalues of the points in the retained area are recorded as 1, and the remaining areas are recorded as 0, and the final abnormal distribution map is obtained; The loss function L is: Residual plot for: Among them, Dil(·) is the morphological dilation operation; The training module uses the training set images to train the sparse completion network built by the network module, and trains the image completion task in a self-supervised manner on normal image samples based on the loss function of the sparse completion network of the network module; The detection module inputs the test set images into the sparse completion network trained by the training module. Based on the anomaly scoring function of the sparse completion network of the network module, it realizes image-level anomaly detection and pixel-level anomaly location by measuring the accuracy of image completion.
