A method and system for detecting and locating anomalies in industrial images based on local outlier factors

By applying local outlier factor algorithm and pre-trained width residual network in industrial image abnormality detection, the problem of industrial image abnormality detection and positioning automation is solved, efficient and accurate abnormality detection and positioning is achieved, and continuous quality control is supported.

CN114926682BActive Publication Date: 2025-05-02HANGZHOU DIANZI UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210547394.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-18
Publication Date
2025-05-02
Estimated Expiration
2042-05-18

AI Technical Summary

Technical Problem

The existing industrial image abnormality detection and positioning technology is difficult to automate, which leads to difficulties for operators to detect abnormalities and affects quality control.

Method used

An industrial image anomaly detection and positioning method based on local outlier factors is adopted, image features are extracted through a pre-trained width residual network, and anomaly score is calculated using a local outlier factor algorithm to realize automated detection and positioning.

Benefits of technology

It improves the accuracy and efficiency of industrial image abnormality detection, realizes accurate positioning of abnormal phenomena, reduces the difficulty of operators, and supports continuous quality control.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114926682B_ABST
    Figure CN114926682B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for detecting and locating anomalies in industrial images based on local outlier factors. The method of the present invention is as follows: (1) obtaining a training data set; (2) extracting features; (3) using a local outlier factor algorithm to detect and locate anomalies. The present invention combines deep learning with traditional methods to propose an unsupervised anomaly detection and location technology solution, which has high anomaly detection accuracy and more precise anomaly location performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of industrial image anomaly detection and positioning, and specifically relates to an industrial image anomaly detection and positioning method and system based on local outlier factors. Background Art

[0002] Humans are very good at identifying whether an image is similar to what they have observed before, or whether it is abnormal. This task is called anomaly detection and has a wide range of applications, including industrial image anomaly detection. However, anomalies are relatively difficult to detect on a production line, making human detection difficult. Therefore, automating anomaly detection can help reduce the workload of operators and enable continuous quality control. Summary of the invention

[0003] In order to solve the existing problems of anomaly detection and positioning in industrial images, the present invention proposes an industrial image anomaly detection and positioning method and system based on Local Outiler Factor (LOF). The present invention adopts a pre-trained wide residual network to extract image features, and then uses the LOF algorithm to calculate the anomaly score for anomaly detection and positioning.

[0004] To achieve the above object, the present invention adopts the following technical solutions:

[0005] A method for detecting and locating anomalies in industrial images based on local outlier factors includes a training phase, which is specifically as follows:

[0006] Step (1). Obtain training data set;

[0007] Step (2). Feature extraction;

[0008] Step (3). Use the local outlier factor algorithm to detect and locate anomalies.

[0009] Preferably, step (1) of obtaining a training data set includes:

[0010] The training dataset consists of normal images. The training set images are resized to 256×256 and cropped to 224×224 in the center.

[0011] Preferably, step (2) feature extraction is specifically:

[0012] The ResNet model obtained by pre-training is used as the feature extractor F, and the first three layers of the feature extractor are denoted as F3. For a given image x i , the extracted features f i :f i =F3(x i). During the training phase, the features of all training images are extracted and stored. During testing, only the features of the target image are extracted.

[0013] Preferably, step (3) uses a local outlier factor algorithm to detect and locate anomalies, specifically:

[0014] This step is divided into two parts. One part is to output the feature f of the third layer of the ResNet network. i , as the input of the LOF algorithm for training. The other part first fuses the output features of the first, second and third layers of the ResNet network and reduces the dimension. The size of the fused feature map is 1792×56×56. After the dimension reduction, the dimension size of each superpixel on the feature map is 550×1. Finally, each superpixel is used as the input of the LOF algorithm for training.

[0015] Preferably, the anomaly detection process is as follows:

[0016] The third layer output feature f of the feature extractor F in step (2) i , as the input of the LOF algorithm for training. i , as a data point, calculate its k-th distance, and then find the k-th distance neighborhood of the data point. Finally, calculate the local reachable density of each data point and calculate the local outlier factor as the anomaly score. The specific calculation method is as follows:

[0017] Calculate the data point f i The kth distance from f i The kth farthest point to f i The Euclidean distance of k (f i ).

[0018] Find f i The kth distance neighborhood N k (f i ) that is, f i All points within the kth distance of , including the kth distance. |N k (f i )|≥k, |·| represents the number of elements in the set, 0<k≤L, L is the total number of samples.

[0019] Compute the local reachable density for each data point:

[0020]

[0021] Among them, reach_dist k (f i ,t) is f i and N k (f i) is the reachable distance of a point t in the space. The calculation formula for the reachable distance is: reach_dist k (f i ,t)=max{d k (f i ),d(f i ,t)}; d(·,·) represents the Euclidean distance, t is N k (f i )Inside division f i Some point outside.

[0022] Calculate f i The local outlier factor takes this as an anomaly score:

[0023]

[0024] LOF k (f i ) represents point f i Neighborhood point N k (f i ) and the local reachability density of point f i During the test, the local outlier factor is used as the abnormal score of the tested sample, and the threshold is set as th (0<th<1). Samples greater than the threshold th are judged as abnormal samples, and samples less than the threshold th are judged as normal samples.

[0025] Preferably, the abnormality location process is specifically as follows:

[0026] Select the first, second, and third layer output features of the feature extractor F in step (2) and fuse them to obtain the fused feature Where N is the number of input training images, C s represents the sum of the number of output channels of the first, second, and third layers, and H, W represents the resolution of the maximum output feature map. First, each channel of the output feature maps of the first, second, and third layers of F is enlarged to a feature map with a resolution of H×W, and then the output feature maps from different layers are connected front and back to obtain a fused feature map containing information of different semantic levels and resolutions, so as to achieve encoding of different granularities and global contexts.

[0027] The fused feature map may carry redundant information. In order to reduce the computational complexity of the model and reduce memory usage, the present invention adopts random dimensionality reduction to reduce the dimension of the fused feature map P, starting from the channel dimension C of P. s (C s =1792) randomly select 550 dimensions. ij ∈P N×550×H×W ((i,j)∈[1,W]×[1,H]) is used as the input of the LOF algorithm for training, and the kth distance d of each superpixel is calculated. k (pij ), and then find its k-th distance neighborhood. Finally, the local reachable density of each superpixel is calculated according to formula (1), and the anomaly score is calculated according to formula (2).

[0028] Preferably, the present invention further comprises step (4) a testing phase, specifically:

[0029] Step (I). Resize the test image to 256×256 and crop it to 224×224 in the center.

[0030] Step (II). Use the ResNet feature extractor F obtained by pre-training in step (2) of the training phase to extract the features of the test image. For the anomaly detection task, the anomaly score of the test image is calculated according to formula (2). Images with a score greater than the threshold th are considered abnormal images, and images with a score less than or equal to the threshold th are considered normal images.

[0031] For the anomaly localization task, the feature extractor F in step (2) is used to extract the features of the test image, and the output features of the first, second and third layers are fused and reduced to 550 dimensions. The anomaly score of each superpixel after fusion is calculated to obtain the pixel-level anomaly score map M of each feature map. Since the resolution of M is smaller than the resolution of the image under test, M is upsampled to the size of the image under test using bilinear interpolation, and the result is smoothed using a Gaussian filter. Finally, the PR curve of M and the true value map of the test image is calculated, and the balance point of the PR curve is used as the optimal threshold Th; the values ​​less than or equal to Th in M ​​are judged as 0, and the values ​​greater than Th are judged as 1, 1 represents an abnormal pixel, and 0 represents a normal pixel, to obtain the anomaly localization mask map M'; the positions that are 0 in M' are set to 0 in the test image to obtain the image abnormal pixel localization result map.

[0032] The present invention also discloses an industrial image anomaly detection and positioning system based on local outlier factors, comprising the following modules:

[0033] An acquisition module is used to obtain a training data set;

[0034] Extraction module: used to extract features;

[0035] Anomaly detection and location module: uses local outlier factor algorithm for anomaly detection and location.

[0036] The present invention focuses on image anomaly detection, especially anomaly location in industrial images. The present invention contains an efficient and practical industrial image anomaly detection and location method and system based on local outlier factors, which uses a pre-trained ResNet network to extract image features. The present invention uses the third-layer output features of the feature extraction network as the input of the local outlier factor algorithm to calculate the anomaly score of the test image to achieve anomaly detection. It fuses the output features from different layers of ResNet, and uses the local outlier factor algorithm to calculate the anomaly score of each superpixel in the fused feature map to achieve anomaly location. The present invention combines deep learning with traditional methods to propose an unsupervised anomaly detection and location technology solution with high anomaly detection accuracy and more precise anomaly location performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 This is a diagram of an industrial image anomaly detection model based on local anomaly factors;

[0038] Figure 2 It is a model diagram of industrial image anomaly location based on local anomaly factors;

[0039] Figure 3 This is an example of feature map fusion;

[0040] Figure 4 The present invention is a block diagram of an industrial image anomaly detection and positioning system based on local outlier factors. DETAILED DESCRIPTION

[0041] The present invention is described in detail below with reference to examples so that those skilled in the art can better understand the present invention. It should be noted that in the following description, when the detailed description of known functions and designs may dilute the main content of the present invention, these descriptions will be omitted here.

[0042] Example 1

[0043] like Figure 1-3 As shown, this embodiment provides an industrial image anomaly detection and positioning method based on local outlier factors, which includes a training phase and a testing phase.

[0044] The training phases are as follows:

[0045] Step (1). Obtain the training dataset.

[0046] The training dataset consists of normal images in the MVTec AD (https: / / www.mvtec.com / company / research / datasets / mvtec-ad / ) dataset. The training set images are resized to 256×256 and cropped to 224×224 in the center.

[0047] Step (2). Feature extraction.

[0048] This embodiment uses the ResNet model pre-trained on the ImageNet dataset as the feature extractor F, and the first three layers of the feature extractor are denoted as F3. i , the extracted features f i :f i =F3(x i ). During the training phase, the features of all training images are extracted and stored. During testing, only the features of the target image are extracted.

[0049] Step (3). Use the local outlier factor algorithm to detect and locate anomalies.

[0050] This step is divided into two parts. One part is to output the feature f of the third layer of the ResNet network. i , as the input of the LOF algorithm for training. The other part first fuses the output features of the first, second and third layers of the ResNet network and reduces the dimension. The size of the fused feature map is 1792×56×56. After the dimension reduction, the dimension size of each superpixel on the feature map is 550×1. Finally, each superpixel is used as the input of the LOF algorithm for training.

[0051] The anomaly detection process is as follows:

[0052] The third layer output feature f of the feature extractor F in step (2) i , as the input of the LOF algorithm for training. i , as a data point, calculate its k-th distance, and then find the k-th distance neighborhood of the data point. Finally, calculate the local reachable density of each data point and calculate the local outlier factor as the anomaly score. The specific calculation method is as follows:

[0053] Calculate the data point f i The kth distance from f i The kth farthest point to f i The Euclidean distance of k (f i ).

[0054] Find f i The kth distance neighborhood N k (f i ) that is, f i All points within the kth distance of , including the kth distance. |N k (f i )|≥k, |·| represents the number of elements in the set, and the value of k in the present invention is 20.

[0055] Compute the local reachable density for each data point:

[0056]

[0057] Among them, reach_dist k (f i ,t) is f i and N k (f i ) is the reachable distance of a point t in the space. The calculation formula for the reachable distance is: reach_dist k (fi,t)=max{d k (f i ),d(f i ,t)}; d(·,·) represents the Euclidean distance, t is N k (f i )Inside division f i Some point outside.

[0058] Calculate f i The local outlier factor of is used as the anomaly score:

[0059]

[0060] LOF k (f i ) represents point f i Neighborhood point N k (f i ) and the local reachability density of point f i During the test, the local outlier factor is used as the abnormal score of the tested sample, and the threshold th is set to 0.5. Samples greater than the threshold th are considered abnormal samples, and samples less than the threshold th are considered normal samples.

[0061] The abnormality location process is as follows:

[0062] Select the first, second, and third layer output features of the feature extractor F in step (2) and fuse them to obtain a fused feature map Where N is the number of input training images, C s represents the sum of the number of output channels of the first, second, and third layers, and H, W represents the resolution of the maximum output feature map. First, each channel of the output feature maps of the first, second, and third layers of F is enlarged to a feature map with a resolution of H×W, and then the output feature maps from different layers are connected front and back to obtain a fused feature map containing information of different semantic levels and resolutions, so as to achieve encoding of different granularities and global contexts.

[0063] The fused feature map may carry redundant information. In order to reduce the computational complexity of the model and reduce memory usage, the present invention adopts random dimensionality reduction to reduce the dimension of the fused feature map P, starting from the channel dimension C of P. s (C s =1792) randomly select 550 dimensions. ij ∈P N×550×H×W ((i,j)∈[1,W]×[1,H]) is used as the input of the LOF algorithm for training, and the kth distance d of each superpixel is calculated. k (p ij ), and then find its k-th distance neighborhood. Finally, the local reachable density of each superpixel is calculated according to formula (3), and the anomaly score is calculated according to formula (4).

[0064] The specific process of the testing phase is as follows:

[0065] Step (I). The test dataset consists of test images in the MVTec AD dataset. The test images are resized to 256×256 and cropped to 224×224 in the center.

[0066] Step (II). Use the ResNet feature extractor F obtained by pre-training in step (2) of the training phase to extract the features of the test image. For the anomaly detection task, the anomaly score of the test image is calculated according to formula (2). Images with a score greater than the threshold th are considered abnormal images, and images with a score less than or equal to the threshold th are considered normal images.

[0067] For the anomaly localization task, the feature extractor F in step (2) is used to extract the features of the test image, and the output features of the first, second and third layers are fused and reduced to 550 dimensions. The anomaly score of each superpixel after fusion is calculated to obtain the pixel-level anomaly score map M of each feature map. Since the resolution of M is smaller than the resolution of the image under test, bilinear interpolation is used to upsample M to the size of the image under test, and a Gaussian filter is used to smooth the result. Finally, the PR curve of M and the true value map of the test image is calculated, and the balance point of the PR curve is used as the optimal threshold Th; the values ​​less than or equal to Th in M ​​are judged as 0, and the values ​​greater than Th are judged as 1, 1 represents an abnormal pixel, and 0 represents a normal pixel, to obtain the anomaly localization mask map M'; the positions that are 0 in M' are set to 0 in the test image to obtain the image abnormal pixel localization result map.

[0068] Example 2

[0069] like Figure 4 As shown, this embodiment is an industrial image anomaly detection and positioning system based on local outlier factors, which includes an acquisition module, an extraction module, an anomaly detection and positioning module, and a testing module. The specific introduction of each module is as follows:

[0070] The acquisition module is used to obtain the training data set.

[0071] The training dataset consists of normal images in the MVTec AD (https: / / www.mvtec.com / company / research / datasets / mvtec-ad / ) dataset. The training set images are resized to 256×256 and cropped to 224×224 in the center.

[0072] The extraction module is used for feature extraction.

[0073] This embodiment uses the ResNet model pre-trained on the ImageNet dataset as the feature extractor F, and the first three layers of the feature extractor are denoted as F3. i , the extracted features f i :f i =F3(x i ). During training, the features of all training images are extracted and stored. During testing, only the features of the target image are extracted.

[0074] The anomaly detection and location module uses the local outlier factor algorithm to perform anomaly detection and location.

[0075] This module is divided into two parts. One part is based on the third layer output feature f of the ResNet network. i , as the input of the LOF algorithm for training. The other part first fuses the output features of the first, second and third layers of the ResNet network and reduces the dimension. The size of the fused feature map is 1792×56×56. After the dimension reduction, the dimension size of each superpixel on the feature map is 550×1. Finally, each superpixel is used as the input of the LOF algorithm for training.

[0076] The anomaly detection process is as follows:

[0077] The third layer output feature f of feature extractor F i , as the input of the LOF algorithm for training. i , as a data point, calculate its k-th distance, and then find the k-th distance neighborhood of the data point. Finally, calculate the local reachable density of each data point and calculate the local outlier factor as the anomaly score. The specific calculation method is as follows:

[0078] Calculate the data point f i The kth distance from f i The kth farthest point to f i The Euclidean distance of k (f i ).

[0079] Find f iThe kth distance neighborhood N k (f i ) that is, f i All points within the kth distance of , including the kth distance. |N k (f i )|≥k, |·| represents the number of elements in the set, and the value of k in the present invention is 20.

[0080] Compute the local reachable density for each data point:

[0081]

[0082] Among them, reach_dist k (f i ,t) is f i and N k (f i ) is the reachable distance of a point t in the space. The calculation formula for the reachable distance is: reach_dist k (f i ,t)=max{d k (f i ),d(f i ,t)}; d(·,·) represents the Euclidean distance, t is N k (f i )Inside division f i Some point outside.

[0083] Calculate f i The local outlier factor of is used as the anomaly score:

[0084]

[0085] LOF k (f i ) represents point f i Neighborhood point N k (f i ) and the local reachability density of point f i During the test, the local outlier factor is used as the abnormal score of the tested sample, and the threshold th is set to 0.5. Samples greater than the threshold th are considered abnormal samples, and samples less than the threshold th are considered normal samples.

[0086] The abnormality location process is as follows:

[0087] Select the first, second, and third layer output features of feature extractor F and fuse them to get the fused feature map Where N is the number of input training images, C srepresents the sum of the number of output channels of the first, second, and third layers, and H, W represents the resolution of the maximum output feature map. First, each channel of the output feature maps of the first, second, and third layers of F is enlarged to a feature map with a resolution of H×W, and then the output feature maps from different layers are connected front and back to obtain a fused feature map containing information of different semantic levels and resolutions, so as to achieve encoding of different granularities and global contexts.

[0088] The fused feature map may carry redundant information. In order to reduce the computational complexity of the model and reduce memory usage, the present invention adopts random dimensionality reduction to reduce the dimension of the fused feature map P, starting from the channel dimension C of P. s (C s =1792) randomly select 550 dimensions. ij ∈P N×550×H×W ((i,j)∈[1,W]×[1,H]) is used as the input of the LOF algorithm for training, and the kth distance d of each superpixel is calculated. k (p ij ), and then find its k-th distance neighborhood. Finally, the local reachable density of each superpixel is calculated according to formula (3), and the anomaly score is calculated according to formula (4).

[0089] The test modules are as follows:

[0090] The test dataset consists of test images in the MVTec AD dataset. The test images are resized to 256×256 and cropped to 224×224 in the center.

[0091] The features of the test image are extracted using the pre-trained ResNet feature extractor F. For the anomaly detection task, the anomaly score of the test image is calculated according to formula (2). Images with a score greater than the threshold th are considered abnormal images, and images with a score less than or equal to the threshold th are considered normal images.

[0092] For the anomaly localization task, the feature extractor F is used to extract the features of the test image, and the output features of the first, second and third layers are fused and reduced to 550 dimensions. The anomaly score of each superpixel after fusion is calculated to obtain the pixel-level anomaly score map M of each feature map. Since the resolution of M is smaller than the resolution of the image under test, bilinear interpolation is used to upsample M to the size of the image under test, and the result is smoothed using a Gaussian filter. Finally, the PR curve of M and the true value map of the test image is calculated, and the balance point of the PR curve is used as the optimal threshold Th; the values ​​less than or equal to Th in M ​​are judged as 0, and the values ​​greater than Th are judged as 1, 1 represents an abnormal pixel, and 0 represents a normal pixel, to obtain the anomaly localization mask map M'; the positions that are 0 in M' are set to 0 in the test image, and the image abnormal pixel localization result map is obtained.

[0093] The present invention uses the third layer output of the pre-trained residual network as the image-level feature, and uses the local outlier factor to calculate the abnormal score of the tested image. The abnormal score greater than the threshold is judged as abnormal, otherwise it is normal, to achieve abnormal detection. In order to accurately locate the abnormal pixels in the image, the output features of the first three layers of the residual network are fused to obtain a feature map, the abnormal score of each superpixel in the feature map is calculated, and the pixel-level abnormal score map is obtained. The abnormal score map is upsampled, and the abnormal pixel mask map is output. The image abnormal pixel positioning result map is obtained from the mask map.

[0094] The specific embodiments described herein are merely examples of the spirit of the present invention. Those skilled in the art may make various modifications or additions to the specific embodiments described or replace them in similar ways, but they will not deviate from the spirit of the present invention or exceed the scope defined by the appended claims.

Claims

1. A method for detecting and locating anomalies in industrial images based on local outlier factors, characterized by Follow these steps: Step (1), obtaining a training data set; Step (2), feature extraction; Step (3): use the local outlier factor algorithm to detect and locate anomalies; Step (2) is as follows: The ResNet model obtained by pre-training is used as the feature extractor F, and the first three layers of the feature extractor are denoted as F3; for a given image x i , the extracted features f i , f i =F3(x i ); Step (3) is divided into two parts: The first part is anomaly detection: the third layer output feature f of the ResNet network i , used as the input of LOF algorithm for training; The second part is anomaly localization: First, the output features of the first, second and third layers of the ResNet network are fused and reduced in dimension. The size of the fused feature map is 1792×56×56. After the dimension reduction, the dimension size of each superpixel on the feature map is 550×1. Finally, each superpixel is used as the input of the LOF algorithm for training. The anomaly detection process is as follows: Calculate the data point f i The kth distance from f i The kth farthest point to f i The Euclidean distance of k (f i ); Find f i The kth distance neighborhood N k (f i ) that is, f i All points within the kth distance of, including the kth distance; |N k (f i )|≥k, |·| represents the number of elements in the set, 0<k≤L, L is the total number of samples; Compute the local reachable density for each data point: Among them, reach_dist k (f i ,t) is f i and N k (f i ) is the reachable distance of a point t in the space. The calculation formula for the reachable distance is: reach_dist k (f i ,t)=max{d k (f i ),d(f i ,t)}; d(·,·) represents the Euclidean distance, t is N k (f i )Inside division f i a point outside; Calculate f i The local outlier factor of is used as the anomaly score: LOF k (f i ) represents point f i Neighborhood point N k (f i ) and the local reachability density of point f i The average of the ratio of the local reachable density of the sample to the local outlier factor; during the test, the local outlier factor is used as the abnormal score of the tested sample, and the threshold is set as th, 0<th<1, and the sample greater than the threshold th is judged as an abnormal sample, and the sample less than the threshold th is judged as a normal sample; The abnormality location process is as follows: Select the first, second, and third layer output features of the feature extractor F in step (2) and fuse them to obtain a fused feature map Where N is the number of input training images, C s represents the sum of the number of output channels of the first, second and third layers, and H, W represents the resolution of the maximum output feature map; first, each channel of the output feature map of the first, second and third layers of the feature extractor F is enlarged to a feature map with a resolution of H×W, and then the output feature maps from different layers are connected front and back to obtain a fused feature map containing information of different semantic levels and resolutions, so as to realize encoding of different granularities and global contexts; The dimension of the fusion feature map P is reduced by random dimensionality reduction, and the channel dimension C of the fusion feature map P is reduced. s 550 dimensions are randomly selected from C s =1792; with superpixel p ij ∈P N×550×H×W As the input of LOF algorithm for training, (i,j)∈[1,W]×[1,H], calculate the kth distance d of each superpixel k (p ij ), and then find its k-th distance neighborhood; finally, calculate the local reachable density of each superpixel according to formula (1), and calculate the anomaly score according to formula (2).

2. The method for detecting and locating anomalies in industrial images based on local outlier factors according to claim 1, characterized in that: Step (1) is as follows: The training dataset consists of normal images. The training set images are resized to 256×256 and cropped to 224×224 in the center.

3. The method for detecting and locating anomalies in industrial images based on local outlier factors according to claim 1, characterized in that: It also includes step (4) testing phase, the specific process is as follows: Step (I), resize the test image to 256×256, and crop it to 224×224 in the center; Step (II), using the ResNet feature extractor F obtained by pre-training in step (2), extract the features of the test image; for the anomaly detection task, the anomaly score of the test image is calculated according to formula (2), and the image with a score greater than the threshold th is judged as an abnormal image, and the image with a score less than or equal to the threshold th is judged as a normal image; For the anomaly localization task, the feature extractor F in step (2) is used to extract the features of the test image. The output features of the first, second and third layers are fused and reduced to 550 dimensions. The anomaly score of each superpixel after fusion is calculated to obtain the pixel-level anomaly score map M of each feature map. Since the resolution of M is smaller than the resolution of the image under test, M is upsampled using bilinear interpolation and the result is smoothed using a Gaussian filter. Finally, the PR curve of M and the true value map of the test image is calculated, and the balance point of the PR curve is used as the optimal threshold Th. The values ​​less than or equal to Th in M ​​are judged as 0, and the values ​​greater than Th are judged as 1, where 1 represents an abnormal pixel and 0 represents a normal pixel, to obtain the anomaly localization mask map M'. The positions that are 0 in M' are set to 0 in the test image to obtain the image abnormal pixel localization result map.

4. An industrial image anomaly detection and positioning system based on local outlier factors, characterized by Includes the following modules: An acquisition module is used to obtain a training data set; Extraction module: used to extract features; Anomaly detection and location module: uses local outlier factor algorithm for anomaly detection and location; The extraction modules are as follows: The ResNet model obtained by pre-training is used as the feature extractor F, and the first three layers of the feature extractor are denoted as F3; for a given image x i , the extracted features f i , f i =F3(x i ); The anomaly detection and positioning module is divided into two parts: The first part is anomaly detection: the third layer output feature f of the ResNet network i , used as the input of LOF algorithm for training; The second part is anomaly localization: First, the output features of the first, second and third layers of the ResNet network are fused and reduced in dimension. The size of the fused feature map is 1792×56×56. After the dimension reduction, the dimension size of each superpixel on the feature map is 550×1. Finally, each superpixel is used as the input of the LOF algorithm for training. The anomaly detection process is as follows: Calculate the data point f i The kth distance from f i The kth farthest point to f i The Euclidean distance of k (f i ); Find f i The kth distance neighborhood N k (f i ) that is, f i All points within the kth distance of, including the kth distance; |N k (f i )|≥k, |·| represents the number of elements in the set, 0<k≤L, L is the total number of samples; Compute the local reachable density for each data point: Among them, reach_dist k (f i ,t) is f i and N k (f i ) is the reachable distance of a point t in the space. The calculation formula for the reachable distance is: reach_dist k (f i ,t)=max{d k (f i ),d(f i ,t)}; d(·,·) represents the Euclidean distance, t is N k (f i )Inside division f i a point outside; Calculate f i The local outlier factor of is used as the anomaly score: LOF k (f i ) represents point f i Neighborhood point N k (f i ) and the local reachability density of point f i The average of the ratio of the local reachable density of the sample to the local outlier factor; during the test, the local outlier factor is used as the abnormal score of the tested sample, and the threshold is set as th, 0<th<1, and the sample greater than the threshold th is judged as an abnormal sample, and the sample less than the threshold th is judged as a normal sample; The abnormality location process is as follows: Select the first, second, and third layer output features of the feature extractor F in the extraction module and fuse them to obtain the fused feature map Where N is the number of input training images, C s represents the sum of the number of output channels of the first, second and third layers, and H, W represents the resolution of the maximum output feature map; first, each channel of the output feature map of the first, second and third layers of the feature extractor F is enlarged to a feature map with a resolution of H×W, and then the output feature maps from different layers are connected front and back to obtain a fused feature map containing information of different semantic levels and resolutions, so as to realize encoding of different granularities and global contexts; The dimension of the fusion feature map P is reduced by random dimensionality reduction, and the channel dimension C of the fusion feature map P is reduced. s 550 dimensions are randomly selected from C s =1792; with superpixel p ij ∈P N×550×H×W As the input of LOF algorithm for training, (i,j)∈[1,W]×[1,H], calculate the kth distance d of each superpixel k (p ij ), and then find its k-th distance neighborhood; finally, calculate the local reachable density of each superpixel according to formula (1), and calculate the anomaly score according to formula (2).

Citation Information

Patent Citations

  • Gradient-based sample learning difficulty measurement method and device

    CN114492736A