Anomaly detection method and apparatus, and electronic device and storage medium
Through multi-scale image feature extraction and normalized stream processing anomaly detection model, the problem of difficulty in setting the search speed and threshold in the prior art is solved, and efficient and accurate anomaly detection is achieved, suitable for complex backgrounds and high-resolution scenarios.
Patent Information
- Application Number
- PCT/CN2024/141026
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-27
- Filing Date
- 2024-12-20
- Publication Date
- 2025-07-03
AI Technical Summary
The existing anomaly detection methods are greatly affected by the pre-trained network model, and the feature dimensions affect the retrieval speed, and it is impossible to accurately distinguish abnormal textures from normal textures, resulting in difficulty in setting thresholds.
An abnormality detection model using multi-scale image feature extraction and normalized stream processing is used to map the image features to be tested to the latent space through the initial feature extraction network, stacked stream network and feature merging network, and the abnormal area is determined through comparison with the feature library.
It improves the accuracy and efficiency of abnormal detection, is suitable for scenes with variable backgrounds, can detect abnormalities at high resolution, and reduces interference from background information.
Smart Images

Figure CN2024141026_03072025_PF_FP_ABST
Abstract
Description
Abnormality detection method and device, electronic device and storage medium
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on December 27, 2023, with application number 202311814369.1 and invention name “Abnormality detection method and device, electronic device and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of image processing technology, and more specifically to an anomaly detection method, an anomaly detection device, an electronic device, and a storage medium. Background Art
[0003] Anomaly detection has a wide range of applications in the industrial field. Existing anomaly detection methods usually only need to collect a small amount of labeled data to detect unknown anomalies. For example, feature comparison algorithms (such as PatchCore) can extract features from labeled data based on the ImageNet pre-trained network model to generate a feature library. However, the feature library is greatly affected by the pre-trained network model, and the feature dimension also affects the retrieval speed of the feature library. In addition, the features extracted by the open source pre-trained network model are not necessarily applicable to detailed textures. Due to the rich variation in texture morphology, the features extracted from normal textures may be larger than the features extracted from abnormal textures in terms of distance measurement. Therefore, it is impossible to determine the appropriate threshold to accurately distinguish abnormal textures from normal textures. Summary of the Invention
[0004] In view of the above problems, the present application is proposed. The present application provides an anomaly detection method, an anomaly detection device, an electronic device and a storage medium.
[0005] According to one aspect of the present application, a method for abnormality detection is provided, comprising: obtaining an image to be tested, the image to be tested including a target object; inputting the image to be tested into a feature extraction module in a trained abnormality detection model to obtain target image features; inputting the target image features into an abnormality judgment module in the trained abnormality detection model to obtain an abnormality detection result of the target object, the abnormality detection result being used to indicate whether there is an abnormal area of the target object; wherein the feature extraction module is used to extract multi-scale image features of the image to be tested and convert the multi-scale image features into target image features of a preset scale through normalized stream processing, and the abnormality judgment module is used to compare the target image features output by the feature extraction module with a feature library to determine the abnormality detection result, wherein the feature library is a sample feature library obtained after the feature extraction module performs feature extraction on multiple first sample images.
[0006] In one possible implementation, the feature extraction module includes an initial feature extraction network, a stacked flow network, and a feature merging network. The image to be tested is input into the feature extraction module in the trained anomaly detection model to obtain target image features, including: inputting the image to be tested into the initial feature extraction network to obtain a first image feature, and the feature scale corresponding to the first image feature is multi-scale; inputting the first image feature into the stacked flow network, mapping the first image feature to a latent space through the stacked flow network to obtain a second image feature, and the second image feature has the same feature scale as the first image feature; inputting the second image feature into the feature merging network to obtain the target image feature; wherein the stacked flow network and the feature merging network are used to perform normalized flow processing.
[0007] In one possible implementation, the image to be tested includes multiple image blocks, and the image to be tested is input into an initial feature extraction network to obtain a first image feature, including: inputting the multiple image blocks into the initial feature extraction network respectively to obtain first image block features corresponding to each of the multiple image blocks, wherein the first image feature includes first image block features corresponding to each of the multiple image blocks; inputting the first image feature into a stacked flow network, and mapping the first image feature to a latent space through the stacked flow network to obtain a second image block feature corresponding to each of the multiple image blocks, wherein the second image feature includes second image block features corresponding to each of the multiple image blocks; inputting the second image feature into a feature merging network to obtain a target image feature, including: inputting the second image block features corresponding to each of the multiple image blocks into the feature merging network to obtain a target image block feature corresponding to each of the multiple image blocks, wherein the target image feature includes target image block features corresponding to each of the multiple image blocks.
[0008] In one possible implementation, the target image features are input into an anomaly judgment module in a trained anomaly detection model to obtain an anomaly detection result of the target object, including: calculating the distance between the target image features and the reference image features in the feature library through the anomaly judgment module; when the distance is greater than or equal to a first distance threshold, determining that an abnormal area exists in the target object.
[0009] In one possible implementation, a feature library includes reference image block features corresponding to each of a plurality of image positions, and the target image features are input into an anomaly judgment module in a trained anomaly detection model to obtain an anomaly detection result of the target object, including: for each of the plurality of image blocks, calculating, by the anomaly judgment module, a distance between the target image block feature corresponding to the image block and a specific reference image block feature in the feature library, where the specific reference image block feature is a reference image block feature corresponding to the image position where the image block is located; and when the distance is greater than or equal to a second distance threshold, determining that an abnormal area exists within the image block.
[0010] In one possible implementation, the trained anomaly detection model is trained in the following manner: obtaining multiple second sample images; inputting the multiple second sample images into a feature extraction module in the anomaly detection model to be trained respectively to obtain sample image features corresponding to each of the multiple second sample images; calculating a predicted loss value based on the difference between the sample image features corresponding to each of the multiple second sample images; and optimizing the parameters in the feature extraction module in the anomaly detection model to be trained based on the predicted loss value to obtain a trained anomaly detection model.
[0011] In one possible implementation, the trained anomaly detection model is trained in the following manner: obtaining a plurality of second sample images; inputting the plurality of second sample images into a feature extraction module in the anomaly detection model to be trained, respectively, to obtain sample image features output by a stacked flow network corresponding to each of the plurality of second sample images, the sample image features including multi-scale sub-sample image features; calculating a prediction loss value based on the difference between the sample image features corresponding to each of the plurality of second sample images; optimizing the parameters in the feature extraction module in the anomaly detection model to be trained based on the prediction loss value to obtain a trained anomaly detection model; wherein, calculating the prediction loss value based on the difference between the sample image features corresponding to each of the plurality of second sample images comprises: for each characteristic scale of the sample image feature, calculating the sub-prediction loss value at the characteristic scale based on the difference between the sub-sample image features at the characteristic scale corresponding to each of the plurality of second sample images; summing or averaging the sub-prediction loss values at all characteristic scales of the sample image feature to obtain the prediction loss value.
[0012] In a possible implementation, when summing or averaging the sub-prediction loss values at all feature scales of the sample image feature, the sub-prediction loss values at different feature scales have different weight factors.
[0013] In one possible implementation, before inputting the target image features into the anomaly judgment module in the trained anomaly detection model to obtain the anomaly detection results of the target object, the method also includes: obtaining multiple first sample images; inputting the multiple first sample images into the feature extraction module in the trained anomaly detection model respectively to obtain sample image features corresponding to each of the multiple first sample images; clustering the sample image features corresponding to each of the multiple first sample images; retaining the representative sample image features in each cluster group obtained by clustering as reference image features to obtain a feature library.
[0014] According to another aspect of the present application, an anomaly detection device is also provided, including: an acquisition module, used to acquire an image to be tested, wherein the image to be tested includes a target object; a first input module, used to input the image to be tested into a feature extraction module in a trained anomaly detection model to obtain target image features; a second input module, used to input the target image features into an anomaly judgment module in the trained anomaly detection model to obtain an anomaly detection result of the target object, wherein the anomaly detection result is used to indicate whether there is an abnormal area of the target object; wherein the feature extraction module is used to extract multi-scale image features of the image to be tested and convert the multi-scale image features into target image features of a preset scale through normalized stream processing, and the anomaly judgment module is used to compare the target image features output by the feature extraction module with the feature library to determine the anomaly detection result.
[0015] According to another aspect of the present application, an electronic device is provided, including a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions are used to execute the above-mentioned abnormality detection method when the processor is executed.
[0016] According to another aspect of the present application, a storage medium is provided, which stores a computer program / instruction, and the computer program / instruction is used to execute the above-mentioned anomaly detection method when running.
[0017] According to the above technical solution, the acquired image to be tested is input into the feature extraction module in the trained anomaly detection model to obtain the target image features. The target image features are then input into the anomaly judgment module in the trained anomaly detection model to obtain the anomaly detection results of the target object. This solution extracts the multi-scale image features of the image to be tested through the feature extraction module and converts the multi-scale image features into target image features of a preset scale through normalized stream processing. Target image features of different scales can be selected for output according to the actual application scenario to improve the inference speed while reducing the interference of background information. This method can be applied to anomaly detection in scenes with changing backgrounds, such as the texture of materials such as metal. In addition, through normalized stream processing, anomaly detection at high resolution can be achieved, and the anomaly detection results at different feature scales corresponding to the image to be tested can also be perceived. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The above and other purposes, features, and advantages of the present application will become more apparent through a more detailed description of the embodiments of the present application in conjunction with the accompanying drawings. The accompanying drawings are intended to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. In the drawings, the same reference numerals generally represent the same components or steps.
[0019] FIG1 shows a schematic flow chart of an anomaly detection method according to an embodiment of the present application;
[0020] FIG2 shows a schematic diagram of a feature extraction module according to an embodiment of the present application;
[0021] FIG3 shows a schematic block diagram of an abnormality detection device according to an embodiment of the present application;
[0022] FIG4 shows a schematic block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solutions and advantages of the present application more apparent, the following is a detailed description of example embodiments of the present application with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application, and it should be understood that the present application is not limited to the example embodiments described herein. Based on the embodiments of the present application described in this application, all other embodiments obtained by those skilled in the art without creative work should fall within the scope of protection of this application.
[0024] To at least partially address the above issues, an embodiment of the present application provides an anomaly detection method. FIG1 shows a schematic flow chart of an anomaly detection method according to an embodiment of the present application. As shown in FIG1 , the method may include the following steps S110, S120, and S130.
[0025] Step S110 , obtaining an image to be tested, where the image to be tested includes a target object.
[0026] For example, the image to be tested can be any type of image containing a target object. The target object can be any type of item, such as a wafer, a character, an electronic component, etc. The image to be tested can be a static image or any frame in a dynamic video. The image to be tested can be an original image captured by an image acquisition device (such as an image sensor in a camera), or an image obtained after preprocessing the original image (such as digitization, normalization, smoothing, etc.).
[0027] In step S120, the image to be tested is input into a feature extraction module in the trained anomaly detection model to obtain target image features, wherein the feature extraction module is used to extract multi-scale image features of the image to be tested and convert the multi-scale image features into target image features of a preset scale through normalized stream processing.
[0028] Exemplarily, the anomaly detection model can be any suitable existing or future neural network model capable of performing anomaly detection. Furthermore, the anomaly detection model is an algorithm suitable for performing anomaly detection based on the extracted features. Examples of anomaly detection algorithms include, but are not limited to, the PaDim algorithm and the PatchCore algorithm.
[0029] By inputting the image to be tested into the feature extraction module of the trained anomaly detection model, the target image features can be obtained. The image to be tested I can be expressed as Where H0, W0, and C0 represent the height, width, and number of channels of the image to be tested I, respectively. For example, if the image to be tested I is an RGB image, the number of channels C0 can be 3. The image to be tested I is input into the feature extraction module. After the feature extraction module performs initial feature extraction on the image to be tested, multiple image features of different scales (hereinafter referred to as multi-scale image features) can be obtained. The initial feature extraction process mentioned here includes increasing the number of channels of the image to be tested by a preset number, obtaining single-scale image features with the preset number of channels, and then performing Laplacian pyramid expansion. For example, if the initial number of channels of the image to be tested is C0, after convolution with a 1×1 convolution kernel, a test image I' with a number of channels C1 can be obtained. Using the Laplacian pyramid algorithm, the image features of the image to be tested I' are expanded at multiple scales to obtain multi-scale image features. The obtained multi-scale image features are then subjected to normalization flow processing and inverse Laplacian pyramid processing to obtain target image features of a preset scale. The number of channels of the target image features of the preset scale is the same as the number of channels of the image to be tested I'.
[0030] In one embodiment, if the image I to be tested is subjected to a 1×1 convolution lifting channel and the image features obtained using the Laplacian pyramid algorithm are X1, X2, X3, and X4, then image features M1, M2, M3, and M4 can be obtained through normalization flow processing, and then the target image feature Q can be obtained through inverse Laplacian pyramid processing. The scales corresponding to the image features X1, X2, X3, and X4, or the image features M1, M2, M3, and M4, are increased or decreased in sequence.
[0031] Exemplarily, the feature extraction module includes an initial feature extraction network, a stacked flow network and a feature merging network. Inputting the image to be tested into the feature extraction module in the trained anomaly detection model to obtain the target image feature can include: inputting the image to be tested into the initial feature extraction network to obtain a first image feature, and the feature scale corresponding to the first image feature is multi-scale; inputting the first image feature into the stacked flow network, mapping the first image feature to the latent space through the stacked flow network to obtain a second image feature, and the second image feature has the same feature scale as the first image feature; inputting the second image feature into the feature merging network to obtain the target image feature; wherein the stacked flow network and the feature merging network are used to perform normalized flow processing.
[0032] In one embodiment, the image to be tested is input into the initial feature extraction network to obtain the first image feature. Exemplarily, the initial feature extraction network can be implemented using a 1×1 convolution kernel, a convolutional neural network (CNN) or a Vision Transformer (ViT). Exemplarily and non-restrictively, the stacked flow network can be implemented using other flow networks such as a stacked normalization flow network (NF). Figure 2 shows a schematic diagram of a feature extraction module according to an embodiment of the present application. For the image to be tested After increasing the initial number of channels C0, the image to be tested can be obtained The initial image features of the image to be tested I' are expanded using a Laplacian pyramid to obtain first image features X at four scales, namely, first image features X1, X2, X3, and X4. The first image features X at the four scales are input into a stacked flow network (NF). The stacked flow network maps the first image features X to a latent space, and second image features M at four scales are obtained, namely, second image features M1, M2, M3, and M4. The characteristic scale of the second image feature M is the same as that of the first image feature X. For example, if the scale of the first image feature X1 is 4×4, then the scale of the second image feature M1 corresponding to the first image feature X1 is also 4×4. The corresponding elements of the second image features at different scales of the four-scale second image features M are merged using an inverse Laplacian pyramid algorithm to obtain the target image feature Q. The normalized flow processing in the above embodiments may include the processing operations performed on the first image features by the stacked flow network and the merging operations performed on the second image features by the feature merging network. The stacked flow network shown in FIG2 is merely exemplary. The number of stacked flow networks can be set according to the actual application scenario, and this application does not impose any restrictions on this.
[0033] According to the above technical solution, a first image feature can be obtained by inputting the image to be tested into an initial feature extraction network. The first image feature is then input into a stacked flow network, which maps the first image feature into a latent space to obtain a second image feature. The second image feature is then input into a feature merging network to obtain a target image feature. This method can establish a dual mapping relationship between the image space and the latent space, and based on the obtained target image feature, it can better fit the true distribution of the data. Furthermore, using the stacked flow network for normalization processing can extract image features at different scales and multiple frequencies, thereby improving the accuracy of anomaly detection results.
[0034] Step S130: Input the target image features into the anomaly judgment module in the trained anomaly detection model to obtain an anomaly detection result of the target object. The anomaly detection result is used to indicate whether there is an abnormal area of the target object, wherein the anomaly judgment module is used to compare the target image features output by the feature extraction module with the feature library to determine the anomaly detection result. The feature library is a sample feature library obtained after the feature extraction module extracts features from multiple first sample images.
[0035] Exemplarily, the trained anomaly detection model may also include an anomaly determination module. By inputting target image features into the anomaly determination module, an anomaly detection result for the target object can be obtained. In one embodiment of the present application, the anomaly detection result can be represented by an anomaly detection box. The anomaly detection box can be of any shape, preferably a rectangular box. If the anomaly detection box is a rectangular box, the location information of the abnormal region in the image to be tested can be represented by the position of the corresponding rectangular box in the image to be tested. The anomaly determination module can compare the similarity between any reference image feature in the feature library and the target image feature, and determine the presence of an abnormal region in the target object when the similarity does not meet a target similarity threshold. The anomaly determination module can also compare the distance between any reference image feature in the feature library and the target image feature. By comparing the distance with a preset distance threshold (e.g., the first distance threshold or the second distance threshold in the embodiments below), it can be determined whether the target object has an abnormal region. The feature library can be a sample feature library obtained by clustering multiple reference image features. The multiple reference image features can be multiple image features obtained by the feature extraction model after processing multiple first sample images according to the above-described method. Exemplarily, the first sample image can be a positive sample image (OK image).
[0036] According to the above technical solution, the acquired image to be tested is input into the feature extraction module in the trained anomaly detection model to obtain the target image features. The target image features are then input into the anomaly judgment module in the trained anomaly detection model to obtain the anomaly detection results of the target object. This solution extracts the multi-scale image features of the image to be tested through the feature extraction module and converts the multi-scale image features into target image features of a preset scale through normalized stream processing. The target image features with different numbers of channels can be set for output according to the actual application scenario to meet the needs of different application scenarios. At the same time, the target features output by this solution can reduce the interference of background information. This method can be applied to anomaly detection in scenes with changing backgrounds, such as the texture of materials such as metal. In addition, through normalized stream processing, anomaly detection at high resolution can be achieved, and at the same time, the anomaly detection results at different feature scales corresponding to the image to be tested can be perceived.
[0037] Exemplarily, the image to be tested may include multiple image blocks, and inputting the image to be tested into the initial feature extraction network to obtain the first image feature may include: inputting the multiple image blocks into the initial feature extraction network respectively to obtain the first image block features corresponding to each of the multiple image blocks, wherein the first image feature includes the first image block features corresponding to each of the multiple image blocks; inputting the first image feature into the stacked flow network, and mapping the first image feature to the latent space through the stacked flow network to obtain the second image block feature corresponding to each of the multiple image blocks, wherein the second image feature includes the second image block features corresponding to each of the multiple image blocks; inputting the second image feature into the feature merging network to obtain the target image feature, which may include: inputting the second image block features corresponding to each of the multiple image blocks into the feature merging network to obtain the target image block feature corresponding to each of the multiple image blocks, wherein the target image feature may include the target image block feature corresponding to each of the multiple image blocks.
[0038] In one embodiment, the image to be tested can be divided into multiple image blocks. For example, for an image to be tested with an image size of 16×16, the image to be tested can be divided into four image blocks, each of which is 4×4 in size. The first image block feature, second image block feature, and target image block feature corresponding to each image block can be obtained by referring to the method for obtaining the first image feature, second image block feature, and target image block feature in the previous embodiment. For the sake of brevity, these methods are not further described here. The target image feature can include target image block features corresponding to each of the multiple image blocks.
[0039] According to the above technical solution, the image to be tested is divided into multiple image blocks, and the first image block features corresponding to each image block are obtained. The second image block features are then used to obtain the target image block features. This allows feature extraction to be performed on specific areas of the image to detect whether there are abnormal areas in each image block, further improving the reliability of the abnormality detection results.
[0040] Exemplarily, inputting the target image features into the anomaly judgment module in the trained anomaly detection model to obtain the anomaly detection result of the target object may include: calculating the distance between the target image features and the reference image features in the feature library through the anomaly judgment module; when the distance is greater than or equal to a first distance threshold, determining that there is an abnormal area in the target object.
[0041] In one embodiment, the target image feature is input into the abnormality judgment module, and the abnormality judgment module can calculate the distance between the target image feature and the reference image feature in the feature library. The distance can be any distance such as Euclidean distance, Mahalanobis distance, etc. The feature library can be pre-acquired and stored in the storage device of the host computer, or it can be obtained after training the abnormality detection model. The reference image feature can be any image feature in the feature library. In one embodiment of the present application, the Euclidean distance between the target image feature and the reference image feature in the feature library can be calculated. By way of example and not limitation, the distance between the target image feature and the reference image feature in the feature library can be calculated using methods such as the distance-based K-nearest neighbor algorithm (Nested-loop Method) and the local distance-based outlier factor (LDOF). When the calculated distance is greater than or equal to the first distance threshold, it can be determined that there is an abnormal area in the target object.
[0042] According to the above technical solution, the anomaly determination module calculates the distance between the target image feature and the reference image feature in the feature library. This calculated distance is then compared with a first distance threshold. If the distance is greater than or equal to the first distance threshold, the presence of an abnormal region in the target object is determined. This method eliminates the need for a complex judgment process. Simply by comparing the calculated distance between the target image feature and the reference image feature in the feature library with the first distance threshold, it can determine whether an abnormal region exists in the target object. Therefore, this method is highly reliable and efficient.
[0043] Exemplarily, the feature library may include reference image block features corresponding to each of a plurality of image positions, and the target image features are input into an anomaly judgment module in a trained anomaly detection model to obtain an anomaly detection result of the target object, including: for each of the plurality of image blocks, calculating, by the anomaly judgment module, a distance between the target image block feature corresponding to the image block and a specific reference image block feature in the feature library, where the specific reference image block feature is a reference image block feature corresponding to the image position where the image block is located; and when the distance is greater than or equal to a second distance threshold, determining that an abnormal area exists in the image block.
[0044] In one embodiment, the image to be tested can be divided into multiple image blocks. For example, for an image to be tested with an image size of 16×16, the image to be tested can be divided into four image blocks, each of which has a size of 4×4. Each image block has a corresponding image position in the image to be tested. The feature library can include reference image block features corresponding to each of the multiple image positions. That is, in the feature library, the four image blocks can have corresponding reference image block features. For each of the multiple image blocks, the distance between the target image block feature corresponding to the image block and the specific reference image block feature in the feature library can be calculated by the abnormality judgment module. When the distance is greater than or equal to the second distance threshold, it can be determined that there is an abnormal area in the image block. For the specific implementation method, please refer to the relevant description of determining the presence of an abnormal area in the target object based on the target image feature in the previous embodiment. For the sake of brevity, it will not be repeated here. The second distance threshold may be the same as or different from the first distance threshold, and this application does not impose any restrictions on this.
[0045] According to the above technical solution, for each of the multiple image blocks, the anomaly determination module can calculate the distance between the target image block features corresponding to that image block and the reference image block features in the feature library. The calculated distance is then compared with a second distance threshold. If the distance is greater than or equal to the second distance threshold, the presence of an abnormal region within the image block is determined. This method can efficiently determine whether an abnormal region exists within a target object without requiring a complex determination process. Furthermore, this method can perform anomaly determinations for each target feature corresponding to each image block in the image to be tested, thereby detecting whether an abnormal region exists within each image block, further improving the reliability of the anomaly detection results.
[0046] Exemplarily, the trained anomaly detection model is trained in the following manner: obtaining multiple second sample images; inputting the multiple second sample images into the feature extraction module in the anomaly detection model to be trained respectively to obtain sample image features corresponding to each of the multiple second sample images; calculating a predicted loss value based on the difference between the sample image features corresponding to each of the multiple second sample images; and optimizing the parameters in the feature extraction module in the anomaly detection model to be trained based on the predicted loss value to obtain a trained anomaly detection model.
[0047] In one embodiment, the method for acquiring the second sample image is similar to the method for acquiring the image to be tested. The method for acquiring the image to be tested has been described in detail in step S110. For the sake of brevity, it will not be repeated here. Similar to the image to be tested, multiple second sample images are respectively input into the feature extraction module in the anomaly detection model to be trained, and the sample image features corresponding to each of the multiple second sample images can be obtained. Based on the differences between the sample image features corresponding to each of the multiple second sample images, the prediction loss value can be calculated. For example, the difference Δz between the sample image feature Z1 and the sample image feature Z2 can be expressed as: Δz = (Z1-Z2) 2 . For any two sample image features, the difference between the two sample image features can be substituted into a preset loss function to perform loss calculation to obtain a predicted loss value. By way of example and not limitation, the preset loss function can be a Fourier loss function. Subsequently, the parameters in the initial anomaly detection model can be optimized based on the predicted loss value using backpropagation and gradient descent algorithms. The optimization operation can be repeatedly performed until the anomaly detection model reaches a convergence state. When the training is completed, the obtained anomaly detection model can be used for subsequent anomaly detection on the image to be tested.
[0048] According to the above technical solution, an anomaly detection model can be trained based on the differences between the sample image features corresponding to multiple second sample images. The anomaly detection model obtained through such training is suitable for anomaly detection in scenes with varying backgrounds, such as textures of materials such as metal. Furthermore, through normalized stream processing, anomaly detection can be achieved at high resolution, while also being able to perceive anomaly detection results at different feature scales corresponding to the image under test.
[0049] Exemplarily, the trained anomaly detection model is trained in the following manner: obtaining multiple second sample images; inputting the multiple second sample images into the feature extraction module in the anomaly detection model to be trained respectively to obtain sample image features output by the stacked flow network corresponding to each of the multiple second sample images, the sample image features including multi-scale sub-sample image features; calculating a prediction loss value based on the difference between the sample image features corresponding to each of the multiple second sample images; optimizing the parameters in the feature extraction module in the anomaly detection model to be trained based on the prediction loss value to obtain a trained anomaly detection model; wherein, calculating the prediction loss value based on the difference between the sample image features corresponding to each of the multiple second sample images includes: for each characteristic scale of the sample image feature, calculating the sub-prediction loss value at the characteristic scale based on the difference between the sub-sample image features at the characteristic scale corresponding to each of the multiple second sample images; summing or averaging the sub-prediction loss values at all characteristic scales of the sample image feature to obtain the prediction loss value.
[0050] In one embodiment, the implementation method of "obtaining a plurality of second sample images; inputting the plurality of second sample images into the feature extraction module in the anomaly detection model to be trained respectively to obtain sample image features output by the stacked flow network corresponding to each of the plurality of second sample images, the sample image features including multi-scale sub-sample image features; calculating the prediction loss value based on the difference between the sample image features corresponding to each of the plurality of second sample images; optimizing the parameters in the feature extraction module in the anomaly detection model to be trained based on the prediction loss value to obtain a trained anomaly detection model" has been described in detail in the previous embodiments and will not be repeated here for the sake of brevity. For each characteristic scale of the sample image feature, the sub-prediction loss value at the characteristic scale can be calculated based on the difference between the sub-sample image features at the characteristic scale corresponding to each of the plurality of second sample images. For example, the sample image feature Z1 may include the sub-sample image feature Z 11 , subsample image feature Z 12 , subsample image feature Z 13 and subsample image features Z 14 , the sample image feature Z2 can contain the subsample image feature Z 21 , subsample image feature Z 22 , subsample image feature Z 23 and subsample image features Z 24 . Subsample image feature Z 11 and subsample image feature Z 21 is the subsample image feature at the same feature scale, the subsample image feature Z 12 and subsample image feature Z 22is the subsample image feature at the same feature scale, and so on. For the subsample image feature at each feature scale, the corresponding sub-prediction loss can be calculated. For example, the subsample image feature Z 11 and subsample image features Z 21 , the difference between the two sub-sample image features can be calculated Δz1=(Z 11 -Z 21 ) 2 . Based on the calculated difference and the preset loss function, the sub-prediction loss value at the feature scale can be calculated. By a similar method, the difference between the two sub-sample image features at each feature scale and the sub-prediction loss value can be calculated. For the sake of brevity, we will not go into details here. The prediction loss value can be obtained by summing the sub-prediction loss values at all feature scales of the sample image feature. In addition, the sub-prediction loss values at all feature scales of the sample image feature can be averaged to obtain the prediction loss value.
[0051] According to the above technical solution, sub-prediction loss values can be calculated based on sub-sample images of sample image features at different feature scales. The prediction loss value can be obtained by summing or averaging the sub-prediction loss values at all feature scales of the sample image features. The anomaly detection model trained in this way can further improve the accuracy of anomaly detection for target objects at different feature scales.
[0052] Exemplarily, when summing or averaging the sub-prediction loss values at all feature scales of the sample image feature, the sub-prediction loss values at different feature scales have different weight factors.
[0053] In one embodiment, the sub-prediction loss values at different feature scales may have different weight factors, so that the importance of each feature scale in the anomaly detection model training process can be adjusted through the weight factor to improve the training efficiency of the anomaly detection model.
[0054] Exemplarily, before inputting the target image features into the anomaly judgment module in the trained anomaly detection model to obtain the anomaly detection results of the target object, the method also includes: obtaining multiple first sample images; inputting the multiple first sample images into the feature extraction module in the trained anomaly detection model respectively to obtain sample image features corresponding to each of the multiple first sample images; clustering the sample image features corresponding to each of the multiple first sample images; retaining the representative sample image features in each cluster group obtained by clustering as reference image features to obtain a feature library.
[0055] In one embodiment, the method for acquiring the first sample image is similar to the method for acquiring the image to be tested. The method for acquiring the image to be tested has been described in detail in step S110 and will not be repeated here for the sake of brevity. Multiple first sample images are respectively input into the feature extraction module of the trained anomaly detection model to obtain sample image features corresponding to each first sample image. Then, the sample image features corresponding to each of the multiple first sample images are clustered. Representative sample image features in each cluster group obtained by clustering are retained as reference image features to obtain a feature library. The clustering algorithm may include, but is not limited to, any type of clustering algorithm, such as the K-means algorithm (K-Means algorithm), the K-Means++ algorithm, and the Minibatch K-means algorithm. For example, after feature extraction of any first sample image, the sample image features corresponding to the first sample image are obtained as 10×10×C3. If the number of first sample images is 100, then the number of sample image features for all 100 first sample images is equal to 10,000 (100×10×10), and the number of channels of each sample image feature is C3. The 10,000 sample image features are clustered using a clustering algorithm and the top 10% of the sample image features in the clustering result are selected as reference image features. That is, the number of reference image features is 1,000. Multiple reference image features can form a feature library (MemoryBank).
[0056] According to the above technical solution, by inputting multiple first sample images into the feature extraction module of the trained anomaly detection model, sample image features corresponding to each of the multiple first sample images can be obtained. The sample image features corresponding to each of the multiple first sample images are clustered, and the representative sample image features in each cluster group obtained by clustering are retained as reference image features to obtain a feature library. The reference image features obtained in the feature library can represent the anomalies in the corresponding cluster group. The obtained target image features can then be compared with the feature library to improve the accuracy of the obtained anomaly detection results.
[0057] According to another aspect of the present application, an abnormality detection device is also provided. FIG3 shows a schematic block diagram of an abnormality detection device according to an embodiment of the present application. As shown in FIG3 , the abnormality detection device 300 includes an acquisition module 310 , a first input module 320 , and a second input module 330 .
[0058] The acquisition module 310 is configured to acquire an image to be tested, where the image to be tested includes a target object.
[0059] The first input module 320 is used to input the image to be tested into the feature extraction module in the trained anomaly detection model to obtain target image features, wherein the feature extraction module is used to extract multi-scale image features of the image to be tested and convert the multi-scale image features into target image features of a preset scale through normalized stream processing.
[0060] The second input module 330 is used to input the target image features into the anomaly judgment module in the trained anomaly detection model to obtain the anomaly detection result of the target object, and the anomaly detection result is used to indicate whether there is an abnormal area of the target object, wherein the anomaly judgment module is used to determine the anomaly detection result based on the comparison of the target image features output by the feature library and the feature extraction module, and the feature library is a sample feature library obtained after the feature extraction module extracts features from multiple first sample images.
[0061] A person skilled in the art can understand the specific implementation scheme and beneficial effects of the above-mentioned anomaly detection device by reading the relevant description of the above-mentioned anomaly detection method. For the sake of brevity, they will not be described here in detail.
[0062] According to another aspect of the present application, an electronic device is also provided. FIG4 shows a schematic block diagram of an electronic device according to an embodiment of the present application. As shown in FIG4 , the electronic device includes a processor 410 and a memory 420 . The memory 420 stores a computer program, and the computer program instructions are used by the processor 410 to execute the above-mentioned anomaly detection method when executed.
[0063] According to another aspect of the present application, a storage medium is provided, storing a computer program / instructions. The storage medium may include, for example, a storage component of a tablet computer, a hard disk of a personal computer, an erasable programmable read-only memory (EPROM), a compact disc read-only memory (CD-ROM), a USB memory, or any combination thereof. The storage medium may be any combination of one or more computer-readable storage media. The computer program / instructions are used by a processor to execute the above-described anomaly detection method when executed.
[0064] A person skilled in the art can understand the specific implementation scheme of the above-mentioned electronic device and storage medium by reading the above-mentioned description of the abnormality detection method. For the sake of brevity, it is not repeated here.
[0065] Example:
[0066] Example 1: A method for detecting anomalies, comprising:
[0067] Acquire an image to be measured, wherein the image to be measured includes a target object;
[0068] Inputting the image to be tested into a feature extraction module in a trained anomaly detection model to obtain target image features;
[0069] Inputting the target image features into an anomaly judgment module in the trained anomaly detection model to obtain an anomaly detection result of the target object, wherein the anomaly detection result is used to indicate whether there is an abnormal area in the target object;
[0070] Among them, the feature extraction module is used to extract multi-scale image features of the image to be tested and convert the multi-scale image features into the target image features of a preset scale through normalized stream processing; the abnormality judgment module is used to compare the target image features output by the feature extraction module with the feature library based on the feature library to determine the abnormality detection result; the feature library is a sample feature library obtained after the feature extraction module performs feature extraction on multiple first sample images.
[0071] Embodiment 2: The method according to embodiment 1, wherein the feature extraction module includes an initial feature extraction network, a stacked flow network, and a feature merging network, and inputting the image to be tested into the feature extraction module in the trained anomaly detection model to obtain target image features includes:
[0072] Inputting the image to be tested into the initial feature extraction network to obtain a first image feature, wherein the feature scale corresponding to the first image feature is multi-scale;
[0073] Inputting the first image feature into the stacked flow network, mapping the first image feature to a latent space through the stacked flow network to obtain a second image feature, where the second image feature has the same feature scale as that corresponding to the first image feature;
[0074] Inputting the second image feature into the feature merging network to obtain the target image feature;
[0075] The stacked flow network and the feature merging network are used to perform the normalized flow processing.
[0076] Embodiment 3: The method according to embodiment 1 or 2, wherein the image to be tested includes a plurality of image blocks, and inputting the image to be tested into the initial feature extraction network to obtain the first image feature includes:
[0077] Inputting the plurality of image blocks into the initial feature extraction network respectively to obtain first image block features corresponding to each of the plurality of image blocks, wherein the first image features include the first image block features corresponding to each of the plurality of image blocks;
[0078] Inputting the first image feature into the stacked flow network, and mapping the first image feature to a latent space through the stacked flow network to obtain a second image feature, includes:
[0079] Inputting the first image block features corresponding to each of the plurality of image blocks into the stacked flow network respectively, mapping the first image block features corresponding to each of the plurality of image blocks into a latent space through the stacked flow network to obtain second image block features corresponding to each of the plurality of image blocks, wherein the second image features include the second image block features corresponding to each of the plurality of image blocks; inputting the second image features into the feature merging network to obtain the target image features, comprises:
[0080] The second image block features corresponding to each of the multiple image blocks are input into the feature merging network to obtain target image block features corresponding to each of the multiple image blocks, wherein the target image features include the target image block features corresponding to each of the multiple image blocks.
[0081] Embodiment 4: According to the method described in Embodiments 1-3, wherein inputting the target image features into the anomaly judgment module in the trained anomaly detection model to obtain an anomaly detection result of the target object includes:
[0082] Calculating the distance between the target image feature and the reference image feature in the feature library by the abnormality judgment module;
[0083] When the distance is greater than or equal to a first distance threshold, it is determined that an abnormal area exists in the target object.
[0084] Embodiment 5: According to the method described in any one of Embodiments 1-4, wherein the feature library includes reference image block features corresponding to each of a plurality of image positions, and inputting the target image features into an anomaly determination module in the trained anomaly detection model to obtain an anomaly detection result for the target object comprises:
[0085] For each image block among the plurality of image blocks, calculating, by the abnormality determination module, a distance between a target image block feature corresponding to the image block and a specific reference image block feature in the feature library, where the specific reference image block feature is a reference image block feature corresponding to the image position where the image block is located;
[0086] When the distance is greater than or equal to a second distance threshold, it is determined that an abnormal area exists in the image block.
[0087] Embodiment 6: According to the method described in any one of embodiments 1-5, the trained anomaly detection model is obtained by training in the following manner:
[0088] acquiring a plurality of second sample images;
[0089] Inputting the plurality of second sample images into a feature extraction module in the anomaly detection model to be trained respectively to obtain sample image features corresponding to the plurality of second sample images;
[0090] Calculating a prediction loss value based on differences between sample image features corresponding to each of the plurality of second sample images;
[0091] Parameters in a feature extraction module in the anomaly detection model to be trained are optimized based on the predicted loss value to obtain the trained anomaly detection model.
[0092] Embodiment 7: The method according to any one of embodiments 1-6, wherein the trained anomaly detection model is obtained by training in the following manner:
[0093] acquiring a plurality of second sample images;
[0094] Inputting the plurality of second sample images into a feature extraction module in the anomaly detection model to be trained, respectively, to obtain sample image features output by the stacked stream network corresponding to each of the plurality of second sample images, the sample image features including multi-scale sub-sample image features;
[0095] Calculating a prediction loss value based on differences between sample image features corresponding to each of the plurality of second sample images;
[0096] Optimizing parameters in a feature extraction module in the anomaly detection model to be trained based on the predicted loss value to obtain the trained anomaly detection model;
[0097] The step of calculating the prediction loss value based on the difference between the sample image features corresponding to the plurality of second sample images includes:
[0098] For each characteristic scale of the sample image feature, calculating a sub-prediction loss value at the characteristic scale based on a difference between sub-sample image features at the characteristic scale corresponding to each of the plurality of second sample images;
[0099] The sub-prediction loss values at all feature scales of the sample image feature are summed or averaged to obtain the prediction loss value.
[0100] Example 8: According to the method introduced in Examples 1-7, when summing or averaging the sub-prediction loss values at all feature scales of the sample image features, the sub-prediction loss values at different feature scales have different weight factors.
[0101] Embodiment 9: The method according to any one of embodiments 1-8, wherein, before inputting the target image features into the anomaly judgment module in the trained anomaly detection model to obtain an anomaly detection result for the target object, the method further comprises:
[0102] acquiring a plurality of first sample images;
[0103] Inputting the plurality of first sample images into the feature extraction module in the trained anomaly detection model respectively to obtain sample image features corresponding to each of the plurality of first sample images;
[0104] clustering the sample image features corresponding to each of the plurality of first sample images;
[0105] The representative sample image features in each cluster group obtained by clustering are retained as reference image features to obtain the feature library.
[0106] Embodiment 10: An abnormality detection device, comprising:
[0107] An acquisition module, configured to acquire an image to be tested, wherein the image to be tested includes a target object;
[0108] A first input module is used to input the image to be tested into a feature extraction module in a trained anomaly detection model to obtain target image features;
[0109] a second input module, configured to input the target image features into an anomaly judgment module in the trained anomaly detection model to obtain an anomaly detection result of the target object, wherein the anomaly detection result is used to indicate whether there is an abnormal area in the target object;
[0110] Among them, the feature extraction module is used to extract multi-scale image features of the image to be tested and convert the multi-scale image features into the target image features of a preset scale through normalized stream processing, and the abnormality judgment module is used to compare the target image features output by the feature extraction module with the feature library to determine the abnormality detection result.
[0111] Embodiment 11: An electronic device comprises a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions are used by the processor to execute the anomaly detection method as described in any one of embodiments 1-9 when the processor is running.
[0112] Example 12: A storage medium storing a computer program / instruction, wherein the computer program / instruction is used to execute the anomaly detection method as described in any one of Examples 1-9 when running.
[0113] Although example embodiments have been described herein with reference to the accompanying drawings, it should be understood that the above example embodiments are merely illustrative and are not intended to limit the scope of the present application. Various changes and modifications may be made therein by those skilled in the art without departing from the scope and spirit of the present application. All such changes and modifications are intended to be included within the scope of the present application as required by the appended claims.
[0114] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0115] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units described is merely a logical function division. In actual implementation, other division methods may be used, such as combining or integrating multiple units or components into another device, or ignoring or not performing some features.
[0116] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures, and techniques are not shown in detail so as not to obscure the understanding of this description.
[0117] Similarly, it should be understood that in order to streamline the present application and aid in understanding one or more of the various inventive aspects, in the description of the exemplary embodiments of the present application, the various features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, this approach of the present application should not be interpreted as reflecting the intention that the application claimed for protection requires more features than those explicitly recited in each claim. More precisely, as reflected in the corresponding claims, the inventive point is that the corresponding technical problem can be solved with fewer features than all the features of a single disclosed embodiment. Therefore, the claims following the detailed description are hereby expressly incorporated into the detailed description, with each claim itself serving as a separate embodiment of the present application.
[0118] It will be understood by those skilled in the art that, except where mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all processes or units of any method or apparatus disclosed herein may be combined in any combination. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) may be replaced by an alternative feature providing the same, equivalent, or similar purpose.
[0119] Furthermore, those skilled in the art will appreciate that although some embodiments described herein include certain features included in other embodiments but not other features, combinations of features from different embodiments are intended to be within the scope of this application and to form different embodiments. For example, in the claims, any of the claimed embodiments may be used in any combination.
[0120] The various component embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all of the functions of some modules in the anomaly detection device according to the embodiment of the present application. The present application can also be implemented as a device program (e.g., a computer program and a computer program product) for executing part or all of the methods described herein. Such a program implementing the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0121] It should be noted that the above embodiments illustrate rather than limit the present application, and that a person skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbols placed between brackets should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present application may be implemented by means of hardware comprising several different elements and by means of appropriately programmed computers. In a unit claim enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third etc. does not indicate any order. These words may be interpreted as names.
[0122] The above description is merely a specific embodiment or illustration of a specific embodiment of the present application, and the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present application should be included in the scope of protection of the present application. The scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. An anomaly detection method, characterized in that, The method includes: Obtaining a to-be-tested image, where the to-be-tested image includes a target object; Inputting the to-be-tested image into a feature extraction module in a trained anomaly detection model to obtain target image features; Inputting the target image features into an anomaly judgment module in the trained anomaly detection model to obtain an anomaly detection result of the target object, where the anomaly detection result is used to indicate whether there is an abnormal area in the target object; Wherein, the feature extraction module is used to extract multi-scale image features of the to-be-tested image and convert the multi-scale image features into the target image features of a preset scale through normalizing flow processing, and the anomaly judgment module is used to compare with the target image features output by the feature extraction module based on a feature library to determine the anomaly detection result, and the feature library is a sample feature library obtained by the feature extraction module after extracting features from a plurality of first sample images.
2. The method according to claim 1, wherein The feature extraction module includes an initial feature extraction network, a stacked flow network, and a feature merging network. The step of inputting the to-be-tested image into the feature extraction module in the trained anomaly detection model to obtain target image features includes: Inputting the to-be-tested image into the initial feature extraction network to obtain first image features, where the feature scale corresponding to the first image features is multi-scale; Inputting the first image features into the stacked flow network, and mapping the first image features to a latent space through the stacked flow network to obtain second image features, where the feature scale corresponding to the second image features is the same as that of the first image features; Inputting the second image features into the feature merging network to obtain the target image features; Wherein, the stacked flow network and the feature merging network are used to perform the normalizing flow processing.
3. The method according to claim 2, characterized in that, The to-be-tested image includes a plurality of image patches. The step of inputting the to-be-tested image into the initial feature extraction network to obtain first image features includes: Inputting the plurality of image patches into the initial feature extraction network respectively to obtain first image patch features corresponding to the plurality of image patches respectively, where the first image features include the first image patch features corresponding to the plurality of image patches respectively; The step of inputting the first image features into the stacked flow network and mapping the first image features to a latent space through the stacked flow network to obtain second image features includes: Inputting the first image patch features corresponding to the plurality of image patches into the stacked flow network respectively, and mapping the first image patch features corresponding to the plurality of image patches to a latent space through the stacked flow network to obtain second image patch features corresponding to the plurality of image patches respectively, where the second image features include the second image patch features corresponding to the plurality of image patches respectively; The step of inputting the second image features into the feature merging network to obtain the target image features includes: Input the second image patch features corresponding to each of the multiple image patches into the feature merging network to obtain the target image patch features corresponding to each of the multiple image patches, where the target image features include the target image patch features corresponding to each of the multiple image patches.
4. The method according to claim 1 or 2, characterized in that, The inputting the target image features into the anomaly judgment module in the trained anomaly detection model to obtain the anomaly detection result of the target object includes: Calculating, by the anomaly judgment module, the distance between the target image features and the reference image features in the feature library; When the distance is greater than or equal to the first distance threshold, determining that there is an abnormal area in the target object.
5. The method according to claim 3, wherein The feature library includes reference image patch features corresponding to each of multiple image positions. The inputting the target image features into the anomaly judgment module in the trained anomaly detection model to obtain the anomaly detection result of the target object includes: For each of the multiple image patches, calculating, by the anomaly judgment module, the distance between the target image patch feature corresponding to the image patch and the specific reference image patch feature in the feature library, where the specific reference image patch feature is the reference image patch feature corresponding to the image position where the image patch is located; When the distance is greater than or equal to the second distance threshold, determining that there is an abnormal area within the image patch.
6. The method according to claim 1 or 2, characterized in that, The trained anomaly detection model is obtained by training in the following manner: Obtain a plurality of second sample images; Input the plurality of second sample images into the feature extraction module in the anomaly detection model to be trained respectively to obtain the sample image features corresponding to each of the plurality of second sample images; Calculate a prediction loss value based on the differences between the sample image features corresponding to the plurality of second sample images; Optimize the parameters in the feature extraction module of the anomaly detection model to be trained based on the prediction loss value to obtain the trained anomaly detection model.
7. The method according to claim 3, characterized in that The trained anomaly detection model is obtained by training in the following manner: Obtain a plurality of second sample images; Input the plurality of second sample images into the feature extraction module in the anomaly detection model to be trained respectively to obtain the sample image features output by the stacked flow network corresponding to each of the plurality of second sample images, where the sample image features include multi-scale sub-sample image features; Calculate a prediction loss value based on the differences between the sample image features corresponding to the plurality of second sample images; Optimize the parameters in the feature extraction module of the anomaly detection model to be trained based on the prediction loss value to obtain the trained anomaly detection model; Wherein, the calculating the prediction loss value based on the differences between the sample image features corresponding to the plurality of second sample images includes: For each feature scale of the sample image features, calculating a sub-prediction loss value at the feature scale based on the differences between the sub-sample image features at the feature scale corresponding to each of the plurality of second sample images; Sum or average the sub-prediction loss values at all feature scales of the sample image features to obtain the prediction loss value.
8. The method according to claim 7, wherein When summing or averaging the sub-prediction loss values at all feature scales of the sample image features, the sub-prediction loss values at different feature scales have different weight factors.
9. The method according to any one of claims 1-3, characterized in that, Before inputting the target image features into the anomaly judgment module of the trained anomaly detection model to obtain the anomaly detection result of the target object, the method further includes: Obtain a plurality of first sample images; Input the plurality of first sample images into the feature extraction module of the trained anomaly detection model respectively to obtain the sample image features corresponding to the plurality of first sample images; Cluster the sample image features corresponding to the plurality of first sample images respectively; Retain the representative sample image features in each clustering group obtained by clustering as reference image features to obtain the feature library.
10. An anomaly detection device, characterized in that, Including: An acquisition module, configured to acquire a to-be-detected image, where the to-be-detected image includes a target object; A first input module, configured to input the to-be-detected image into the feature extraction module of the trained anomaly detection model to obtain target image features; A second input module, configured to input the target image features into the anomaly judgment module of the trained anomaly detection model to obtain the anomaly detection result of the target object, where the anomaly detection result is used to indicate whether there is an abnormal area in the target object; Wherein, the feature extraction module is configured to extract multi-scale image features of the to-be-detected image and convert the multi-scale image features into the target image features of a preset scale through normalizing flow processing, and the anomaly judgment module is configured to compare the feature library with the target image features output by the feature extraction module to determine the anomaly detection result.
11. An electronic device, comprising a processor and a memory, characterized in that, The memory stores computer program instructions, and when the computer program instructions are run by the processor, they are used to execute the anomaly detection method according to any one of claims 1-9.
12. A storage medium stores computer programs / instructions, characterized in that, The computer program / instructions are used to execute the anomaly detection method according to any one of claims 1-9 when running.
Citation Information
Patent Citations
Power grid equipment abnormity detection method and device
CN111242144A
Abnormality detection method and device, electronic equipment and computer readable storage medium
CN113688890A
Image anomaly detection method and device, storage medium and electronic equipment
CN114820540A
Unsupervised notebook appearance defect detection method based on multi-scale standardized flow
CN116205876A
Abnormality detection method and device, electronic equipment and storage medium
CN117474918A
Cited By
Display panel processing method and device, computer equipment and readable storage medium
CN121393334A