Apparatus image distribution outlier detection method based on a composite score function

By constructing an equipment image detection model with a comprehensive scoring function and designing an anomaly detection method using multiple heterogeneous feature factors, the problem of decision-making errors in identifying novel out-of-distribution anomaly types in existing technologies is solved, thereby improving the accuracy and efficiency of detection.

CN118521547BActive Publication Date: 2026-11-24UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410638121.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-22
Publication Date
2026-11-24
Estimated Expiration
2044-05-22

AI Technical Summary

Technical Problem

Existing out-of-distribution anomaly detection methods are prone to decision-making errors when identifying novel out-of-distribution anomaly types, and existing methods lack comprehensive utilization of the feature factors of heterogeneous samples, resulting in poor detection efficiency or insufficient robustness.

Method used

A comprehensive scoring function-based approach is adopted. By collecting and annotating equipment images, a detection model including feature extraction, mapping, and category prediction modules is constructed. By utilizing various heterogeneous feature factors such as feature norm, logistic probability score, Euclidean distance, and similarity difference, a comprehensive score for out-of-distribution anomaly detection is designed to improve detection accuracy.

Benefits of technology

By comprehensively considering various heterogeneous feature factors and increasing the difference between samples inside and outside the distribution, the accuracy of detecting anomalies outside the equipment image distribution is improved, and the robustness and detection efficiency of the model are enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118521547B_ABST
    Figure CN118521547B_ABST
Patent Text Reader

Abstract

This invention discloses a method for detecting out-of-distribution anomalies in equipment images based on a comprehensive scoring function. First, a training sample set is obtained by acquiring several equipment images. Then, each equipment image sample undergoes image enhancement processing. The original equipment image sample and the enhanced equipment image sample are combined to form a positive sample pair. An equipment detection model is constructed, including a feature extraction module, a mapping module, and a linear module. The contrast loss is calculated based on the positive sample pairs, and the cross-entropy loss is calculated based on the original equipment image samples. The equipment detection model is then trained. Each equipment image sample and a test equipment image are input into the trained equipment detection model. Based on the obtained features, a comprehensive score for out-of-distribution anomalies is calculated, thereby obtaining the detection result of whether the test equipment image is an out-of-distribution anomalous device. This invention integrates multiple heterogeneous feature factors obtained during the training process of in-distribution samples to design a comprehensive score for out-of-distribution anomaly detection, thereby improving the accuracy of out-of-distribution anomaly detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer vision technology, and more specifically, relates to a method for detecting out-of-distribution anomalies in equipment images based on a comprehensive scoring function. Background Technology

[0002] Currently, with the widespread application of computer vision systems, emerging industries are booming. While bringing convenience, the security issues they present are also a potential threat. A safe and stable artificial intelligence system should ensure accurate predictions of objects within its assumed scope, while also detecting unknown targets and issuing warnings to the user. Image out-of-distribution anomaly detection tasks determine whether the input image is an in-distribution (ID) semantic type existing in the database or an out-of-distribution (OOD) semantic type completely unknown to the system, ensuring the system is not affected by external anomalous data. However, when computer vision systems perform image recognition of target objects, if the system identifies a new type of out-of-distribution anomaly as an existing type in the system, it will lead to decision-making errors. Therefore, out-of-distribution anomaly detection methods for equipment images require in-depth research.

[0003] The key tasks in out-of-distribution anomaly detection in images mainly include feature extraction of in-distribution samples and anomaly detection of out-of-distribution samples. Feature extraction methods for in-distribution samples are relatively mature, and methods based on contrastive learning can effectively extract the distribution features of in-distribution samples. Anomaly detection of out-of-distribution samples typically employs anomaly scoring functions. Anomaly scores are calculated based on sample features obtained from a neural network encoder and compared with a threshold to determine whether an input sample belongs to the out-of-distribution anomaly category. Mainstream anomaly detection scoring function methods include: confidence-based scoring functions, feature norm-based scoring functions, and Mahalanobis distance-based scoring functions. Among these, confidence-based methods can pose a threat to the system due to generating high confidence for anomalous samples; feature norm-based methods, while robust, have poor anomaly detection efficiency; and Mahalanobis distance-based methods are unsuitable for situations with small sample sizes or high dimensionality because they do not satisfy matrix inversion operations. Furthermore, these methods usually only consider one feature factor as the evaluation criterion for out-of-distribution anomalies, lacking comprehensive utilization of feature factors from heterogeneous samples. Summary of the Invention

[0004] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method for detecting out-of-distribution anomalies in equipment images based on a comprehensive scoring function. This method integrates multiple heterogeneous feature factors obtained during the training process of in-distribution samples, including the feature norm of the input sample, the logistic probability score, the Euclidean distance between the input sample and the center of the in-distribution samples, and the similarity difference between the input sample and the in-distribution samples, to design a comprehensive score for out-of-distribution anomaly detection, thereby improving the accuracy of out-of-distribution anomaly detection.

[0005] To achieve the above-mentioned objectives, the equipment image distribution anomaly detection method based on a comprehensive scoring function includes the following steps:

[0006] S1: Collect several equipment images according to actual needs, and label them with categories to obtain the training sample set X = {x1, x2, ..., x...} N},Y={y1,y2,...,y N}, where N represents the number of equipped images in the training sample set, x i Let y represent the i-th equipment image sample. i It is an equipment image sample x i The corresponding label, y i =1,2,…,C, where C represents the number of equipment categories;

[0007] S2: For each equipment image sample x in the training sample set X... i Normalized to a preset size, then image enhancement processing is performed. The enhanced image is then randomly flipped twice to obtain two enhanced equipment image samples. Thus, N positive sample pairs are obtained.

[0008] S3: Construct an equipment detection model, including a feature extraction module, a mapping module, and a category prediction module, wherein:

[0009] The feature extraction module is used to extract image features from the input equipment image and output the obtained feature vector z to the mapping module and the category prediction module;

[0010] The mapping module is used to map the feature vector z to a low-dimensional feature vector h;

[0011] The category prediction module is used to obtain the probability p that the input equipment image belongs to each category, predicted based on the feature vector z. c c = 1, 2, ..., C;

[0012] S4: Pair the N positive samples obtained in step S2 Image samples of medium-strengthened equipment The equipment detection model is trained by inputting the corresponding low-dimensional feature vectors and the predicted probabilities of each category. The loss function is then calculated and the model parameters are updated. The loss function is calculated as follows:

[0013] The positive sample pairs are calculated using the following formula. The contrastive loss of low-dimensional feature vectors:

[0014]

[0015]

[0016] in, These represent enhanced equipment image samples. The low-dimensional feature vector, sim() represents calculating the vector similarity, τ represents the temperature coefficient, 1 [j≠i] This is an indicator function; it is 1 when j ≠ i, and 0 otherwise.

[0017] Then, the overall contrastive loss L of the training sample set is calculated using the following formula. CL :

[0018]

[0019] The cross-entropy loss L of the training sample set is calculated using the following formula. CE :

[0020]

[0021] Among them, y ic Indicates equipment image sample x i The probability of belonging to category c, when y i =c,y ic =1, otherwise y ic =0; p i,1,c p i,2,c These represent enhanced equipment image samples. The predicted probability of belonging to each category;

[0022] The loss function Loss of the equipment detection model during training is calculated using the following formula:

[0023] Loss=λL CE +(1-λ)L CL

[0024] Where λ represents the preset weight, 0 < λ < 1;

[0025] S5: Transfer the image samples of each equipment x i Input the trained equipment detection model and obtain the feature z output by the feature extraction module.i For each equipment category c, calculate the average feature of all equipment image samples belonging to that category as the in-distribution sample center o corresponding to that category. c ;

[0026] S6: For test equipment images x that require anomaly detection t After normalizing it to a preset size, it is input into the trained equipment detection model to obtain the feature z output by the feature extraction module. t The low-dimensional feature vector h output by the mapping module t And the test equipment image x output by the category prediction module t The predicted probability p of belonging to each category tc ;

[0027] S7: The comprehensive score for distribution anomalies is calculated using the following method:

[0028] S7.1: Calculate the eigenvector z t The sum of the elements in each dimension is used as the image feature evaluation score in the out-of-distribution anomaly scoring function. sum The calculation formula is:

[0029]

[0030] Among them, z t (m) represents the eigenvector z t The m-th element in the vector z, where m = 1, 2, ..., M, represents the eigenvector z. t The dimension;

[0031] S7.2: Calculate the low-dimensional eigenvector h t The feature norm is used as a low-dimensional feature vector in the out-of-distribution anomaly scoring function to evaluate the score. L2 The calculation formula is:

[0032]

[0033] Among them, h t (d) represents the low-dimensional feature vector h t The d-th element in the vector, d = 1, 2, ..., D, where D represents the low-dimensional eigenvector h. t The dimension;

[0034] S7.3: Use the maximum class probability obtained from the class prediction module as the class prediction evaluation score in the out-of-distribution anomaly scoring function. class The calculation formula is:

[0035] score class =max(p tc )

[0036] S7.4: Calculate the distance between the test equipment image and the center of the distributed samples as the score for evaluating the distance between the distributed samples. dis The calculation formula is:

[0037]

[0038] S7.5: From N equipment image samples x i Features z i Image x of search and test equipment t Features z t The K features with the highest similarity are selected, with the value of K determined based on actual needs. The variance of these K features is then calculated as the variance score for the samples within the most similar distribution. var :

[0039]

[0040] in, This represents the calculation of features z in an image sample. t The k-th feature among the K features with the highest similarity;

[0041] S7.6: The out-of-distribution anomaly composite score is calculated using the following formula:

[0042]

[0043] S8: Based on the comprehensive score of out-of-distribution anomalies calculated in step S7, compare it with the preset anomaly score threshold δ. When the comprehensive score of out-of-distribution anomalies is higher than the threshold, the test equipment image is identified as a sample of normal equipment type within the distribution; when the comprehensive score of out-of-distribution anomalies is lower than the threshold, the test equipment image is identified as a sample of out-of-distribution abnormal equipment type.

[0044] This invention relates to an equipment image out-of-distribution anomaly detection method based on a comprehensive scoring function. First, a training sample set is obtained by acquiring several equipment images. Then, each equipment image sample undergoes image enhancement processing. The original equipment image sample and the enhanced equipment image sample are combined to form a positive sample pair. An equipment detection model is constructed, including a feature extraction module, a mapping module, and a linear module. The contrast loss is calculated based on the positive sample pair, and the cross-entropy loss is calculated based on the original equipment image sample. The equipment detection model is then trained. Each equipment image sample and the test equipment image are input into the trained equipment detection model. Based on the obtained features, a comprehensive score for distribution anomalies is calculated, thereby obtaining the detection result of whether the test equipment image is an out-of-distribution anomalous device.

[0045] The present invention has the following beneficial effects:

[0046] 1) In the model training stage, this invention improves the model training effect by comparing the learning loss function and the cross-entropy loss function to extract the features of the samples within the distribution.

[0047] 2) During the detection phase, a variety of heterogeneous feature factors are comprehensively considered. By considering the feature factors from different feature perspectives to distinguish between samples inside and outside the distribution, the difference between samples inside and outside the distribution can be increased, thereby improving the accuracy of detecting anomalies outside the distribution of equipment images. Attached Figure Description

[0048] Figure 1 This is a flowchart illustrating a specific implementation of the equipment image distribution anomaly detection method based on a comprehensive scoring function according to the present invention.

[0049] Figure 2 This is a structural diagram of the equipment detection model in this invention;

[0050] Figure 3 This is a flowchart for calculating the comprehensive score of out-of-distribution anomalies in this invention. Detailed Implementation

[0051] The specific embodiments of the present invention will now be described with reference to the accompanying drawings to enable those skilled in the art to better understand the invention. It should be particularly noted that in the following description, detailed descriptions of known functions and designs that might obscure the main content of the invention will be omitted here.

[0052] Example

[0053] Figure 1 This is a flowchart illustrating a specific implementation of the equipment image distribution anomaly detection method based on a comprehensive scoring function according to the present invention. Figure 1 As shown, the specific steps of the equipment image distribution anomaly detection method based on the comprehensive scoring function of the present invention include:

[0054] S101: Training samples for acquiring images of the equipment:

[0055] Based on actual needs, collect several equipment images and label them with categories to obtain a training sample set X = {x1, x2, ..., x...} N},Y={y1,y2,...,y N}, where N represents the number of equipped images in the training sample set, x i Let y represent the i-th equipment image sample. i It is an equipment image sample x i The corresponding label, y i =1,2,…,C, where C represents the number of equipment categories.

[0056] S102: Generate positive sample pairs:

[0057] For each equipment image sample x in the training sample set X i Normalized to a preset size, then image enhancement processing is performed. The enhanced image is then randomly flipped twice to obtain two enhanced equipment image samples. Thus, N positive sample pairs are obtained.

[0058] The specific method of image enhancement processing can be set according to actual needs. In this embodiment, the specific method of image enhancement processing is as follows: randomly crop the equipment image sample normalized to a preset size according to the specified size, partially blur the cropped image by adding a Gaussian blur filter, and then randomly change the brightness, contrast, saturation or hue of the image by adding perturbation.

[0059] S103: Constructing an equipment detection model:

[0060] Figure 2 This is a structural diagram of the equipment detection model in this invention. (For example...) Figure 2 As shown, the equipment detection model in this invention includes a feature extraction module, a mapping module, and a category prediction module. Each module will be described in detail below.

[0061] The feature extraction module extracts image features from the input equipment image and outputs the resulting feature vector z to the mapping module and the category prediction module. In this embodiment, the feature extraction module uses a ResNet-18 network.

[0062] The mapping module is used to map the feature vector z to a low-dimensional feature vector h, thereby filtering out sparse vectors with irrelevant representations in the high-dimensional feature vector and obtaining an instance-level representation of the input equipment feature map.

[0063] like Figure 2 As shown, in this embodiment, the mapping module includes a first fully connected layer (FC), a ReLU function layer, and a second fully connected layer, wherein:

[0064] The first fully connected layer is used to process the feature vector z and send the resulting feature vector to the ReLU function layer;

[0065] The ReLU function layer is used to process the received feature vector using the ReLU activation function, and then sends the resulting feature vector to the second fully connected layer.

[0066] The second fully connected layer processes the received feature vectors and outputs the resulting feature vectors as low-dimensional feature vectors h.

[0067] The category prediction module is used to obtain the probability p that the input equipment image belongs to each category, predicted based on the feature vector z. c c = 1, 2, ..., C. For example... Figure 2 As shown, the category prediction module in this embodiment includes a fully connected layer and a Softmax layer, wherein:

[0068] The fully connected layer is used to process the feature vector z and send the resulting feature vector to the Softmax layer;

[0069] The softmax layer is used to predict the probability p that the input equipment image belongs to each category based on the received feature vectors. c .

[0070] S104: Training the equipment detection model:

[0071] The N positive sample pairs obtained in step S102 Image samples of medium-strengthened equipment The equipment detection model is trained by inputting the corresponding low-dimensional feature vectors and the predicted probabilities of each category. The loss function is then calculated and the model parameters are updated. In this invention, the loss function combines the contrastive loss of the low-dimensional feature vectors and the cross-entropy loss of the predicted probabilities of each category. The specific calculation method is as follows:

[0072] The positive sample pairs are calculated using the following formula. The contrastive loss of low-dimensional feature vectors:

[0073]

[0074]

[0075] in, These represent enhanced equipment image samples. The low-dimensional feature vectors, sim() represents calculating the vector similarity, and in this embodiment, cosine similarity is used, τ represents the temperature coefficient, 1 [j≠i] This is an indicator function, which is 1 when j≠i and 0 otherwise. The indicator function filters out the cosine similarity comparison between the sample and itself in the denominator, making the comparison loss more accurate.

[0076] Then, the overall contrastive loss L of the training sample set is calculated using the following formula. CL :

[0077]

[0078] The cross-entropy loss L of the training sample set is calculated using the following formula. CE :

[0079]

[0080] Among them, y ic Indicates equipment image sample x i The true probability of belonging to category c, when y i =c,y ic =1, otherwise y ic =0; p i,1,c p i,2,c These represent enhanced equipment image samples. The predicted probability of belonging to each category.

[0081] Combining the overall contrastive loss and cross-entropy loss, the loss function Loss for the equipment detection model during training is obtained:

[0082] Loss=λL CE +(1-λ)L CL

[0083] Where λ represents the preset weight, 0 < λ < 1.

[0084] S105: Determine the characteristics of samples within the distribution:

[0085] x i Input the trained equipment detection model and obtain the feature z output by the feature extraction module. i For each equipment category c, the average feature of all equipment image samples belonging to that category is calculated as the in-distribution sample center o corresponding to that category. c .

[0086] S106: Feature extraction from test equipment images:

[0087] For test equipment image x that requires anomaly detection t After normalizing it to a preset size, it is input into the trained equipment detection model to obtain the feature z output by the feature extraction module. t The low-dimensional feature vector h output by the mapping module t And the test equipment image x output by the category prediction module t The predicted probability p of belonging to each category tc .

[0088] S107: Calculate the comprehensive score for out-of-distribution anomalies:

[0089] According to the test equipment image x t Features z t low-dimensional feature vector h t and test equipment image x t The predicted probability p of belonging to each category tc Calculate test equipment image xt The overall score of out-of-distribution anomalies is used to determine whether out-of-distribution anomalies exist. Figure 3 This is a flowchart illustrating the calculation of the comprehensive score for out-of-distribution anomalies in this invention. For example... Figure 3 As shown, the specific steps for calculating the comprehensive score of out-of-distribution anomalies in this invention include:

[0090] S301: Calculate image feature evaluation score:

[0091] The semantic relationships of high-dimensional feature vectors are more obvious than those of low-dimensional feature vectors, and after feature extraction by a neural network encoder, z t Typically, these are sparse non-negative vectors, calculated by z. t The sum of elements across all dimensions serves as a partial evaluation criterion. Since the neural network encoder is only sensitive to samples within the distribution during training, when z... t For samples within the distribution, the sum of their features is relatively large; while when z t These are out-of-distribution anomalous samples, which the neural network encoder is insensitive to, and their feature sum data is relatively small. Therefore, the feature vector z can be calculated. t The sum of the elements in each dimension is used as the image feature evaluation score in the out-of-distribution anomaly scoring function. sum The calculation formula is:

[0092]

[0093] Among them, z t (m) represents the eigenvector z t The m-th element in the vector z, where m = 1, 2, ..., M, represents the eigenvector z. t Dimensions.

[0094] S302: Calculate the evaluation score of the low-dimensional feature vector:

[0095] In contrastive learning, a large amount of irrelevant background and other feature information is filtered out by the mapping module, resulting in a dense, low-dimensional feature vector h. t This represents the essential features of the test equipment image. Therefore, it is possible to calculate the low-dimensional feature vector h. t The feature norm is used as a low-dimensional feature vector in the out-of-distribution anomaly scoring function to evaluate the score. L2 The calculation formula is:

[0096]

[0097] Among them, h t (d) represents the low-dimensional feature vector h t The d-th element in the vector, d = 1, 2, ..., D, where D represents the low-dimensional eigenvector h. t The dimension of score. L2The larger the value, the greater the probability that the sample is within the distribution.

[0098] S303: Calculate the category prediction evaluation score:

[0099] Ideally, in-distribution samples have high confidence levels, while out-of-distribution anomaly samples have low maximum confidence levels, leading to some ambiguity in category identification. Therefore, the maximum category probability obtained from the category prediction module is used as the category prediction evaluation score in the out-of-distribution anomaly scoring function. class The calculation formula is:

[0100] score class =max(p tc )

[0101] S304: Calculate the in-distribution sample center distance evaluation score:

[0102] After continuous optimization of the equipment detection model parameters, the final distributed sample centers are basically consistent with the true semantic centers. The distance between the test equipment image and the distributed sample centers is calculated as the distributed sample center distance evaluation score. dis The calculation formula is:

[0103]

[0104] Sample center distance score dis The larger the value, the greater the probability that the sample is an outlier.

[0105] S305: Calculate the variance evaluation score for samples within the most similar distribution:

[0106] In this invention, the top K training equipment image samples with the highest similarity to the test equipment image are also calculated, and the feature variance of these K samples is used as the variance evaluation score of the most similar in-distribution samples. When the test equipment image is of a known equipment category within the distribution, the probability that the top K similar in-distribution samples belong to the same type is relatively high, and their variance is relatively low; when the test equipment image is of an unknown type outside the distribution, since the equipment detection model is unaware of it, the probability that the top K similar in-distribution samples belong to the same type is relatively low, and their variance is relatively high.

[0107] First, from N equipment image samples x i Features z i Image x of search and test equipment t Features z t The K features with the highest similarity are selected, with the value of K determined based on actual needs. The variance of these K features is then calculated as the variance score for the samples within the most similar distribution. var :

[0108]

[0109] in, This represents the calculation of features z in an image sample. t The kth feature among the K features with the highest similarity.

[0110] S306: Calculate the comprehensive score for out-of-distribution anomalies:

[0111] Based on the above evaluation scores, a comprehensive score for out-of-distribution anomalies is obtained, where the score is... sum score L2 score class This is a positive gain, meaning the larger the value, the more likely it is a normal sample within the distribution; score dis score var This represents a negative gain, meaning the smaller the value, the more normal the sample is within the distribution. Furthermore, to reflect the influence of different factors on out-of-distribution samples, this invention uses a product approach to amplify the effect of each component. Therefore, the formula for calculating the out-of-distribution anomaly comprehensive score is:

[0112]

[0113] S108: Identification of Abnormal Equipment Outside Distribution:

[0114] Based on the out-of-distribution anomaly comprehensive score calculated in step S107, it is compared with a preset anomaly score threshold δ. When the out-of-distribution anomaly comprehensive score is higher than the threshold, the test equipment image is identified as a normal equipment type sample within the distribution; when the out-of-distribution anomaly comprehensive score is lower than the threshold, the test equipment image is identified as an out-of-distribution abnormal equipment type sample. Generally, the anomaly score threshold δ can be set based on experience.

[0115] To better illustrate the technical effects of this invention, specific examples were used for experimental verification. Seven types of equipment datasets were collected as in-distribution training datasets, with 2000 training images and 300 test images for each type. Five types of equipment image datasets were used as out-of-distribution anomaly detection datasets, with 300 test images for each type. Therefore, in this embodiment, the number of equipment image samples N = 14000, and the equipment categories C = 7. The area under the receiver operating characteristic curve (AUROC) was used as the evaluation index; a larger value indicates better out-of-distribution anomaly detection performance.

[0116] During training, the number of training iterations (epochs) was set to 1000, the batch size per iteration was set to 128, the temperature coefficient τ = 0.5, and the weight coefficient of the loss function was set to λ = 0.5. In the detection phase, the variance of samples within the most similar distribution was calculated, where K = 5000. The scoring function's decision threshold was set to δ = 15.5.

[0117] For example, in an out-of-distribution anomaly detection dataset, an image of transportation equipment, after feature extraction by a neural network, yields the feature z output by the feature extraction module. t The low-dimensional feature vector h output by the mapping module t And the test equipment image x output by the category prediction module t The predicted probability p of belonging to each category tc Calculate the different evaluation scores to obtain:

[0118] score sum =∑z t =5.14

[0119]

[0120] score class =max(p m ) = 0.99

[0121]

[0122]

[0123] Then, the out-of-distribution anomaly score is calculated using the following formula:

[0124]

[0125] As can be seen, the overall score for in-distribution anomaly detection is 0.0097, which is less than the threshold δ = 15.5, indicating that the input sample is an out-of-distribution anomaly. Conversely, if the overall score for out-of-distribution anomaly detection is higher than the threshold δ, it indicates that the input sample is a normal in-distribution sample.

[0126] Next, we will examine the experimental results of using different scoring scores on the equipment image dataset in this embodiment. Table 1 shows the experimental results of different scoring scores on the equipment image dataset.

[0127] Evaluation score AUROC <![CDATA[score sum ]]> 94.36 <![CDATA[score L2 ]]> 94.53 <![CDATA[score class ]]> 94.67 <![CDATA[score dis ]]> 89.58 <![CDATA[score var ]]> 73.25 score 95.33

[0128] Table 1

[0129] As shown in Table 1, evaluating scores based solely on individual anomaly detection components is less effective than the comprehensive scoring function proposed in this invention. The Euclidean distance to the sample center and the similarity difference with samples within the distribution, as negative gain factors for sample features, have limited effect; therefore, the method using sample features shows some effectiveness. Overall, the comprehensive scoring function designed by considering heterogeneous feature factors can amplify the score difference between samples within and outside the distribution in image out-of-distribution anomaly detection tasks, thereby improving out-of-distribution anomaly detection performance.

[0130] Although the illustrative specific embodiments of the present invention have been described above to enable those skilled in the art to understand the invention, it should be understood that the invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the invention as defined and determined by the appended claims, and all inventions utilizing the concept of the present invention are protected.

Claims

1. A method for detecting out-of-distribution anomalies in equipment images based on a comprehensive scoring function, characterized in that, Includes the following steps: S1: Collect several equipment images according to actual needs, and label them with categories to obtain the training sample set X = {x1, x2, ..., x...} N },Y={y1,y2,...,y N }, where N represents the number of equipped images in the training sample set, x i Let y represent the i-th equipment image sample. i It is an equipment image sample x i The corresponding label, y i =1,2,…,C, where C represents the number of equipment categories; S2: For each equipment image sample x in the training sample set X... i Normalized to a preset size, then image enhancement processing is performed. The enhanced image is then randomly flipped twice to obtain two enhanced equipment image samples. Thus, N positive sample pairs are obtained. S3: Construct an equipment detection model, including a feature extraction module, a mapping module, and a category prediction module, wherein: The feature extraction module is used to extract image features from the input equipment image and output the obtained feature vector z to the mapping module and the category prediction module; The mapping module is used to map the feature vector z to a low-dimensional feature vector h; The category prediction module is used to obtain the probability p that the input equipment image belongs to each category, predicted based on the feature vector z. c c = 1, 2, ..., C; S4: Pair the N positive samples obtained in step S2 Image samples of medium-strengthened equipment The equipment detection model is trained by inputting the corresponding low-dimensional feature vectors and the predicted probabilities of each category. The loss function is then calculated and the model parameters are updated. The loss function is calculated as follows: The positive sample pairs are calculated using the following formula. The contrastive loss of low-dimensional feature vectors: in, These represent enhanced equipment image samples. The low-dimensional feature vector, sim() represents calculating the vector similarity, τ represents the temperature coefficient, 1 [j≠i] This is an indicator function; it is 1 when j ≠ i, and 0 otherwise. Then, the overall contrastive loss L of the training sample set is calculated using the following formula. CL : The cross-entropy loss L of the training sample set is calculated using the following formula. CE : Among them, y ic Indicates equipment image sample x i The probability of belonging to category c, when y i =c,y ic =1, otherwise y ic =0; p i,1,c p i,2,c These represent enhanced equipment image samples. The predicted probability of belonging to each category; The loss function Loss of the equipment detection model during training is calculated using the following formula: Loss=λL CE +(1-λ)L CL Where λ represents the preset weight, 0 < λ < 1; S5: Transfer the image samples of each equipment x i Input the trained equipment detection model and obtain the feature z output by the feature extraction module. i For each equipment category c, calculate the average feature of all equipment image samples belonging to that category as the in-distribution sample center o corresponding to that category. c ; S6: For test equipment images x that require anomaly detection t After normalizing it to a preset size, it is input into the trained equipment detection model to obtain the feature z output by the feature extraction module. t The low-dimensional feature vector h output by the mapping module t And the test equipment image x output by the category prediction module t The predicted probability p of belonging to each category tc ; S7: The comprehensive score for distribution anomalies is calculated using the following method: S7.1: Calculate the eigenvector z t The sum of the elements in each dimension is used as the image feature evaluation score in the out-of-distribution anomaly scoring function. sum The calculation formula is: Among them, z t (m) represents the eigenvector z t The m-th element in the vector z, where m = 1, 2, ..., M, represents the eigenvector z. t The dimension; S7.2: Calculate the low-dimensional eigenvector h t The feature norm is used as a low-dimensional feature vector in the out-of-distribution anomaly scoring function to evaluate the score. L2 The calculation formula is: Among them, h t (d) represents the low-dimensional feature vector h t The d-th element in the vector, d = 1, 2, ..., D, where D represents the low-dimensional eigenvector h. t The dimension; S7.3: Use the maximum class probability obtained from the class prediction module as the class prediction evaluation score in the out-of-distribution anomaly scoring function. class The calculation formula is: score class =max(p tc ) S7.4: Calculate the distance between the test equipment image and the center of the distributed samples as the score for evaluating the distance between the distributed samples. dis The calculation formula is: S7.5: From N equipment image samples x i Features z i Image x of search and test equipment t Features z t The K features with the highest similarity are selected, with the value of K determined based on actual needs. The variance of these K features is then calculated as the variance score for the samples within the most similar distribution. var : in, This represents the calculation of features z in an image sample. t The k-th feature among the K features with the highest similarity; S7.6: The out-of-distribution anomaly composite score is calculated using the following formula: S8: Based on the comprehensive score of out-of-distribution anomalies calculated in step S7, compare it with the preset anomaly score threshold δ. When the comprehensive score of out-of-distribution anomalies is higher than the threshold, the test equipment image is identified as a sample of normal equipment type within the distribution; when the comprehensive score of out-of-distribution anomalies is lower than the threshold, the test equipment image is identified as a sample of out-of-distribution abnormal equipment type.

2. The method for detecting anomalies in equipment image distribution according to claim 1, characterized in that, The specific method for image enhancement processing in step S2 is as follows: The equipment image samples, normalized to a preset size, are randomly cropped according to the specified size. The cropped images are partially blurred by adding a Gaussian blur filter. Then, the brightness, contrast, saturation, or hue of the images are randomly changed by adding perturbations.

3. The method for detecting anomalies in equipment image distribution according to claim 1, characterized in that, In step S3, the feature extraction module uses a ResNet-18 network.

4. The method for detecting anomalies in equipment image distribution according to claim 1, characterized in that, The mapping module in step S4 includes a first fully connected layer, a ReLU function layer, and a second fully connected layer, wherein: The first fully connected layer is used to process the feature vector z and send the resulting feature vector to the ReLU function layer; The ReLU function layer is used to process the received feature vector using the ReLU activation function, and then sends the resulting feature vector to the second fully connected layer. The second fully connected layer processes the received feature vectors and outputs the resulting feature vectors as low-dimensional feature vectors h.

5. The method for detecting anomalies in equipment image distribution according to claim 1, characterized in that, The category prediction module in step S4 includes a fully connected layer and a Softmax layer, wherein: The fully connected layer is used to process the feature vector z and send the resulting feature vector to the Softmax layer; The softmax layer is used to predict the probability p that the input equipment image belongs to each category based on the received feature vectors. c .

Citation Information

Patent Citations

  • Data enhancement-based out-of-distribution abnormal sample detection method

    CN113392890A

  • Abnormity detection method and system based on comparative learning and computer storage medium

    CN114330572A