Method for determining feature vector in anomaly detection, anomaly detection method and device
By using a pre-trained network model in anomaly detection to extract and fit the feature vectors of positive sample images, determine the angular space differences and enhance the attention weights, the over-detection problem caused by insufficient positive sample feature fitting ability is solved, and the detection accuracy is improved.
Patent Information
- Application Number
- CN202211711618.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2042-12-29
AI Technical Summary
In the existing technology, anomaly detection methods lack the bias of training positive samples and the ability to fit positive sample features when training positive sample features, resulting in serious over-detection of images to be detected.
The first eigenvector of the positive sample image is extracted through the pre-trained first network model, and the second network model with the same structure is triggered to fit the first network model. The difference value of the first and second eigenvectors in the angular space is determined, and the difference value is normalized to determine the attention weight. The first eigenvector is enhanced by the attention weight to form a target eigenvector for anomaly detection.
By introducing the difference features of the training fitting angle space, the interfering feature vectors are removed, the over-detection problem of the image to be detected is improved, and the detection accuracy is improved.
Smart Images

Figure CN115984216B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of industrial defect detection, and in particular to a method for determining a feature vector in anomaly detection, an anomaly detection method, and an anomaly detection device. Background Art
[0002] With the increasing application of deep learning models in the field of industrial defect detection, the deep learning model can be used to learn sample features and realize the detection of various defects in industrial products.
[0003] In some industrial defect detection scenarios, since negative samples (images with defects) are difficult to collect and positive samples (images without defects) are easy to collect, defect detection is performed using anomaly detection methods. This anomaly detection method only trains positive sample images. The degree of matching between the feature library composed of the positive sample features obtained after training and the image to be tested is used to determine whether the image to be tested has an anomaly, thereby achieving defect detection on the image to be tested.
[0004] However, in the process of training positive sample features, the anomaly detection method lacks the bias of training positive samples and the ability to fit the positive sample features, resulting in serious over-detection of the images to be detected. Summary of the Invention
[0005] In order to solve the serious problem of over-detection of images to be detected, the present application provides a method for determining a feature vector in anomaly detection, an anomaly detection method and an apparatus.
[0006] The embodiment of the present application is implemented as follows:
[0007] A first aspect of an embodiment of the present application provides a method for determining a feature vector in anomaly detection, comprising the following steps:
[0008] Pass the positive sample image through the pre-trained first network model to extract the first feature vector; trigger the second network model to fit the first network model, and extract the second feature vector from the positive sample image through the fitted second network model; wherein the second network model has the same structure as the first network model;
[0009] determining a difference between each first eigenvector and the corresponding second eigenvector in angular space;
[0010] Normalize the difference value and determine the attention weight of the corresponding position area in the positive sample image;
[0011] The first eigenvector is enhanced by the attention weight to determine the target eigenvector, which is used for anomaly detection.
[0012] A second aspect of the embodiments of the present application provides an anomaly detection method, comprising the following steps:
[0013] Extracting a fourth eigenvector of the image to be detected through the first network model;
[0014] Determine a fifth eigenvector having the smallest distance from the first position of the fourth eigenvector, wherein the first position is the position of a pixel of the fourth eigenvector in the test image to be tested, and the fifth eigenvector is a eigenvector in a target feature library, the target feature library being a feature library composed of target feature vectors determined by the method for determining a eigenvector in anomaly detection according to the first aspect of the invention;
[0015] Determine the anomaly score of the first position based on the fifth eigenvector and the fourth eigenvector,
[0016] Based on the anomaly score, the defects of the image to be inspected are determined.
[0017] A third aspect of the embodiments of the present application provides a device for determining a feature vector in anomaly detection, comprising an extraction module, an execution module, and a target feature vector determination module, wherein:
[0018] An extraction module is configured to pass a positive sample image through a pre-trained first network model to extract a first eigenvector; and trigger a second network model to fit the first network model, and extract a second eigenvector from the positive sample image through the fitted second network model; wherein the second network model has the same structure as the first network model;
[0019] an execution module, configured to determine a difference between each first eigenvector and the corresponding second eigenvector in an angular space;
[0020] The execution module is also used to normalize the difference value and determine the attention weight of the corresponding position area in the positive sample image;
[0021] A target feature vector determination module is configured to enhance the first feature vector using the attention weight to determine the target feature vector of the positive sample image, and the target feature vector is used for anomaly detection. A fourth aspect of an embodiment of the present application provides an anomaly detection device, comprising a feature extraction module, a feature determination module, and an anomaly determination module, wherein:
[0022] A feature extraction module, configured to extract a fourth feature vector of the image to be detected through the first network model;
[0023] a feature determination module, configured to determine a fifth eigenvector having the smallest distance from a first position of the fourth eigenvector, wherein the first position is a position of a pixel of the fourth eigenvector in the test image to be tested, and the fifth eigenvector is a eigenvector in a target feature library, wherein the target feature library is a feature library composed of target feature vectors determined by the method for determining a eigenvector in anomaly detection according to the first aspect of the invention;
[0024] an anomaly determination module, configured to determine an anomaly score of the first position based on the fifth eigenvector and the fourth eigenvector,
[0025] The defect detection module is used to determine defects in the image to be detected based on the anomaly score.
[0026] A fifth aspect of an embodiment of the present application provides a computer device including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the anomaly detection method of the second aspect of the invention are implemented.
[0027] A sixth aspect of an embodiment of the present application provides a computer storage medium, on which a computer program is stored. When the computer program is executed by a processor, the processor executes the steps of the anomaly detection method according to the second aspect of the invention.
[0028] The beneficial effects of the present application are as follows: a method for determining feature vectors in anomaly detection, wherein a positive sample image is passed through a pre-trained first network model to extract a first feature vector; and a second network model is triggered to fit the first network model, and a second feature vector is extracted from the positive sample image through the fitted second network model; wherein the second network model has the same structure as the first network model; the difference value between each first feature vector and the corresponding second feature vector in the angular space is determined; the difference value is normalized to determine the attention weight of the corresponding position area in the positive sample image; the first feature vector is enhanced by the attention weight to determine the target feature vector, and the target feature vector is used for anomaly detection; by introducing the difference feature of the trained fitting angular space, the interfering feature vector is removed, and the over-detection of the image to be detected is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0030] Figure 1 A schematic diagram of a flow chart of a method for determining a feature vector in anomaly detection provided by an embodiment of the present application is shown;
[0031] Figure 2a A schematic flow chart of another method for determining a feature vector in anomaly detection provided by an embodiment of the present application is shown;
[0032] Figure 2b A schematic flow chart of another method for determining a feature vector in anomaly detection provided by an embodiment of the present application is shown;
[0033] Figure 3 A schematic diagram of a process for detecting anomalies according to an embodiment of the present application is shown;
[0034] Figure 4 A schematic diagram of a process for determining defects in an image to be inspected is shown in an embodiment of the present application;
[0035] Figure 5 A schematic diagram of a process flow of another anomaly detection method provided by an embodiment of the present application is shown;
[0036] Figure 6 A schematic diagram of the structure of a device for determining a feature vector in anomaly detection provided by an embodiment of the present application is shown;
[0037] Figure 7 A schematic structural diagram of an anomaly detection device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0038] In order to make the purpose, implementation mode and advantages of the present application clearer, the exemplary implementation mode of the present application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only part of the embodiments of the present application, not all of the embodiments.
[0039] It should be noted that the brief descriptions of terms in this application are only for the purpose of facilitating the understanding of the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their ordinary and usual meanings.
[0040] In the specification and claims of this application and the accompanying drawings, the terms "first," "second," "third," etc. are used to distinguish similar or similar objects or entities, and are not necessarily intended to limit a particular order or sequence, unless otherwise noted. It should be understood that the terms used in this manner are interchangeable under appropriate circumstances.
[0041] The terms "comprise," "comprises," and "having," and any variations thereof, are intended to cover but not exclude inclusion; for example, a product or device comprising a list of components is not necessarily limited to all the components expressly listed but may include other components not expressly listed or inherent to such product or device.
[0042] In some industrial defect detection scenarios, deep learning models are difficult to train and learn because negative samples (images with defects) are difficult to collect and their number is small; positive samples (images without defects) are easy to collect and their number is large, so defect detection is performed through anomaly detection methods. This anomaly detection method only trains positive samples, and determines whether the image to be tested has an anomaly by comparing the degree of matching between the feature library composed of the trained feature vectors and the image to be tested, thereby realizing defect detection of the image to be tested.
[0043] In the process of training positive sample features, the above-mentioned anomaly detection methods lack the bias of training positive samples and the ability to fit positive sample features, resulting in serious over-detection of the images to be detected.
[0044] In order to improve over-detection of images to be detected, an embodiment of the present application provides a method for determining feature vectors in anomaly detection, an anomaly detection method and an apparatus, wherein a positive sample image is passed through a pre-trained first network model to extract a first feature vector; and a second network model is triggered to fit the first network model, and a second feature vector is extracted from the positive sample image through the fitted second network model; wherein the second network model has the same structure as the first network model; the difference value between each first feature vector and the corresponding second feature vector in the angular space is determined; the difference value is normalized to determine the attention weight of the corresponding position area in the positive sample image; the first feature vector is enhanced by the attention weight to determine the target feature vector, and the target feature vector is used for anomaly detection; by introducing the difference feature of the trained fitting angular space, the interfering feature vector is removed, and the over-detection of the image to be detected is improved.
[0045] The following describes in detail a method for determining a feature vector in anomaly detection, an anomaly detection method, and an apparatus according to an embodiment of the present application in conjunction with the accompanying drawings.
[0046] Figure 1 A flow chart of a method for determining a feature vector in anomaly detection provided by an embodiment of the present application is shown. Figure 1 As shown, an embodiment of the present application provides a method for determining a feature vector in anomaly detection.
[0047] The method for determining the feature vector in the anomaly detection includes the following steps:
[0048] S110, the positive sample image is passed through the pre-trained first network model to extract the first eigenvector; and the second network model is triggered to fit the first network model, and the second eigenvector is extracted from the positive sample image through the fitted second network model.
[0049] Positive sample image data is defect-free image data obtained in a specific industrial defect detection scenario.
[0050] The second network model has the same structure as the first network model. The pre-trained first network model can be a convolutional neural network (CNN), and the second network model is also a convolutional neural network.
[0051] In some embodiments, the scale and complexity of the positive sample image data are different, so first network models of different scales and sizes can be selected; the first network model and the second network model can be a model from the ResNet residual network series, RegNet series, EfficientNet series, ShuffleNet series, MobileNet series, etc.
[0052] In some embodiments, the first network model and the second network model may be variant structures in the above system. For example, the first network model and the second network model may be Resnet18 networks in a ResNet residual network.
[0053] It should be understood that the first network model is pre-trained, while the second network model is not pre-trained.
[0054] The positive sample image data is extracted with positive sample features through the pre-trained first network model. The positive sample features represent the image features of the positive sample image data, that is, the first feature vector; and the second network model is triggered to fit the first network model, and the first network model is learned to extract the second feature vector for the positive sample image.
[0055] It should be understood that the first eigenvector is the multi-scale image feature of the unbiased positive sample dataset, and the second eigenvector is the multi-scale image feature of the biased positive sample dataset.
[0056] In some embodiments, the size of the required training data can be adjusted by downsampling, for example, by 8x, 16x, or 32x. However, it should be noted that if the downsampling ratio is too small, the sample feature image will lack high-level semantic features and cause significant interference; if the downsampling ratio is too large, the feature image will lack spatial information, which is not conducive to detecting detailed anomalies. Therefore, a range of downsampling ratios can be pre-set. For example, an 8x downsampling ratio can be used to adjust the required training data.
[0057] S120: Determine a difference value between each first eigenvector and the corresponding second eigenvector in the angle space.
[0058] The difference value can be determined by the angle between the first eigenvector and the corresponding second eigenvector. The difference value reflects the perception of the feature distribution of the positive sample image and can adapt to changes in the distribution. The second eigenvector corresponding to a first eigenvector refers to the second eigenvector extracted from the same location in the positive sample image as the first eigenvector.
[0059] In some embodiments, the difference value can be calculated using the following formula:
[0060] t i,j =(x i / ||xi ||)·(x j / ||x j ||)
[0061] Where, t i,j is the difference between the first eigenvector and the corresponding second eigenvector, x i is the first eigenvector, x j is the second eigenvector.
[0062] It should be understood that the difference between normal samples and positive samples with background changes is small, while the difference between abnormal samples is large, which increases the bias perception of the normal sample distribution.
[0063] S130: Normalize the difference value and determine the attention weight of the corresponding position area in the positive sample image.
[0064] It should be understood that the difference value is determined by the angle between the first eigenvector and the corresponding second eigenvector, and therefore, the difference value also corresponds to the position area of the first eigenvector in the positive sample image.
[0065] By normalizing the difference values, the attention weights of different positions of the positive sample image can be obtained, thereby enhancing the unbiased first eigenvector extracted by the first network model.
[0066] In some embodiments, the attention weight of the corresponding position area in the positive sample image is determined, and the attention weight is calculated by the following formula:
[0067]
[0068] Where ω is the attention weight of the position area corresponding to the first eigenvector i in the positive sample image, t i,j is the difference between the first eigenvector i and the corresponding second eigenvector j, e is the base, and p is the number of pixels in the positive sample image.
[0069] In some embodiments, softmax normalization can be used on the difference value (first using the natural base e to expand the element gap and then normalize it) to determine the attention weight of the corresponding position area in the positive sample image. Alternatively, 2-norm normalization can be used on the difference value to determine the distribution-aware attention weight of the corresponding position area in the positive sample image, thereby enhancing the feature vector of the unbiased positive sample.
[0070] S140 , enhancing the first eigenvector using the attention weight to determine a target eigenvector, which is used for anomaly detection.
[0071] After performing weighted enhancement processing on the first eigenvector using the attention weight, a target eigenvector corresponding to the first eigenvector is obtained.
[0072] It should be understood that the target feature vector is used for anomaly detection, or the feature library composed of the target feature vector is used for anomaly detection.
[0073] Figure 2a FIG2 shows a flow chart of another method for determining a feature vector in anomaly detection provided by an embodiment of the present application. Figure 2b FIG. 1 shows a flow chart of another method for determining a feature vector in anomaly detection provided by an embodiment of the present application, such as Figure 2a As shown, step 140 enhances the first feature vector by using the attention weight to determine the target feature vector, which may include the following steps:
[0074] S141. After enhancing the first eigenvector using the attention weight, determine the enhanced first eigenvector as a target eigenvector.
[0075] Or, as Figure 2b As shown, step 140 enhances the first feature vector by using the attention weight to determine the target feature vector, which may include the following steps:
[0076] S142: Perform clustering on the enhanced first feature vector to determine at least one vector set, wherein the enhanced first feature vectors included in each vector set belong to the same category.
[0077] For each first eigenvector, there may be identical or similar data. By clustering, at least one vector set is determined. The vector set is determined based on the category of each first eigenvector, that is, for each vector set, the first eigenvectors contained therein belong to the same category.
[0078] In some embodiments, clustering can be achieved by sampling Coresets (key data sets, core sets). Extracting Coresets and then clustering can reduce the amount of computation and may also reduce the impact of outliers, thereby making the model more robust.
[0079] S143. Select a target feature vector from the vector set.
[0080] By clustering, a target feature vector can be determined from each vector set determined above. It should be understood that the target feature vector can be equal to the first feature vector in the vector set, or can be data close to the first feature vector in the vector set.
[0081] An embodiment of the present application provides a method for determining feature vectors in anomaly detection, which extracts a first feature vector from a positive sample image through a pre-trained first network model; triggers a second network model to fit the first network model, and extracts a second feature vector from the positive sample image through the fitted second network model; wherein the second network model has the same structure as the first network model; determines the difference value between each first feature vector and the corresponding second feature vector in the angular space; normalizes the difference value to determine the attention weight of the corresponding position area in the positive sample image; enhances the first feature vector through the attention weight to determine the target feature vector, which is used for anomaly detection; removes interfering feature vectors by introducing the difference feature of the trained fitting angular space, and improves over-detection of the image to be detected.
[0082] Figure 3 The flowchart of an abnormality detection method provided by the embodiment of the present application is shown as follows: Figure 3 As shown, an embodiment of the present application provides an anomaly detection method.
[0083] The anomaly detection method includes the following steps:
[0084] S210 . Extracting a fourth eigenvector of the image to be detected through the first network model.
[0085] Obtain an image to be inspected that requires abnormality detection. The image to be inspected can be obtained by capturing the target object through a visual inspection device.
[0086] The image to be detected is passed through the first network model to extract the fourth eigenvector of the image to be detected. The first network model is a pre-trained model; the first network model can be a convolutional neural network, for example, the Resnet18 network in the ResNet residual network.
[0087] Each fourth eigenvector corresponds to a position in the image to be detected.
[0088] In some embodiments, the fourth eigenvector of the image to be detected is extracted through the first network model, and the length of the third eigenvector can also be extracted.
[0089] S220. Determine a fifth eigenvector having the smallest distance from a first position of each fourth eigenvector, wherein the first position is a pixel position of the fourth eigenvector in the test image to be tested, and the fifth eigenvector is a eigenvector in a target feature library; the target feature library is a feature library composed of target feature vectors determined by a method for determining a eigenvector in anomaly detection.
[0090] It should be understood that the fifth eigenvector having the smallest distance to the fourth eigenvector can be found in the target feature library by traversing the fourth eigenvectors at each first position in the image to be detected.
[0091] Among them, the target feature library is obtained by Figure 1 、 Figure 2a 、 Figure 2b The feature library composed of the target feature vectors determined by the method for determining the feature vectors in the anomaly detection is composed of the fifth feature vectors of each target feature vector. Therefore, in the process of determining the fifth feature vector with the smallest distance from the first position of each fourth feature vector in step 220, the amount of data of the fifth feature vector that needs to be compared is small, and the effectiveness of the target feature library is improved.
[0092] In some embodiments, the distance between the fourth eigenvector and the fifth eigenvector may be determined by a Euclidean distance calculation.
[0093] S230 : Determine an anomaly score of the first position according to the fifth eigenvector and the fourth eigenvector.
[0094] The anomaly score of the first position may be calculated and determined by using the fourth eigenvector corresponding to the first position and the fifth eigenvector having the smallest distance from the fourth eigenvector.
[0095] In some embodiments, the anomaly score of the first position is calculated using the following formula:
[0096] S=||xx n ||
[0097] Where S is the anomaly score of the first position, x is the fourth eigenvector extracted at the first position; x n is the fifth eigenvector.
[0098] S240: Determine defects of the image to be detected based on the anomaly score.
[0099] Based on the abnormality scores of the first positions, a defect in the image to be detected is determined, where the defect includes a position of the defect.
[0100] Figure 4 FIG. 1 shows a flow chart of a defect determination process for an image to be detected provided by an embodiment of the present application. Figure 4 As shown, step 240 includes the following steps:
[0101] S241 : Determine an initial anomaly score map corresponding to the image to be detected based on the anomaly scores of the first positions.
[0102] It should be understood that the initial anomaly score map is composed of the anomaly scores of each first position, and the anomaly scores of each position in the initial anomaly score map correspond one-to-one to each pixel of the image to be detected. The initial anomaly score map and the image to be detected have the same size.
[0103] S242: Normalize the initial anomaly score map to determine a target anomaly score map, where the target anomaly score map represents an anomaly probability score of each first position in the image to be detected.
[0104] The initial anomaly score map may be normalized to determine a normalized target anomaly score map. The data in the target anomaly score map is not the anomaly score of each first position, but represents the anomaly probability score of each first position in the image to be detected.
[0105] In some embodiments, the initial anomaly score map may be normalized to a grayscale space or a color space. That is, the normalized target anomaly score map may be a grayscale image or a color image.
[0106] S243: If the abnormality probability score is greater than the preset abnormality threshold, determine that there is a defect in the image to be detected, and the defect is located at the corresponding first position.
[0107] A preset threshold is used to determine whether each abnormal probability score in the target abnormal score map is abnormal. If the abnormal probability score is greater than the preset abnormal threshold, the corresponding first position is determined to be a defect in the image to be detected. If the abnormal probability score is not greater than the preset abnormal threshold, the corresponding first position is determined to be a non-defect in the image to be detected.
[0108] At the same time, the position of the abnormal probability score can determine the position of the defect in the image to be detected.
[0109] Figure 5 FIG. 1 shows a flow chart of another anomaly detection method provided by an embodiment of the present application, such as Figure 5 As shown, the embodiment of the present application provides an abnormality detection method. Figure 3 The image to be detected in step 210 is an image obtained by downsampling the initial detection image according to a preset downsampling factor. The corresponding step 230 determines defects in the image to be detected based on the anomaly score. The corresponding data also needs to be upsampled. The anomaly detection method includes the following steps:
[0110] S310 , obtaining an initial detection image, and downsampling the initial detection image according to a preset downsampling factor to determine an image to be detected.
[0111] The initial detection image can be obtained by collecting the target object to be detected through a visual detection device, and the obtained initial detection image is downsampled according to a preset downsampling multiple to determine the image to be detected.
[0112] S320: Extracting a fourth eigenvector of the image to be detected through the first network model.
[0113] The image to be detected is passed through the first network model to extract the fourth eigenvector of the image to be detected. The first network model is a pre-trained model; the first network model can be a convolutional neural network, for example, the Resnet18 network in the ResNet residual network.
[0114] Each fourth eigenvector corresponds to a position in the image to be detected.
[0115] S330 , determining a fifth eigenvector having the smallest distance from a first position of each fourth eigenvector, wherein the first position is a pixel position of the fourth eigenvector in the test image to be tested, and the fifth eigenvector is a eigenvector in the target feature library.
[0116] Among them, the target feature library is obtained through the above Figure 1 、 Figure 2a 、 Figure 2b The feature library composed of the target feature vectors determined by the feature vector determination method in the described anomaly detection is a feature library after removing redundant data. Therefore, in the process of determining the fifth feature vector with the smallest distance from the first position of each fourth feature vector in step 220, the amount of data of the fifth feature vector that needs to be compared is small, and the effectiveness of the target feature library is improved.
[0117] S340: Determine an anomaly score of the first position based on the fifth eigenvector and the fourth eigenvector.
[0118] The anomaly score of the first position may be calculated and determined by using the fourth eigenvector corresponding to the first position and the fifth eigenvector having the smallest distance from the fourth eigenvector.
[0119] In some embodiments, the anomaly score of the first position is calculated using the following formula:
[0120] S=||xx n ||
[0121] Where S is the anomaly score of the first position, x is the fourth eigenvector extracted at the first position; x n is the fifth eigenvector.
[0122] S350: Determine an initial anomaly score map corresponding to the image to be detected based on the anomaly scores of the first positions.
[0123] The initial anomaly score map is composed of the anomaly scores of each first position, and the anomaly score of each position in the initial anomaly score map corresponds one-to-one to each pixel point of the image to be detected. The initial anomaly score map and the image to be detected have the same size.
[0124] S360: upsampling the initial anomaly score map based on an upsampling multiple corresponding to a preset downsampling multiple to determine an alternative anomaly score map.
[0125] The initial anomaly score map is upsampled by an upsampling multiple corresponding to a preset downsampling multiple to determine an alternative anomaly score map.
[0126] S370: Normalize the candidate anomaly score maps to determine a target anomaly score map, where the target anomaly score map represents an anomaly probability score of each second position in the initial detection image.
[0127] The initial anomaly score map can be normalized to a grayscale space or a color space to determine a normalized target anomaly score map. The data in the target anomaly score map is not the anomaly score of each first position, but represents the anomaly probability score of each first position in the image to be detected.
[0128] S380: If the abnormality probability score is greater than the preset abnormality threshold, determine a defect in the initial detection image, and the defect is located at the corresponding second position.
[0129] A preset threshold is used to determine whether each abnormal probability score in the target abnormal score map is abnormal. If the abnormal probability score is greater than the preset abnormal threshold, the corresponding first position is determined to be a defect in the image to be detected. If the abnormal probability score is not greater than the preset abnormal threshold, the corresponding first position is determined to be a non-defect in the image to be detected.
[0130] An embodiment of the present application provides an anomaly detection method, which extracts the fourth eigenvector of the image to be detected through a first network model; determines the fifth eigenvector with the smallest distance from the first position of each fourth eigenvector, wherein the first position is the position of the pixel of the fourth eigenvector in the image to be detected, and the fifth eigenvector is a eigenvector in a target feature library, which is a feature library composed of target feature vectors determined by a method for determining eigenvectors in anomaly detection; determines the anomaly score of the first position based on the fifth eigenvector and the fourth eigenvector, determines the defect of the image to be detected based on the anomaly score, removes interfering eigenvectors by introducing difference features in the training fitting angle space, and improves over-detection of the image to be detected.
[0131] Figure 6 FIG. 1 shows a schematic diagram of a structure of a device for determining a feature vector in anomaly detection according to an embodiment of the present application. Figure 6 As shown, the device 600 for determining a feature vector in anomaly detection includes an extraction module 610, an execution module 620, and a target feature vector determination module 630, wherein:
[0132] The extraction module is used to extract the first feature vector from the positive sample image through the pre-trained first network model; and trigger the second network model to fit the first network model, and extract the second feature vector from the positive sample image through the fitted second network model; wherein the second network model has the same structure as the first network model.
[0133] The execution module is used to determine the difference between each first eigenvector and the corresponding second eigenvector in the angular space; and is also used to normalize the difference value and determine the attention weight of the corresponding position area in the positive sample image.
[0134] The target feature vector determination module is used to enhance the first feature vector through the attention weight to determine the target feature vector of the positive sample image, and the target feature vector is used for anomaly detection.
[0135] The implementation principle and technical effects are similar to those of the above method embodiment and will not be repeated here.
[0136] Figure 7 A schematic diagram of the structure of an abnormality detection device provided in an embodiment of the present application is shown in FIG. Figure 7 As shown, the abnormality detection device 700 includes a feature extraction module 710, a feature determination module 720, an abnormality determination module 730 and a defect detection module 640, wherein:
[0137] A feature extraction module, configured to extract a fourth feature vector of the image to be detected through the first network model;
[0138] a feature determination module, determining a fifth eigenvector having the smallest distance from a first position of the fourth eigenvector, wherein the first position is a position of a pixel of the fourth eigenvector in the test image to be tested, and the fifth eigenvector is a eigenvector in a target feature library, wherein the target feature library is a feature library composed of target feature vectors determined by a method for determining a eigenvector in anomaly detection;
[0139] an anomaly determination module, configured to determine an anomaly score of the first position based on the fifth eigenvector and the fourth eigenvector,
[0140] The defect detection module determines the defects of the image to be detected based on the anomaly score.
[0141] In some embodiments, the defect detection module includes a first anomaly unit and a detection unit. The anomaly unit is used to determine an initial anomaly score map corresponding to the image to be detected based on the anomaly score of each first position; and is also used to normalize the initial anomaly score map to determine a target anomaly score map, which represents the anomaly probability score of each first position in the image to be detected.
[0142] The detection unit is configured to determine that the corresponding first position is a defect in the image to be detected if the abnormality probability score is greater than a preset abnormality threshold.
[0143] In some embodiments, if the image to be detected is an image of the initial detection image that is downsampled according to a preset downsampling multiple, the defect detection module includes a second abnormality unit and a detection unit, and the second abnormality unit is used to determine an initial abnormality score map corresponding to the image to be detected based on the abnormality scores of each first position; it is also used to upsample the initial abnormality score map based on an upsampling multiple corresponding to the preset downsampling multiple to determine an alternative abnormality score map; it is also used to normalize the alternative abnormality score map to determine a target abnormality score map, and the target abnormality score map represents the abnormality probability score of each second position in the initial detection image.
[0144] The detection unit is configured to determine that the corresponding second position is a defect in the initial detection image if the abnormality probability score is greater than a preset abnormality threshold.
[0145] The anomaly detection device provided in the embodiment of the present application includes a feature extraction module, a feature judgment module, an anomaly determination module and a defect detection module. The fourth eigenvector of the image to be detected is extracted through a first network model; the fifth eigenvector with the smallest distance from the first position of each fourth eigenvector is determined, wherein the first position is the position of the pixel of the fourth eigenvector in the image to be detected, the fifth eigenvector is a eigenvector in a target feature library, and the feature library is composed of target eigenvectors determined by the method for determining the eigenvector in anomaly detection; the anomaly score of the first position is determined according to the fifth eigenvector and the fourth eigenvector, and the defect of the image to be detected is determined based on the anomaly score, and the interference eigenvectors are removed by introducing the difference features of the training fitting angle space, thereby improving the over-detection of the image to be detected.
[0146] An embodiment of the present application also provides a terminal device, including a memory and a processor, wherein the memory stores a computer program, and is characterized in that the above-mentioned anomaly detection method is implemented when the processor executes the computer program. The implementation principle and technical effect are similar to those of the above-mentioned method embodiment and will not be repeated here.
[0147] An embodiment of the present application also provides a computer storage medium, on which a computer program is stored. When the computer program is executed by a processor, the processor executes the above-mentioned anomaly detection method. The implementation principle and technical effect are similar to those of the above-mentioned method embodiment and will not be repeated here.
[0148] The following paragraphs will compare and list the Chinese terms involved in this application specification and their corresponding English terms to facilitate reading and understanding.
[0149] For ease of explanation, the above description has been made in conjunction with specific embodiments. However, the above discussion of some embodiments is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. Based on the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are intended to better explain the principles and practical applications, so that those skilled in the art can better use the embodiments and various different variations of the embodiments suitable for specific use considerations.
Claims
1. A method for determining a feature vector in anomaly detection, characterized in that: include: Pass the positive sample image through the pre-trained first network model to extract the first feature vector; and triggering a second network model to fit the first network model, and extracting a second feature vector from the positive sample image through the fitted second network model; wherein the second network model has the same structure as the first network model; determining a difference value between each first eigenvector and the corresponding second eigenvector in an angular space; Normalizing the difference value and determining the attention weight of the corresponding position area in the positive sample image; Performing enhancement processing on the first feature vector by using the attention weight to determine a target feature vector of the positive sample image includes: After performing enhancement processing on the first feature vector using the attention weight, determining the enhanced first feature vector as the target feature vector; or, Performing clustering on the enhanced first feature vector to determine at least one vector set, wherein the enhanced first feature vectors included in each vector set belong to the same category; Selecting a target feature vector from the vector set; The target feature vector is used for anomaly detection.
2. The method for determining a feature vector in anomaly detection according to claim 1, wherein: Normalize the difference value and determine the attention weight of the corresponding position area in the positive sample image. The attention weight is calculated by the following formula: Where ω is the attention weight of the position area corresponding to the first eigenvector i in the positive sample image, t i,j is the difference between the first eigenvector i and the corresponding second eigenvector j, e is the base, and p is the number of pixels in the positive sample image.
3. An anomaly detection method, characterized in that: include: Extracting a fourth eigenvector of the image to be detected through the first network model; Determine a fifth eigenvector having the smallest distance from a first position of the fourth eigenvector, wherein the first position is a position of a pixel of the fourth eigenvector in the test image to be tested, and the fifth eigenvector is a eigenvector in a target feature library, wherein the target feature library is a feature library composed of target feature vectors determined by the method for determining a eigenvector in anomaly detection according to claim 1 or 2; determining an anomaly score of the first position based on the fifth eigenvector and the fourth eigenvector, The anomaly score of the first position is calculated by the following formula: S=||x-x n || Where S is the anomaly score of the first position, x is the fourth eigenvector extracted at the first position; x n is the fifth eigenvector; Defects of the image to be detected are determined based on the anomaly score.
4. The anomaly detection method according to claim 3, wherein: If the image to be detected is an image obtained by downsampling the initial detection image according to a preset downsampling factor, determining defects of the image to be detected based on the anomaly score includes: determining an initial anomaly score map corresponding to the image to be detected based on the anomaly scores of each of the first positions; Upsampling the initial anomaly score map based on an upsampling multiple corresponding to the preset downsampling multiple to determine an alternative anomaly score map; Normalizing the candidate anomaly score map to determine a target anomaly score map, where the target anomaly score map represents an anomaly probability score of each second position in the initial detection image; If the abnormality probability score is greater than the preset abnormality threshold, a defect in the initial detection image is determined, and the defect is located at the corresponding second position.
5. A device for determining a feature vector in anomaly detection, characterized in that: include: An extraction module, configured to pass the positive sample image through a pre-trained first network model to extract a first feature vector; and triggering a second network model to fit the first network model, and extracting a second feature vector from the positive sample image through the fitted second network model; wherein the second network model has the same structure as the first network model; an execution module, configured to determine a difference value between each first eigenvector and the corresponding second eigenvector in an angular space; The execution module is further configured to normalize the difference value and determine the attention weight of the corresponding position area in the positive sample image; A target feature vector determination module, configured to enhance the first feature vector using the attention weight to determine a target feature vector of the positive sample image, includes: After performing enhancement processing on the first feature vector using the attention weight, determining the enhanced first feature vector as the target feature vector; or, Performing clustering on the enhanced first feature vector to determine at least one vector set, wherein the enhanced first feature vectors included in each vector set belong to the same category; Selecting a target feature vector from the vector set; The target feature vector is used for anomaly detection.
6. An abnormality detection device, characterized in that: include: A feature extraction module, configured to extract a fourth feature vector of the image to be detected through the first network model; a feature determination module, configured to determine a fifth eigenvector having the smallest distance from a first position of the fourth eigenvector, wherein the first position is a position of a pixel of the fourth eigenvector in the test image to be tested, and the fifth eigenvector is a eigenvector in a target feature library, wherein the target feature library is a feature library composed of target feature vectors determined by the method for determining a eigenvector in anomaly detection according to any one of claims 1 to 3; an anomaly determination module, configured to determine an anomaly score of the first position based on the fifth eigenvector and the fourth eigenvector; The anomaly score of the first position is calculated by the following formula: S=||x-x n || Where S is the anomaly score of the first position, x is the fourth eigenvector extracted at the first position; x n is the fifth eigenvector; A defect detection module is configured to determine defects in the image to be detected based on the anomaly score.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the abnormality detection method according to claim 3 or 4 are implemented.
8. A computer storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the steps of the abnormality detection method according to claim 3 or 4.
Citation Information
Patent Citations
A user comment emotion analysis system and method based on attention convolution neural network
CN109284506A
Knowledge distillation-based positive sample industrial defect detection method
CN112991330A
Image anomaly detection method and device, storage medium and electronic equipment
CN114820540A