Cross-domain small sample anomaly detection model training method and device, and cross-domain small sample anomaly detection method and device
By utilizing style datasets for style enhancement and domain feature learning in a small-sample anomaly detection model, the problem of domain differences in cross-domain detection is solved, achieving efficient detection on new production lines.
Patent Information
- Application Number
- CN202410556655.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-07
- Publication Date
- 2025-11-07
AI Technical Summary
Existing small-sample anomaly detection methods assume that the training and test sets belong to the same distribution, which cannot effectively adapt to the domain differences between production lines in industrial scenarios. This leads to a decrease in the detection performance of the model on new production lines, and makes it difficult to collect and label data from new production lines.
By acquiring the feature vectors of query and support samples from the training dataset, style enhancement is performed using pre-stored style data sets, the model is updated to reduce domain differences, and a cross-domain few-shot anomaly detection model is trained through an encoder and a prediction network. The model performance is then optimized by combining inter-class contrastive loss.
It significantly improves the model's cross-domain detection capability, enabling it to quickly adapt to new production lines, reduce inter-domain gaps, enhance semantic feature representation, and improve detection accuracy.
Smart Images

Figure CN120912930A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the field of artificial intelligence, and in particular, to a training method of a cross-domain small sample anomaly detection model, a cross-domain small sample anomaly detection method and a detection device, and further relates to a computer device, a computer readable storage medium and a computer program product for implementing the training method or the detection method. BACKGROUND
[0002] With the rapid development of deep neural networks, surface anomaly / defect detection of industrial products has received unprecedented attention. Generally speaking, due to the difficulty of obtaining abnormal samples, unsupervised methods are usually used for anomaly detection (AD), i.e., the training process only uses normal samples, therefore, the AD method usually needs a large number of normal samples to support during training. In order to reduce the dependence of the model on the number of training samples, so as to enable the model to quickly adapt to new categories, in recent years, small sample anomaly detection (few-shot AD, abbreviated as FSAD) has been applied more and more.
[0003] The existing FSAD method assumes that the training set and the test set belong to the same distribution, and uses generation or transformation to expand the support set containing a small number of normal samples, extracts common features between different categories for modeling and calculates the distribution, and detects anomalies on the query sample. But this assumption is not always true. In the industrial scene, as more and more new production lines are put into use, the domain difference between production lines is also increasingly obvious. It is very time-consuming to fine-tune the algorithm or machine for each production line, and at the initial stage, the data collection and labeling of new production lines are often difficult and insufficient, so the demand for quickly adapting the knowledge learned from the previous production line (training set) to the new production line (test set) is greatly improved. SUMMARY
[0004] According to a first aspect of the present disclosure, a training method of a cross-domain small sample anomaly detection model is provided, including: obtaining a training data set, the training data set including a query sample set and a support sample set; determining a query image feature vector from a query image included in the query sample set, and determining a support sample feature vector from a support sample image included in the support sample set; updating first style data and second style data included in each style data group pre-stored based on the query image feature vector, to obtain updated first style data and updated second style data, wherein each style data group reflects different domain features; performing style enhancement on the query image feature vector from a style data group with the largest domain difference with the query image feature vector among the style data groups, to obtain a style-enhanced query image feature vector; and training the cross-domain small sample anomaly detection model based on the support sample feature vector and the style-enhanced query image feature vector.
[0005] According to some example embodiments, the updating the first style data and the second style data included in each style data group pre-stored based on the query image feature vector, to obtain updated first style data and updated second style data includes: determining a feature mean and a feature variance of the query image feature vector; determining a first similarity of the first style data with the feature mean, and determining a second similarity of the second style data with the feature variance; and performing weighted summation of the first style data with a product of the feature mean and the first similarity, to obtain the updated first style data, and performing weighted summation of the second style data with a product of the feature variance and the second similarity, to obtain the updated second style data.
[0006] According to some example embodiments, the performing style enhancement on the query image feature vector from a style data group with the largest domain difference with the query image feature vector among the style data groups, to obtain a style-enhanced query image feature vector includes: determining a feature mean and a feature variance of the query image feature vector; determining a normalized query image feature vector based on the query image feature vector, the feature mean and the feature variance; determining a first similarity of the feature mean with updated first style data of each style data group, determining a second similarity of the feature variance with updated second style data of each style data group, and determining a selected style data group as a style data group with the smallest first similarity and second similarity; and determining the style-enhanced query image feature vector based on the normalized query image feature vector, the query image feature vector, and the updated first style data and the updated second style data included in the selected style data group.
[0007] According to some example embodiments, the training of the cross-domain few-shot anomaly detection model based on the support sample feature vector and the style-enhanced query image feature vector further comprises: passing the support sample feature vector and the style-enhanced query image feature vector through an encoder network to obtain an encoded support sample feature vector and an encoded query image feature vector, respectively; passing the encoded support sample feature vector and the encoded query image feature vector through a prediction network to obtain a predicted support sample feature vector and a predicted query image feature vector, respectively; determining a matching loss based on the encoded support sample feature vector, the predicted support sample feature vector, the encoded query image feature vector, and the predicted query image feature vector; and determining the matching loss as a model loss of the cross-domain few-shot anomaly detection model.
[0008] According to some example embodiments, the training of the cross-domain few-shot anomaly detection model based on the support sample feature vector and the style-enhanced query image feature vector further comprises: passing the support sample feature vector and the style-enhanced query image feature vector through an encoder network to obtain an encoded support sample feature vector and an encoded query image feature vector, respectively; passing the encoded support sample feature vector and the encoded query image feature vector through a prediction network to obtain a predicted support sample feature vector and a predicted query image feature vector, respectively; determining a matching loss based on the encoded support sample feature vector, the predicted support sample feature vector, the encoded query image feature vector, and the predicted query image feature vector; classifying the encoded query image feature vector based on all query images of the query sample set to obtain a classified encoded query image feature vector; determining an inter-class contrast loss based on the classified encoded query image feature vector; and performing a weighted summation on the matching loss and the inter-class contrast loss, and determining the obtained sum as a model loss of the cross-domain few-shot anomaly detection model.
[0009] According to a second aspect of the present disclosure, a cross-domain few-shot anomaly detection method is provided, comprising: obtaining a detection dataset, the detection dataset comprising a detection sample set and a support sample set; determining a detection image feature vector from a detection image included in the detection sample set, and determining a support sample feature vector from a support sample image included in the support sample set; performing style enhancement on the detection image feature vector from a style data group that is pre-stored and has the least domain difference with the detection image feature vector, to obtain a style-enhanced detection image feature vector, wherein each style data group comprises first style data and second style data reflecting domain features; and evaluating all detection images of the detection sample set based on the support sample feature vector and the style-enhanced detection image feature vector, to determine whether there is an anomaly.
[0010] According to some example embodiments, the selecting, from the pre-stored style data groups, a style data group having the least domain difference with the detected image feature vector to perform style enhancement on the detected image feature vector to obtain a style-enhanced detected image feature vector includes: determining a feature mean and a feature variance of the detected image feature vector; determining a normalized detected image feature vector based on the detected image feature vector, the feature mean and the feature variance; determining a first similarity between the feature mean and first style data of each style data group, determining a second similarity between the feature variance and second style data of each style data group, and determining a style data group having the largest first similarity and second similarity as a selected style data group; and determining the style-enhanced detected image feature vector based on the normalized detected image feature vector, the detected image feature vector, and the first style data and the second style data included in the selected style data group.
[0011] According to some example embodiments, the evaluating, based on the support sample feature vector and the style-enhanced detected image feature vector, all detected images of the detected sample set to determine whether there is an anomaly further includes: determining support sample image feature representations of each pixel position of the support sample image based on the support sample feature vector; determining detected image feature representations of each pixel position of the detected image based on the style-enhanced detected image feature vector; evaluating each pixel position of the support sample image based on the support sample image feature representations to obtain support sample image evaluation scores of each pixel position of the support sample image; evaluating each pixel position of the detected image based on the detected image feature representations to obtain detected image evaluation scores of each pixel position of the detected image; and comparing, for each pixel position, the corresponding detected image evaluation score and the corresponding support sample image evaluation score, and determining a pixel position having a difference between the two scores greater than a predetermined threshold as an abnormal position.
[0012] According to some example embodiments, the evaluating, based on the support sample image feature representations, each pixel position of the support sample image to obtain support sample image evaluation scores of each pixel position of the support sample image includes: determining Mahalanobis distances of each pixel position of the support sample image based on the support sample image feature representations as the support sample image evaluation scores; and the evaluating, based on the detected image feature representations, each pixel position of the detected image to obtain detected image evaluation scores of each pixel position of the detected image includes: determining Mahalanobis distances of each pixel position of the detected image based on the detected image feature representations as the detected image evaluation scores.
[0013] According to a third aspect of the present disclosure, there is provided a cross-domain small sample anomaly detection apparatus, characterized in that comprising: a data acquisition module configured to acquire a detection dataset, the detection dataset comprising a detection sample set and a support sample set; a feature acquisition module configured to acquire a detection image feature vector from all detection images of the detection sample set, and acquire a support sample feature vector from all support sample images of the support sample set; a style memory module configured to store a plurality of style data groups, each of the style data groups comprising first style data and second style data reflecting domain features; a style enhancement module configured to select a style data group with least domain difference from the detection image feature vector from the pre-stored style data groups, and perform style enhancement on the detection image feature vector to obtain a style-enhanced detection image feature vector; and an evaluation module configured to evaluate all detection images of the detection sample set based on the support sample feature vector and the style-enhanced detection image feature vector, and determine whether there is an anomaly.
[0014] According to a fourth aspect of the present disclosure, there is provided a computer device comprising a memory and a processor, the memory having stored thereon a computer program, wherein the processor, when executing the computer program, implements the steps of the training method according to the first aspect of the present disclosure and each of the exemplary embodiments thereof, or implements the steps of the cross-domain small sample anomaly detection method according to the second aspect of the present disclosure and each of the exemplary embodiments thereof.
[0015] According to a fifth aspect of the present disclosure, there is provided a computer readable storage medium having stored thereon a computer program, wherein the computer program, when executed by a processor, implements the steps of the training method according to the first aspect of the present disclosure and each of the exemplary embodiments thereof, or implements the steps of the cross-domain small sample anomaly detection method according to the second aspect of the present disclosure and each of the exemplary embodiments thereof.
[0016] According to a sixth aspect of the present disclosure, there is provided a computer program product comprising a computer program, wherein the computer program, when executed by a processor, implements the steps of the training method according to the first aspect of the present disclosure and each of the exemplary embodiments thereof, or implements the steps of the cross-domain small sample anomaly detection method according to the second aspect of the present disclosure and each of the exemplary embodiments thereof.
[0017] The training method of the cross-domain small sample anomaly detection model according to the present disclosure can update the style data included in the style data set based on the query image feature vector, and can perform style enhancement on the query image feature vector based on the selected style data set, so that the training method can generate diversified domain features, and can reduce the gap by learning the domain features, thereby significantly improving the performance of the trained CD-FSAD model.
[0018] In addition, the cross-domain small sample anomaly detection method according to the present disclosure can enhance the detection image feature vector using the style data, thereby migrating the knowledge of the training domain to the test domain to reduce the domain gap and strengthen the semantic feature representation, thereby significantly improving the model cross-domain detection capability. BRIEF DESCRIPTION OF DRAWINGS
[0019] Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings; in the drawings:
[0020] Figure 1 The contrast between unsupervised anomaly detection, small sample anomaly detection and cross-domain small sample anomaly detection is schematically shown;
[0021] Figure 2 The architecture when training the cross-domain small sample anomaly detection model according to the exemplary embodiments of the present disclosure is schematically shown;
[0022] Figure 3 The training method of a cross-domain small sample anomaly detection model according to the exemplary embodiments of the present disclosure is schematically shown in the form of a flowchart;
[0023] Figure 4 The training method of the cross-domain small sample anomaly detection model according to the exemplary embodiments of the present disclosure is further shown in detail;
[0024] Figure 5A and Figure 5B The style update strategy according to the exemplary embodiments of the present disclosure is schematically shown;
[0025] Figure 6 The training method of the cross-domain small sample anomaly detection model according to the exemplary embodiments of the present disclosure is further shown in detail;
[0026] Figure 7 The style enhancement strategy according to the exemplary embodiments of the present disclosure is schematically shown;
[0027] Figure 8 The training method of the cross-domain small sample anomaly detection model according to the exemplary embodiments of the present disclosure is further shown in detail;
[0028] Figure 9Details of the training method of the cross-domain small sample anomaly detection model are further shown according to the exemplary embodiments of the present disclosure.
[0029] Figure 10 A cross-domain small sample anomaly detection method according to the exemplary embodiments of the present disclosure is schematically shown in the form of a flow chart;
[0030] Figure 11 Details of the cross-domain small sample anomaly detection method are further shown according to the exemplary embodiments of the present disclosure.
[0031] Figure 12 Details of the cross-domain small sample anomaly detection method are further shown according to the exemplary embodiments of the present disclosure.
[0032] Figure 13 The structure of a cross-domain small sample anomaly detection device according to the exemplary embodiments of the present disclosure is schematically shown in the form of a block diagram;
[0033] Figure 14 The structure of a computer device according to the exemplary embodiments of the present disclosure is schematically shown.
[0034] It should be understood that the accompanying drawings are only schematic diagrams of the exemplary embodiments of the present disclosure, and are not limited to scale. In addition, in the accompanying drawings, the same or similar features are indicated by the same or similar reference numerals. DETAILED DESCRIPTION
[0035] The exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, so that those skilled in the art can fully understand and implement the technical solutions according to the present disclosure.
[0036] First, some concepts related to the technical solutions of the present disclosure and some terms involved in the exemplary embodiments of the present disclosure below are explained, so as to facilitate the understanding of the present disclosure by those skilled in the art:
[0037] Artificial Intelligence (abbreviated as AI): is to use digital computers or digital computer controlled machines to simulate, extend and expand human intelligence, perceive environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology of computer science, which tries to understand the essence of intelligence and produce a new intelligent machine that can react in a similar way to human intelligence. Artificial intelligence is to design and implement principles and methods of various intelligent machines, so that machines have the functions of perception, reasoning and decision-making.
[0038] Machine Learning (ML): is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithmic complexity theory, etc. It is a subject that studies how computers simulate or implement human learning behavior to acquire new knowledge or skills, reorganize existing knowledge structure, and continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental approach to making computers intelligent. Its applications are widespread in various fields of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and teaching learning.
[0039] Deep Learning (DL): is a branch of machine learning that is an algorithm that attempts to use multiple processing layers containing complex structures or multiple nonlinear transformations to abstract data at a high level. Deep learning is a learning process that learns the internal rules and representations of training sample data, and the information obtained in this learning process is very helpful for the interpretation of data such as text, images, and sound. The ultimate goal of deep learning is to enable machines to have analytical learning ability like humans, and to recognize data such as text, images, and sound. Deep learning is a complex machine learning algorithm, and the results achieved in speech and image recognition far exceed previous related technologies.
[0040] Neural Network (NN): in the field of machine learning and cognitive science, a deep learning model that simulates the structure and function of biological neural networks.
[0041] Domain: in this disclosure, this term should be understood as a data set composed of images obtained with the same source and / or using the same algorithm and equipment. For example, in an industrial scenario, due to differences in algorithms and / or equipment, there can be large differences in imaging conditions between different production lines, resulting in large differences in images generated by different production lines as a whole. In this case, the data set composed of images generated by a production line can be referred to as a domain.
[0042] Style: in this disclosure, this term refers to the unique characteristics (i.e. domain characteristics) that a domain has relative to other domains, which reflect the characteristics or styles common to all images in the domain. Therefore, in this disclosure, the difference in style between different domains should be understood as reflecting the inter-domain difference of these domains.
[0043] Referring to Figure 1 which schematically shows the comparison between unsupervised anomaly detection, small sample anomaly detection, and cross-domain small sample anomaly detection. As Figure 1As shown, the partial view on the left schematically illustrates an unsupervised anomaly detection method (i.e., AD method). AD is a commonly used detection method in industrial AI image quality inspection, which requires training a neural network model with a large amount of defect-free data for the target category. That is, a separate model needs to be trained for each category, and direct testing of unknown categories typically results in poor performance. It should be understood that in this disclosure, the term "class" or "category" refers to a subset obtained by partitioning all images in the dataset based on the displayed content of the image. Figure 1 For example, the training set data used to train the neural network model in this AD method can be divided into three subsets, that is, the image data of the training set data includes three categories.
[0044] To enable modeling using only a small number of samples and reduce the model's dependence on the number of training samples, thereby allowing the model to quickly adapt to new categories, few-sample anomaly detection methods (FSAD methods, such as...) have been proposed. Figure 1 (As shown in the top right partial view). Existing FSAD methods assume that the training and test sets belong to the same distribution. Therefore, the support set, which contains a small number of normal samples, can be expanded by generating or transforming it to extract common features between different categories for modeling and calculating the distribution, which can then be used to detect anomalies on the query samples. However, this assumption is not always valid. In industrial scenarios, as more and more new production lines are put into use, the domain differences between production lines are becoming increasingly apparent. Fine-tuning the algorithm or machine for each production line individually is very time-consuming. At the same time, data collection and labeling for new production lines are often difficult and insufficient in the early stages, greatly increasing the need to quickly adapt the knowledge learned from previous production lines (training set) to new production lines (test set).
[0045] Figure 1 The lower right partial view shows the cross-domain small sample anomaly detection method (i.e., crossdomain FSAD, abbreviated as CD-FSAD) according to this disclosure. Figure 1 As shown, in the CD-FSAD method, the categories of images in the test set may not be the same as those in the training set, and there may be significant domain differences between the training and test sets. Therefore, the CD-FSAD method has two limitations: firstly, only a small number of samples are available for testing; secondly, it needs to consider both the differences in features between categories within a domain and the significant differences between domains.
[0046] See Figure 2 This schematically illustrates the architecture for training a CD-FSAD model according to an exemplary embodiment of the present disclosure. Figure 2As shown, the architecture 100 can include a training dataset 110, shared networks 120a and 120b, a style memory module 130, an encoder network 140, a prediction network 150, and an inter-class contrastive loss module 160.
[0047] The training dataset 110 can include a query sample set Q train and a support sample set S train , where the query sample set Q train may include a plurality of query images as query samples, and the support sample set S train may include a plurality of support sample images as support samples. Further, for each class included in the training dataset 110, it has a large number of query-support pairs, and each pair can include one normal query image and K normal support sample images (where K is an integer greater than 0).
[0048] The shared networks 120a and 120b, the encoder network 140, and the prediction network 150 constitute part of an exemplary feature registration network (i.e., FRN), which can be used in the FSAD method. As a non-limiting example, the shared networks 120a and 120b can each include a respective convolutional block and a spatial transformation network. The shared network 120a can determine a query image feature vector f q from a query image, and can determine a support sample feature vector f s from a support sample image. The encoder network 140 can encode the query image feature vector f q and the support sample feature vector f s to obtain an encoded query image feature vector z q and an encoded support sample feature vector z s , respectively. The prediction network 150 can predict the encoded query image feature vector z q and the encoded support sample feature vector z s to obtain a predicted query image feature vector p q and a predicted support sample feature vector p s , respectively. The encoded query image feature vector z q , the encoded support sample feature vector z s , the predicted query image feature vector p q , and the predicted support sample feature vector p s may be used to determine a matching loss. The matching loss can be used to determine a model total loss function for training the CD-FSAD model used.
[0049] The style memory module 130 can store specific statistics of domain features reflecting inter-domain differences. For example, the style memory module 130 can store the mean and variance of the query image feature vectors as specific statistics of domain features reflecting inter-domain differences, by which the domain distribution information can be measured to some extent. It should be understood that this is merely exemplary and not limiting. According to actual needs, other statistics can also be selected as long as they can reflect the domain distribution information. The style memory module 130 can store multiple data pairs, i.e., the first style data m j and the second style data v j constitute a data pair, wherein C represents the dimension of the feature channel, N is an integer greater than 1, m j represents the first style data, and v j represents the second style data. As a non-limiting example, the first style data can be determined based on the feature mean of the query image feature vector of the query image, and the second style data can be determined based on the feature variance of the query image feature vector of the query image.
[0050] Continuing to refer to Figure 2 In the illustrated architecture 100, each data pair stored by the style memory module 130 can be taken as a style data group, which includes the first style data and the second style data reflecting the corresponding domain features. Therefore, when training the CD-FSAD model, the style memory module 130 can perform the following two operations: (1) updating the style data of each style data group stored by using the obtained query image feature vector f q , and (2) selecting the style data pair of the style data group with the largest domain difference to perform style enhancement on the query image feature vector f q to obtain the style-enhanced query image feature vector f The largest domain difference means that the similarity between the style data of the style data group and the domain features obtained based on the query image feature vector f q is the smallest. Then, Figure 2 The illustrated architecture 100 will pass the style-enhanced query image feature vector f and the support sample feature vector f s through the downstream shared network 120b, the encoder network 140 and the prediction network 150 to determine the matching loss.
[0051] It can be seen that, by using the style memory module 130, Figure 2 the illustrated architecture 100 can determine the query sample set Q trainThe intra-domain statistical information obtained is continuously aggregated into the style memory module to enrich the sample styles, force the model to learn style differences, and achieve better generalization by narrowing the distance between the style-enhanced query image feature vector and the support sample feature vector. This enables the trained CD-FSAD model to achieve robust detection. Furthermore, the style memory module 130 is a simple, plug-and-play module that can be placed between any layers of the feature matching network to implement the above functions. Figure 2 As shown, the style memory module 130 is placed between the shared networks 120a and 120b of the feature matching network.
[0052] The inter-class contrast loss module 160 can be used to determine the different categories of the query image in the training dataset 110. The inter-class contrastive loss can be combined with the determined matching loss as the total model loss of the trained CD-FSAD model, thus jointly used to train the CD-FSAD model. The inter-class contrastive loss module 160 enables different classes in the training dataset 110 to exclude each other, thereby increasing the distance between different classes and enabling the trained CD-FSAD model to have better discriminative ability. Furthermore, it should be understood that although... Figure 2 The architecture 100 shown includes both a style memory module 130 and an inter-class contrast loss module 160, but this is merely exemplary and not limiting. In other embodiments of this disclosure, only the style memory module 130 may be included, without the inter-class contrast loss module 160.
[0053] As can be seen from the above analysis, the architecture for training the CD-FSAD model according to the exemplary embodiments of this disclosure can generate diverse domain features, reduce the gap by learning domain features, and increase the discriminative ability by learning discriminative representations, thereby significantly improving the performance of the trained CD-FSAD model.
[0054] See Figure 3 And in conjunction with see Figure 2 ,in, Figure 3 The flowchart schematically illustrates a training method for a cross-domain few-shot anomaly detection model according to an exemplary embodiment of the present disclosure, which can be generated by... Figure 2 The architecture shown is used for implementation.
[0055] like Figure 3 As shown, the training method 300 for the cross-domain few-sample anomaly detection model may include the following steps:
[0056] In step 310, a training dataset is obtained, which includes a query sample set and a support sample set;
[0057] At step 320, a query image feature vector is determined from a query image included in the query sample set, and a support sample feature vector is determined from a support sample image included in the support sample set;
[0058] At step 330, first style data and second style data included in each style data group are updated based on the query image feature vector, to obtain updated first style data and updated second style data, wherein each style data group reflects different domain characteristics;
[0059] At step 340, the query image feature vector is style enhanced by selecting a style data group that is most different from the domain of the query image feature vector from each style data group, to obtain a style enhanced query image feature vector;
[0060] At step 350, the cross-domain small sample anomaly detection model is trained based on the support sample feature vector and the style enhanced query image feature vector.
[0061] It can be seen that the training method 300 of the cross-domain small sample anomaly detection model can update style data included in the style data group based on the query image feature vector, and can style enhance the query image feature vector based on the selected style data group, so that the training method can generate diversified domain characteristics, and can reduce the gap by learning the domain characteristics, thereby significantly improving the performance of the trained CD-FSAD model.
[0062] Referring to Figure 4 and referring to Figure 3 wherein, Figure 4 According to an example embodiment of the present disclosure, it is further shown that Figure 3 the details of step 330 in the training method 300 of the cross-domain small sample anomaly detection model are shown. As shown in Figure 4 step 330 can include the following steps:
[0063] At step 331, a feature mean and a feature variance of the query image feature vector are determined;
[0064] At step 332, a first similarity between the first style data and the feature mean is determined, and a second similarity between the second style data and the feature variance is determined;
[0065] At step 333, a product of the feature mean and the first similarity is weighted summed with the first style data to obtain the updated first style data, and a product of the feature variance and the second similarity is weighted summed with the second style data to obtain the updated second style data.
[0066] Referring to Figure 5A and Figure 5B and referring to Figure 4 wherein, Figure 5A According to an exemplary embodiment of the present disclosure, a strategy of updating the first style data based on the feature mean of the feature vector is schematically shown, Figure 5B According to an exemplary embodiment of the present disclosure, a strategy of updating the second style data based on the feature variance of the feature vector is schematically shown.
[0067] As Figure 5A and Figure 5B shown, when training the CD-FSAD model, the query image feature vector f q1 , f q2 , …, f qB of each query image can be respectively obtained from all query images of one batch of the batch processing with a batch size of B. Therefore, based on the query image feature vectors f q1 , f q2 , …, f qB , the feature mean μ q1 , μ q2 , …, μ qB and the feature variance σ q1 , σ q2 , …, σ qB corresponding to each query image feature vector can be obtained. As described above, the mean and variance of the query image feature vector can be taken as specific statistical data of the domain feature reflecting the domain difference. However, according to actual needs, other statistical data can also be selected as specific statistical data of the domain feature reflecting the domain difference.
[0068] For the query image feature vector f q ∈R C*H*W , where C represents the dimension of the feature channel, H represents the height of the feature vector, and W represents the width of the feature vector, the feature mean μ q and the feature variance σ q of the feature vector can be respectively calculated by the following formulas:
[0069]
[0070]
[0071] The first similarity of the feature mean and the first style data of each style data group and the second similarity of the feature variance and the second style data of each style data group can be respectively calculated by the following formulas:
[0072]
[0073]
[0074] Where, m j v represents the first style data in the j-th style data group out of the N stored style data groups. j Let μ represent the second style data in the j-th style data set, and N represent the number of style data sets, which is a positive integer, so 1 ≤ j ≤ N; where b represents the index number in a batch training of batch size B, which is a positive integer, and 1 ≤ b ≤ B; where μ qb This represents the feature vector f corresponding to the query image with index number b in this batch of batch processing. b The characteristic mean, σ qb Represents the eigenvector f b The characteristic variance; where Sim(m j ,μ qb ) indicates that for m j and μ qb Calculate cosine similarity, Sim(v) j ,σ qb ) indicates that for v j and σ qb Calculate the cosine similarity; where, The characteristic mean μ qb Compared with the first style data m j First similarity, The characteristic variance σ qb With the second style data v j The second similarity.
[0075] Therefore, based on the characteristic mean μ q1 μ q2 ... μ qB The data m for the first style can be calculated according to Equation 3. j First similarity (like Figure 5A (as shown); and based on the characteristic variance σ q1 σ q2 , ..., σ qB The data v for the second style can be calculated according to Equation 4. j Second similarity (like Figure 5B (As shown).
[0076] Then, the product of the feature mean and the first similarity can be weighted-summed with the first style data to update the first style data, and the product of the feature variance and the second similarity can be weighted-summed with the second style data to update the second style data. For example, the above weighted-summing can be calculated by the following formulas, respectively:
[0077]
[0078]
[0079] wherein, denotes the updated first style data in the jth style data group, denotes the updated second style data in the jth style data group, and a is an aggregation weight which can be set according to experience to control the update rate.
[0080] Therefore, according to the training method of the present disclosure, the query sample set Q train The calculated intra-domain statistical information is continuously aggregated to the style memory module, so as to enrich the sample style and force the model to learn the style difference in the training process.
[0081] Referring to Figure 6 and referring to Figure 3 wherein, Figure 6 According to the exemplary embodiments of the present disclosure, it is further shown that Figure 3 Details of step 340 in the training method 300 of the cross-domain small sample anomaly detection model are shown. As shown in Figure 6 As shown, step 340 can include the following steps:
[0082] In step 341, the feature mean and the feature variance of the query image feature vector are determined;
[0083] In step 342, based on the query image feature vector, the feature mean and the feature variance, a normalized query image feature vector is determined;
[0084] In step 343, the first similarity between the feature mean and the updated first style data of each style data group is determined, the second similarity between the feature variance and the updated second style data of each style data group is determined, and the style data group with the smallest first similarity and second similarity is determined as the selected style data group;
[0085] In step 344, based on the normalized query image feature vector, the query image feature vector, and the updated first style data and the updated second style data included in the selected style data group, the style-enhanced query image feature vector is determined.
[0086] Referring to Figure 7 and referring to Figure 6 wherein, Figure 7 According to an exemplary embodiment of the present disclosure, a strategy of style enhancement on a feature vector is schematically shown.
[0087] As Figure 7 shown, for a query image feature vector f q , its feature mean μ q and feature variance σ q can be calculated. For example, the feature mean μ q and the feature variance σ q can be calculated by the above formula 1 and formula 2, and thus, will not be repeated here.
[0088] After obtaining the feature mean μ q and the feature variance σ q , a normalized query image feature vector f
[0089]
[0090] Then, a first similarity of the feature mean μ q and the updated first style data of each style data group can be determined, and a second similarity of the feature variance σ q and the updated second style data of each style data group can be determined. For example, the first similarity and the second similarity can be calculated by the above formula 3 and formula 4, and thus, will not be repeated here.
[0091] Based on the normalized query image feature vector f , the query image feature vector f q , and the first style data and the second style data included in the selected style data group, a style-enhanced query image feature vector f is calculated. As a non-limiting example, in the training process, the first style data and the second style data with the largest difference from the feature mean μ q and the feature variance σ q may be selected for style enhancement, that is, the first style data f and the second style data f with the smallest similarity to the feature mean μ q and the feature variance σ q may be selected.
[0092]
[0093] In the training process of the CD-FSAD model, the first style data with the smallest similarity to the feature mean μ q and the feature variance σ q is used to determine the style-enhanced query image feature vector together with the second style data and the second style data This is advantageous for forcing the model to ignore the style difference, thereby achieving better domain generalization. It should be understood that in other embodiments of the present disclosure, the first style data and the second style data with a specific similarity to the feature mean and the feature variance can also be selected as needed to determine the style-enhanced query image feature vector.
[0094] Referring to Figure 8 and referring to Figure 2 and Figure 3 , wherein, Figure 8 According to one exemplary embodiment of the present disclosure, further details of step 350 in the training method 300 of the cross-domain small sample anomaly detection model are shown in Figure 3 The details shown in Figure 8 , step 350a can include the following steps:
[0095] In step 351, the support sample feature vector and the style-enhanced query image feature vector are passed through the encoder network to obtain the encoded support sample feature vector and the encoded query image feature vector, respectively.
[0096] In step 352, the encoded support sample feature vector and the encoded query image feature vector are passed through the prediction network to obtain the predicted support sample feature vector and the predicted query image feature vector, respectively.
[0097] In step 353, based on the encoded support sample feature vector, the predicted support sample feature vector, the encoded query image feature vector, and the predicted query image feature vector, a matching loss is determined.
[0098] In step 354, the matching loss is determined as the model loss of the cross-domain small sample anomaly detection model.
[0099] Referring to Figure 2 , the support sample feature vector f s and the style-enhanced query image feature vector can be passed through the encoder network 140 to obtain the encoded support sample feature vector z s and the encoded query image feature vector z q , respectively; the encoded support sample feature vector z s and the encoded query image feature vector zq The predicted support sample feature vector p can be obtained through prediction network 150. s and the predicted query image feature vector p q Then, the matching loss L can be calculated using the following formula. reg :
[0100]
[0101] Among them, SG(z) q ) represents the encoded query image feature vector z q Perform gradient stopping operation, SG(z) s ) represents the encoded support sample feature vector z s Perform gradient stopping operation, Sim(p) s ,SG(z q )) represents the feature vector p of the predicted support samples. s After encoding and performing gradient stopping operations, query the image feature vector z. q Calculate cosine similarity, Sim(p) q ,SG(z s )) represents the predicted feature vector p of the query image. q And the encoded support sample feature vector z after gradient stopping operation s Calculate the cosine similarity.
[0102] Matching loss L reg The total model loss can be determined as the total loss of the trained CD-FSAD model and used to train the CD-FSAD model.
[0103] By utilizing the matching loss L determined by Equation 9 reg Style-enhanced query image feature vectors With the unenhanced support sample feature vector f s Feature matching can narrow the gap between the two, thus enabling the trained CD-FSAD model to force the style differences to be ignored, thereby achieving better domain generalization.
[0104] See Figure 9 See also Figure 2 and Figure 3 ,in, Figure 9 According to another exemplary embodiment of this disclosure, it is further shown that Figure 3 The details of step 350 in the training method 300 of the cross-domain few-shot anomaly detection model are shown. It should be understood that... Figure 9 The steps shown are the same as Figure 8 Compared to the steps shown, steps 351, 352, and 353 are the same, the difference being that...Figure 9 Steps 355, 356, 357 are also included, and thus, only the differences between them will be described below, and the same will not be described again.
[0105] As shown in Figure 9 , step 350b includes steps 351, 352, 353 which are the same as those shown in Figure 8 , and further includes the following steps:
[0106] In step 355, the encoded query image feature vectors are classified based on all query images of the query sample set, and classified encoded query image feature vectors are obtained;
[0107] In step 356, the inter-class contrast loss is determined based on the classified encoded query image feature vectors;
[0108] In step 357, the matching loss and the inter-class contrast loss are weighted and summed, and the obtained sum is determined as the model loss of the cross-domain small sample anomaly detection model.
[0109] As shown in Figure 2 , in the inter-class contrast loss module 160, for the encoded query image feature vectors z generated by style enhancement in a given batch q According to the content displayed by the query image, it can be divided into, for example, three categories Therefore, the matching loss L inter can be calculated by the following formula:
[0110]
[0111] wherein, τ is a temperature coefficient, which can be determined by experience, P i is a set composed of features z qi of different categories from z p . Then, the matching loss L reg and the inter-class contrast loss L inter are weighted and summed, and the obtained sum is determined as the model loss of the trained CD-FSAD model. For example, the model loss can be calculated by the following formula:
[0112] L = (1 + L reg ) + λL inter (Formula 11)
[0113] wherein, L is the model loss of the trained CD-FSAD model, and λ is a balance coefficient, which can be determined by experience. The model loss L can be used to train the CD-FSAD model.
[0114] From the above analysis, it can be seen that the inter-class contrast loss is used in the model loss of the trained CD-FSAD model, which can constrain the style features of different classes, obtain a discriminative representation of the features, and improve the small sample performance. Thus, in the case of considering that the intra-class distance has been narrowed, further utilizing the inter-class difference makes the distance between different classes repel each other, which can make the trained CD-FSAD model obtain better discrimination ability.
[0115] Referring to Figure 10 , which schematically shows a cross-domain small sample anomaly detection method according to an exemplary embodiment of the present disclosure in the form of a flowchart. As Figure 10 indicated, the cross-domain small sample anomaly detection method 500 can include the following steps:
[0116] In step 510, a detection dataset is obtained, which includes a detection sample set and a support sample set;
[0117] In step 520, a detection image feature vector is determined from a detection image included in the detection sample set, and a support sample feature vector is determined from a support sample image included in the support sample set;
[0118] In step 530, a style data group with the smallest domain difference from the detection image feature vector is selected from pre-stored style data groups, and the detection image feature vector is style enhanced to obtain a style enhanced detection image feature vector, wherein each style data group includes first style data and second style data reflecting domain features;
[0119] In step 540, all detection images of the detection sample set are evaluated based on the support sample feature vector and the style enhanced detection image feature vector, and it is determined whether there is an anomaly.
[0120] As can be seen, the cross-domain small sample anomaly detection method 500 utilizes style data to enhance the detection image feature vector, which can transfer the knowledge of the training domain to the test domain, reduce the domain gap, and strengthen the semantic feature representation, thereby significantly improving the cross-domain detection ability of the model.
[0121] Referring to Figure 11 , which further shows Figure 10 the details of step 530 in the cross-domain small sample anomaly detection method 500 according to an exemplary embodiment of the present disclosure. As Figure 11 indicated, step 530 in the cross-domain small sample anomaly detection method 500 can include the following steps:
[0122] In step 531, the feature mean and feature variance of the detection image feature vector are determined;
[0123] At step 532, a normalized detection image feature vector is determined based on the detection image feature vector, the feature mean and the feature variance;
[0124] At step 533, a first similarity between the feature mean and first style data of each style data group is determined, a second similarity between the feature variance and second style data of each style data group is determined, and a style data group with the largest first similarity and second similarity is determined as a selected style data group;
[0125] At step 534, a style-enhanced detection image feature vector is determined based on the normalized detection image feature vector, the detection image feature vector, and the first style data and the second style data included in the selected style data group.
[0126] It should be understood that the feature mean and the feature variance of the detection image feature vector can be calculated by using the above-mentioned formula 1 and formula 2, the normalized detection image feature vector can be calculated by using the above-mentioned formula 7, the first similarity and the second similarity can be calculated by using the above-mentioned formula 3 and formula 4, and the style-enhanced detection image feature vector can be calculated by using the above-mentioned formula 8. From the above analysis, it can be known that the cross-domain small sample anomaly detection method 500 selects the style data with the largest similarity value when the feature is enhanced, which is beneficial to further reducing the domain difference, thereby improving the detection performance of the model.
[0127] Referring to Figure 12 , further illustrates Figure 10 the details of step 540 in the cross-domain small sample anomaly detection method 500 according to an example embodiment of the present disclosure. As Figure 12 illustrated, step 540 in the cross-domain small sample anomaly detection method 500 can include the following steps:
[0128] At step 541, a support sample image feature representation of each pixel position of the support sample image is determined based on the support sample feature vector;
[0129] At step 542, a detection image feature representation of each pixel position of the detection image is determined based on the style-enhanced detection image feature vector;
[0130] At step 543, each pixel position in the support sample image is evaluated based on the support sample image feature representation, to obtain a support sample image evaluation score of each pixel position of the support sample image;
[0131] In step 544, based on the feature representation of the detected image, the position of each pixel in the detected image is evaluated to obtain a detection image evaluation score for each pixel position in the detected image;
[0132] In step 545, for each pixel location, the corresponding detection image evaluation score is compared with the corresponding supporting sample image evaluation score, and the pixel location where the difference between the two is greater than a predetermined threshold is determined as the location where there is an anomaly.
[0133] For example, in steps 541 and 542, the support sample image feature representation of each pixel position in the support sample image can be determined from the support sample feature vector through upsampling, and the detection image feature representation of each pixel position in the detection image can be determined from the style-enhanced detection image feature vector. It should be understood that there is a one-to-one correspondence between each pixel position in the support sample image and each pixel position in the detection image.
[0134] In one embodiment, the evaluation score can be obtained by calculating the Mahalanobis distance at each pixel location. For example, suppose the supporting sample image features are represented as follows: Where (i,j) represents the pixel position in the support sample image, the Mahalanobis distance of each pixel position can be calculated using the following formula:
[0135]
[0136] Where, μ ij It supports the representation of sample image features as The sample mean, Σ ij The covariance is calculated for each pixel location. Similarly, for the detected image, the Mahalanobis distance of each pixel location can be calculated using Equation 12 above, and used as the evaluation score.
[0137] The evaluation score of the detected image corresponding to each pixel location is compared with the evaluation score of the corresponding support sample image. Pixel locations where the difference between the two is greater than a predetermined threshold are identified as anomaly locations. For example, if the evaluation score of the detected image for a pixel location is higher than the evaluation score of the support sample image, then that pixel location can be determined to be anomaly.
[0138] See Figure 13 The diagram schematically illustrates the structure of a cross-domain small sample anomaly detection device according to an exemplary embodiment of the present disclosure. Figure 13As shown, the cross-domain few-sample anomaly detection device 700 may include: a data acquisition module 710, a feature acquisition module 720, a style memory module 730, a style enhancement module 740, and an evaluation module 750. Specifically, the data acquisition module 710 may be configured to: acquire a detection dataset, which includes a detection sample set and a support sample set. The feature acquisition module 720 may be configured to: acquire detection image feature vectors from all detection images in the detection sample set, and acquire support sample feature vectors from all support sample images in the support sample set. The style memory module 730 may be configured to: store multiple style data groups, each style data group including first style data and second style data reflecting domain features. The style enhancement module 740 may be configured to: select the style data group with the smallest domain difference from the detection image feature vector from the pre-stored style data groups and perform style enhancement on the detection image feature vector to obtain a style-enhanced detection image feature vector. The evaluation module 750 may be configured to: evaluate all detection images in the detection sample set based on the support sample feature vector and the style-enhanced detection image feature vector to determine whether anomalies exist.
[0139] It can be seen that the cross-domain small sample anomaly detection device 700 enhances the feature vector of the detected image by using style data, which can transfer knowledge from the training domain to the test domain, reduce the gap between domains and strengthen the semantic feature representation, thereby improving the cross-domain detection capability.
[0140] It should be understood that, Figure 13 The modules shown in the text relate to the topics discussed above. Figure 10 The operation of the corresponding steps in the cross-domain few-sample anomaly detection method 500 and its exemplary embodiments described herein will not be repeated here. Furthermore, the various modules described in this disclosure can be implemented in hardware or in hardware combined with software and / or firmware. For example, these modules can be implemented as computer-executable code / instructions configured to execute in one or more processors and stored in a computer-readable storage medium. Alternatively, these modules can be implemented as hardware logic / circuit. As a non-limiting example, one or more of these modules can be implemented in a system-on-a-chip (SoC). An SoC may include an integrated circuit chip (which includes a processor (e.g., a central processing unit (CPU), microcontroller, microprocessor, digital signal processor (DSP), etc.), memory, one or more communication interfaces, and / or one or more components of other circuitry) and may optionally execute received program code and / or include embedded firmware to perform functions.
[0141] See Figure 14which schematically illustrates a computer device in accordance with some embodiments of the present disclosure. As shown Figure 14 The computer device 900 can be used in the various exemplary embodiments described in the present disclosure, and it can implement the various training methods and cross-domain few-shot anomaly detection methods described in the present disclosure.
[0142] The computer device 900 can include at least one processor 902, memory 904, communication interface(s) 906, display device 908, other input / output (I / O) devices 910, and one or more mass storage devices 912, which are able to communicate with each other, such as through a system bus 914 or other appropriate means.
[0143] The processor 902 can be a single processing unit or a plurality of processing units, all of which can include single or multiple computing units or multiple cores. The processor 902 can be implemented as one or more microprocessors, microcomputers, microcontrollers, digital signal processors, central processing units, state machines, logic circuitries, and / or any devices that manipulate signals based on operational instructions. Among other capabilities, the processor 902 can be configured to fetch and execute computer-readable instructions stored in the memory 904, the mass storage device 912, or any other computer-readable storage medium, such as program code of an operating system 916, program code of application programs 918, program code of other programs 920, and the like.
[0144] The memory 904 and the mass storage device 912 are examples of computer-readable storage media for storing instructions that can be executed by the processor 902 to implement the various functionalities described above. By way of example, the memory 904 can include both volatile memory and non-volatile memory (e.g., RAM, ROM, etc.). In addition, the mass storage device 912 can include hard disk drives, solid state drives, removable media, including external and removable drives, memory cards, flash memory, floppy disks, optical disks (e.g., CD, DVD), storage arrays, network attached storage, storage area networks, and the like. The memory 904 and the mass storage device 912 can both be collectively referred to herein as computer-readable storage or computer-readable storage media, and can be non-transitory media that can store computer-readable, processor-executable program instructions as computer-executable code that can be executed by the processor 902 as a particular machine configured to implement the operations and functionalities described in the various exemplary embodiments of the present disclosure.
[0145] A number of program modules can be stored on the mass storage device 912. These program modules can include an operating system 916, one or more application programs 918, other programs 920, and program data 922, and they can be executed by the processor 902. Examples of such application programs or program modules can include, for example, computer program logic (e.g., computer executable instructions or code) for implementing the data acquisition module 710, the feature acquisition module 720, the style memorization module 730, the style augmentation module 740, and the evaluation module 750.
[0146] Although illustrated in Figure 14 the memory 904 of the computer device 900, the various modules described above, or portions of them, can be implemented using any form of computer readable storage media accessible by the computer device 900. As used herein, "computer readable storage media" includes at least two types of computer readable storage media, which are computer storage media and communication media. Computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information for access by a computing device. In contrast, communication media can embody computer readable instructions, data structures, program modules, or other data in a modulated data signal, such as a carrier wave, or other transport mechanism. Computer storage media defined by the present disclosure does not include communication media.
[0147] The computer device 900 can also include one or more communication interfaces 906 for exchanging data with other devices, such as over a network, a direct connection, or the like. The communication interface 906 can facilitate communications over a variety of network and protocol types, including wired networks (e.g., LAN, cable, etc.) and wireless networks (e.g., WLAN, cellular, satellite, etc.), the Internet, and the like. The communication interface 906 can also provide communications with external storage devices (not shown), such as storage arrays, network attached storage, storage area networks, and the like.
[0148] In some examples, the computer device 900 can also include a display device 908, such as a display, for displaying information and images. Other I / O devices 910 can be devices that receive input from and / or provide output to a target object, including, but not limited to, touch input devices, gesture input devices, cameras, keyboards, remote controls, mice, printers, audio input / output devices, and the like.
[0149] The present disclosure also relates to a computer-readable storage medium configured to store computer-executable instructions configured to, when executed on a processor, cause the processor to perform the training method and / or the cross-domain few-shot anomaly detection method according to the example embodiments of the present disclosure. It should be understood that the computer-readable storage medium should be any suitable storage medium including, but not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or semiconductor media (for example, solid state disk (SSD)), or any other non-transmission medium that can be used to store information for access by a computing device. The present disclosure does not limit the computer-readable storage medium.
[0150] In addition, the present disclosure also relates to a computer program product including computer-executable instructions configured to, when executed on a processor, cause the processor to perform the training method and / or the cross-domain few-shot anomaly detection method according to the example embodiments of the present disclosure.
[0151] When implemented using software, the training method and / or the cross-domain few-shot anomaly detection method according to the present disclosure can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, the computer program instructions produce, in whole or in part, the processes or functions according to the example embodiments of the present disclosure. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions can be transferred from one website site, computer, server or data center to another website site, computer, server or data center through wired (for example, coaxial cable, optical fiber, digital subscriber line) or wireless (for example, infrared, wireless, microwave, etc.) means.
[0152] The terminology used in the present disclosure is only for the purpose of describing embodiments of the present disclosure and is not intended to limit the present disclosure. As used in the present disclosure, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and "comprising," when used in this specification, specify the presence of stated features, but do not preclude the presence or addition of one or more other features. As used in the present disclosure, the term "and / or" includes any and all combinations of one or more of the associated listed items. It will be understood that, although the terms "first," "second," "third," etc. can be used herein to describe various features, these features should not be limited by these terms. These terms are only used to distinguish one feature from another.
[0153] Unless otherwise defined, all terms (including technical and scientific terms) used in the present disclosure have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure belongs. It will be further understood that terms, such as those defined in commonly used dictionaries, should be interpreted as having a meaning that is consistent with their meaning in the context of the relevant art and / or the present specification, and will not be interpreted in an idealized or overly formal sense unless expressly so defined in the present disclosure.
[0154] In the present disclosure, the term "module" or "unit" refers to a computer program or a part of a computer program having a predetermined function, and works together with other relevant parts to achieve a predetermined target, and can be implemented entirely or partially by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an integral module or unit that includes the function of the module or unit.
[0155] It can be understood that in the specific embodiments of the present application, training data sets related to training of cross-domain small sample anomaly detection models and detection data sets related to detection are involved. When the above embodiments of the present application are applied to specific products or technologies, the data in the related data sets will require user permission or consent, and the collection, use and processing requirements of the related data will comply with relevant laws, regulations and standards of relevant countries and regions.
[0156] In the description of the disclosure, the description of the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" and the like means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the disclosure. In the specification, the illustrative description of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any appropriate manner in any one or more embodiments or examples. In addition, the person skilled in the art can combine and combine the different embodiments or examples described in the specification and the features of the different embodiments or examples, or can omit some technical features from the different embodiments or examples described in the specification, and the embodiments or examples obtained based on such combination, combination or omission are also considered to fall within the scope of the disclosure.
[0157] The methods described in the disclosure include one or more steps or actions. These method steps and / or actions do not necessarily have to be performed in the order described in the disclosure, but can be performed in different orders. For example, these method steps and / or actions can be performed simultaneously or in reverse order, as long as it does not contradict the principles of the technical solutions described in the disclosure. In addition, according to actual needs, the steps and / or actions in the methods described in the disclosure can be replaced by different steps and / or actions, or additional steps and / or actions can also be included.
[0158] Although the disclosure has been described in detail in conjunction with some exemplary embodiments, it is not limited to the specific forms described in the disclosure. On the contrary, the scope of the disclosure is only limited by the appended claims.
Claims
1. A training method of a cross-domain small sample anomaly detection model, characterized in that, The method comprises: obtaining a training data set comprising a query sample set and a support sample set; determining a query image feature vector from a query image included in the query sample set and a support sample feature vector from a support sample image included in the support sample set; updating first style data and second style data included in each style data group pre-stored based on the query image feature vector, to obtain updated first style data and updated second style data, wherein each style data group reflects different domain characteristics; performing style enhancement on the query image feature vector from a style data group having the largest domain difference with the query image feature vector among the style data groups, to obtain a style-enhanced query image feature vector; training the cross-domain small sample anomaly detection model based on the support sample feature vector and the style-enhanced query image feature vector.
2. The training method of claim 1, wherein, The updating of the first style data and the second style data included in each style data group pre-stored based on the query image feature vector comprises: determining a feature mean and a feature variance of the query image feature vector; determining a first similarity between the first style data and the feature mean and a second similarity between the second style data and the feature variance; performing weighted summation of the product of the feature mean and the first similarity and the first style data, to obtain the updated first style data, and performing weighted summation of the product of the feature variance and the second similarity and the second style data, to obtain the updated second style data.
3. The training method of claim 1, wherein, The performing of style enhancement on the query image feature vector from a style data group having the largest domain difference with the query image feature vector among the style data groups comprises: determining a feature mean and a feature variance of the query image feature vector; determining a normalized query image feature vector based on the query image feature vector, the feature mean and the feature variance; determining a first similarity between the feature mean and the updated first style data of each style data group and a second similarity between the feature variance and the updated second style data of each style data group, and determining a selected style data group as the style data group having the smallest first similarity and second similarity; determining the style-enhanced query image feature vector based on the normalized query image feature vector, the query image feature vector and the updated first style data and the updated second style data included in the selected style data group.
4. The training method of claim 1, wherein, The training of the cross-domain small sample anomaly detection model based on the support sample feature vector and the style-enhanced query image feature vector further comprises: passing the support sample feature vector and the style-enhanced query image feature vector through an encoder network, to obtain an encoded support sample feature vector and an encoded query image feature vector, respectively; passing the encoded support sample feature vector and the encoded query image feature vector through a prediction network to obtain a predicted support sample feature vector and a predicted query image feature vector respectively; determining a matching loss based on the encoded support sample feature vector, the predicted support sample feature vector, the encoded query image feature vector and the predicted query image feature vector; determining the matching loss as a model loss of the cross-domain small sample anomaly detection model.
5. The training method of claim 1, wherein, The training of the cross-domain small sample anomaly detection model based on the support sample feature vector and the style-enhanced query image feature vector further includes: passing the support sample feature vector and the style-enhanced query image feature vector through an encoder network to obtain an encoded support sample feature vector and an encoded query image feature vector respectively; passing the encoded support sample feature vector and the encoded query image feature vector through a prediction network to obtain a predicted support sample feature vector and a predicted query image feature vector respectively; determining a matching loss based on the encoded support sample feature vector, the predicted support sample feature vector, the encoded query image feature vector and the predicted query image feature vector; classifying the encoded query image feature vector based on all query images of the query sample set to obtain a classified encoded query image feature vector; determining an inter-class contrast loss based on the classified encoded query image feature vector; performing weighted summation on the matching loss and the inter-class contrast loss, and determining the obtained sum as a model loss of the cross-domain small sample anomaly detection model.
6. A cross-domain small sample anomaly detection method, characterized in that, It includes: obtaining a detection data set, the detection data set including a detection sample set and a support sample set; determining a detection image feature vector from a detection image included in the detection sample set, and determining a support sample feature vector from a support sample image included in the support sample set; performing style enhancement on the detection image feature vector by selecting a style data group with the smallest domain difference from the detection image feature vector from each pre-stored style data group, to obtain a style-enhanced detection image feature vector, wherein each style data group includes first style data and second style data reflecting domain features; based on the support sample feature vector and the style-enhanced detection image feature vector, evaluating all detection images of the detection sample set to determine whether there is an anomaly.
7. The cross-domain small sample anomaly detection method of claim 6, wherein, The style enhancement on the detection image feature vector by selecting a style data group with the smallest domain difference from the detection image feature vector from each pre-stored style data group includes: determining a feature mean and a feature variance of the detection image feature vector; based on the detection image feature vector, the feature mean and the feature variance, determining a normalized detection image feature vector; determining a first similarity of the feature mean and first style data of each style data group, determining a second similarity of the feature variance and second style data of each style data group, and determining a style data group with the maximum first similarity and second similarity as a selected style data group; determining the style-enhanced detection image feature vector based on the normalized detection image feature vector, the detection image feature vector, and first style data and second style data included in the selected style data group.
8. The cross-domain small sample anomaly detection method of claim 6, wherein, The evaluation of all detection images in the detection sample set based on the support sample feature vector and the style-enhanced detection image feature vector to determine whether there is an anomaly further includes: determining a support sample image feature representation of each pixel position of the support sample image based on the support sample feature vector; determining a detection image feature representation of each pixel position of the detection image based on the style-enhanced detection image feature vector; evaluating each pixel position in the support sample image based on the support sample image feature representation to obtain a support sample image evaluation score of each pixel position of the support sample image; evaluating each pixel position in the detection image based on the detection image feature representation to obtain a detection image evaluation score of each pixel position of the detection image; for each pixel position, comparing the corresponding detection image evaluation score with the corresponding support sample image evaluation score, and determining a pixel position with a difference greater than a predetermined threshold as an abnormal position.
9. The cross-domain small sample anomaly detection method according to claim 8, wherein: the evaluation of each pixel position in the support sample image based on the support sample image feature representation to obtain a support sample image evaluation score of each pixel position of the support sample image includes determining Mahalanobis distance of each pixel position in the support sample image as the support sample image evaluation score based on the support sample image feature representation; the evaluation of each pixel position in the detection image based on the detection image feature representation to obtain a detection image evaluation score of each pixel position of the detection image includes determining Mahalanobis distance of each pixel position in the detection image as the detection image evaluation score based on the detection image feature representation.
10. A cross-domain small sample anomaly detection apparatus, characterized by, comprising: a data acquisition module configured to acquire a detection data set, the detection data set including a detection sample set and a support sample set; a feature acquisition module configured to acquire a detection image feature vector from all detection images in the detection sample set, and acquire a support sample feature vector from all support sample images in the support sample set; a style memory module configured to store a plurality of style data groups, each style data group including first style data and second style data reflecting domain features; a style enhancement module configured to: select a style data group with the least domain difference from the detected image feature vector from pre-stored style data groups, and perform style enhancement on the detected image feature vector to obtain a style-enhanced detected image feature vector; an evaluation module configured to: evaluate all detected images in the detection sample set based on the support sample feature vector and the style-enhanced detected image feature vector, and determine whether there is an anomaly. 11.A computer device, comprising a memory and a processor, wherein a computer program is stored on the memory, and the computer device is characterized in that, The processor executes the computer program to implement the steps of the training method according to any one of claims 1 to 5 or implement the steps of the cross-domain small sample anomaly detection method according to any one of claims 6 to 9.
12. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program, when executed by the processor, implements the steps of the training method according to any one of claims 1 to 5 or implements the steps of the cross-domain small sample anomaly detection method according to any one of claims 6 to 9.
13. A computer program product comprising a computer program, characterized in that, The computer program, when executed by the processor, implements the steps of the training method according to any one of claims 1 to 5 or implements the steps of the cross-domain small sample anomaly detection method according to any one of claims 6 to 9.