Abnormal recognition method, model training method and device
By using feature extraction models and data augmentation techniques, the feature distribution of normal samples is used to identify data anomalies, which solves the problems of poor anomaly identification and high model update costs in existing technologies, and achieves efficient and flexible anomaly identification and strategy updates.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING BAIDU NETCOM SCI & TECH CO LTD
- Filing Date
- 2025-12-09
- Publication Date
- 2026-04-21
AI Technical Summary
Existing anomaly detection technologies are ineffective in scenarios where anomaly detection strategies are sensitive and anomaly samples are scarce. Furthermore, model updates are costly and difficult to adapt to policy changes.
By employing a trained feature extraction model, features are extracted from normal samples to determine the central feature vector and anomaly distance threshold. The feature vector distance is used to identify data anomalies. Combined with data augmentation techniques, the model is trained, reducing the requirements for obtaining sample data and enabling rapid strategy updates.
It improves the accuracy and efficiency of anomaly identification, reduces the requirements for obtaining sample data, enhances the flexibility and interpretability of the model, and can quickly adapt to changes in anomaly judgment strategies.
Smart Images

Figure CN121901699A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the technical fields of artificial intelligence, large models, and deep learning, and in particular to an anomaly identification method, model training method, and apparatus. Background Technology
[0002] In related technologies, anomaly identification mainly employs end-to-end classification models, rule-and-feature pipeline approaches, and multimodal large-scale models. However, these approaches all heavily rely on highly accurate labeled anomaly sample data, resulting in poor anomaly identification performance in scenarios where anomaly detection strategies are sensitive and anomaly samples are scarce. Moreover, when anomaly detection strategies change, the model needs to be relabeled and retrained, which is time-consuming and costly. While pipeline approaches can quickly modify rules, maintaining the rule system becomes extremely difficult as the strategies become more complex. Summary of the Invention
[0003] An anomaly identification method, model training method, and apparatus are disclosed.
[0004] According to one aspect of this disclosure, an anomaly identification method is provided, the method comprising: using a trained feature extraction model to extract features from at least one normal sample in a normal sample set to obtain feature vectors of the at least one normal sample; determining a first central feature vector and a first anomaly distance threshold of the at least one normal sample based on the feature vectors of the at least one normal sample; using the trained feature extraction model to extract features from data to be identified to obtain feature vectors of the data to be identified; and determining whether the data to be identified is anomaly based on the distance between the feature vector of the data to be identified and the first central feature vector, and the first anomaly distance threshold.
[0005] According to another aspect of this disclosure, a model training method is provided, the method comprising: selecting training samples from a normal sample set; performing data augmentation processing on the training samples to obtain augmented sample pairs corresponding to the training samples; inputting the augmented sample pairs corresponding to the training samples into a feature extraction model to obtain feature vectors of the augmented samples in the augmented sample pairs; and training the feature extraction model based on the similarity between the feature vectors of the augmented samples in the augmented sample pairs to obtain a trained feature extraction model.
[0006] According to another aspect of this disclosure, an anomaly identification device is provided, the device comprising: a first feature extraction module, configured to use a trained feature extraction model to extract features from at least one normal sample in a normal sample set to obtain feature vectors of the at least one normal sample; a first determination module, configured to determine a first central feature vector and a first anomaly distance threshold of the at least one normal sample based on the feature vectors of the at least one normal sample; a second feature extraction module, configured to use the trained feature extraction model to extract features from data to be identified to obtain feature vectors of the data to be identified; and a second determination module, configured to determine whether the data to be identified is abnormal based on the distance between the feature vector of the data to be identified and the first central feature vector, and the first anomaly distance threshold.
[0007] According to another aspect of this disclosure, a model training method is provided, comprising: a selection module for selecting training samples from a normal sample set; a second processing module for performing data augmentation processing on the training samples to obtain augmented sample pairs corresponding to the training samples; an input module for inputting the augmented sample pairs corresponding to the training samples into a feature extraction model to obtain feature vectors of the augmented samples in the augmented sample pairs; and a training module for training the feature extraction model based on the similarity between the feature vectors of the augmented samples in the augmented sample pairs to obtain a trained feature extraction model.
[0008] According to another aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the anomaly identification method or model training method proposed above in this disclosure.
[0009] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided that stores computer instructions for causing the computer to execute the anomaly identification method or model training method proposed in this disclosure.
[0010] According to another aspect of this disclosure, a computer program product is provided, including a computer program / instructions, which, when executed by a processor, implement the anomaly identification method or model training method proposed above.
[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0012] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein: Figure 1 A flowchart illustrating an anomaly identification method provided in an embodiment of this disclosure; Figure 2 A flowchart illustrating another anomaly identification method provided in this embodiment of the disclosure; Figure 3 A flowchart illustrating another anomaly identification method provided in this embodiment of the disclosure; Figure 4 A schematic flowchart of a model training method provided in an embodiment of this disclosure; Figure 5 A flowchart illustrating another model training method provided in this embodiment of the disclosure; Figure 6(a) is a schematic diagram of the principle of an anomaly identification method provided in an embodiment of this disclosure; Figure 6(b) is a schematic diagram illustrating the application of an anomaly identification method provided in an embodiment of this disclosure; Figure 7 This is a schematic diagram of the structure of an anomaly detection device provided in an embodiment of this disclosure; Figure 8 This is a schematic diagram of the structure of a model training device provided in an embodiment of the present disclosure; Figure 9 A schematic block diagram of an example electronic device 900 that can be used to implement embodiments of the present disclosure is shown. Detailed Implementation
[0013] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0014] In related technologies, the main approaches for anomaly identification include end-to-end classification model-based schemes, rule-and-feature-based pipeline schemes, and multimodal large model-based schemes.
[0015] In end-to-end classification model-based solutions, a large number of abnormal and normal samples are collected, and a deep neural network (such as CNN (Convolutional Neural Network) or Transformer) is trained as a binary or multi-classifier, which directly determines whether the input content is abnormal. In a rule-based and feature-based pipeline solution, a multi-module pipeline system is constructed. This system first uses independent models to perform visual element recognition, text extraction, and sentiment analysis, and then inputs the extracted structured features into a rule engine or classifier, which judges whether an anomaly or normal behavior is determined according to a preset if-else logic. The multimodal large model-based approach leverages the inherent powerful vision-language joint understanding capabilities and rich world knowledge of multimodal large models (such as GPT-4V (GPT-4 with Vision, GPT (Generative Pre-trained Transformer))) as the core inference engine for anomaly detection. Specific implementation methods include: 1. Zero-shot / Few-shot Hint Classification: The image to be identified is directly input into an MLLM (Multimodal Large Language Model) along with a natural language hint describing the anomaly detection strategy (e.g., "Determine if this image contains violent content"). The MLLM then generates a classification decision. This method requires no training and relies on the model's internal prior knowledge for reasoning. 2. Supervised fine-tuning: Fine-tune the MLLM using data (images, text, labels) labeled for a specific anomaly recognition task to make it more accurately suited to the anomaly recognition needs of a specific scenario.
[0016] However, in the aforementioned schemes, the decision-making logic of the end-to-end model and the multimodal large-scale model using zero-shot / few-shot hint classification is a "black box," with opaque decision-making criteria. Although the supervised fine-tuning of the multimodal large-scale model allows the model to learn specific anomaly recognition task requirements through data, it typically only provides the conclusion, and the specific decision-making logic may not be transparent. While the pipelined approach is interpretable at the module level, the correlation between its final decision and the original strategy intent may be diluted by the complex rule chain.
[0017] Moreover, end-to-end models struggle to learn highly abstract and subjective anomaly detection strategies. For example, an anomaly detection strategy might be "prohibit incitement to violence, but allow satire and criticism." When faced with a satirical cartoon (which may contain violent symbols such as fists or weapons, but whose true intention is anti-violence), end-to-end models lack the ability to understand "irony," "metaphor," and "creative intent."
[0018] Furthermore, all of the above solutions heavily rely on highly accurate labeled anomaly sample data. In scenarios where anomaly detection strategies are sensitive and anomaly samples are scarce, the high cost of data acquisition makes it difficult to guarantee anomaly identification performance. Moreover, when anomaly detection strategies change, the model needs to be relabeled and retrained, which is time-consuming and costly. While pipeline solutions can quickly modify rules, maintaining the rule system becomes extremely difficult as the strategies become more complex.
[0019] To address the aforementioned issues, this disclosure proposes an anomaly identification method, a model training method, and an apparatus.
[0020] The anomaly identification method, model training method, and apparatus of this disclosure are described below with reference to the accompanying drawings.
[0021] Figure 1 This is a flowchart illustrating an anomaly identification method provided in an embodiment of this disclosure.
[0022] like Figure 1 As shown, this anomaly identification method may include the following steps: Step S101: Using the trained feature extraction model, extract features from at least one normal sample in the normal sample set to obtain the feature vector of at least one normal sample.
[0023] It should be noted that the execution entity of the anomaly identification method in this disclosure embodiment can be a hardware device with data processing capabilities and / or the necessary software to drive the hardware device. Optionally, the execution entity may include a server, a user terminal, and other smart devices. Optionally, the user terminal includes, but is not limited to, mobile phones, computers, smart voice interaction devices, etc. Optionally, the server includes, but is not limited to, a network server, an application server, or a server of a distributed system, or a server combined with blockchain, etc. This disclosure embodiment does not impose specific limitations.
[0024] The normal sample set is determined by domain experts based on effective anomaly detection strategies.
[0025] As an example, the normal sample set could be a set of N (N≥1) samples manually selected by domain experts based on a currently effective and clearly defined anomaly detection strategy. Each sample in this set is considered a model of "compliance" under that anomaly detection strategy.
[0026] The definition of the normal sample set is dynamic and can be updated as the effective anomaly detection strategy evolves.
[0027] As an example, suppose a domain expert has determined a set of normal samples based on the currently effective and explicit anomaly determination strategy 1. If the anomaly determination strategy changes and the currently effective anomaly determination strategy evolves from anomaly determination strategy 1 to anomaly determination strategy 2, then the domain expert can redetermine a set of normal samples based on the currently effective and explicit anomaly determination strategy 2.
[0028] The trained feature extraction model can extract features from the input content and output the corresponding feature vector.
[0029] As an example, the feature extraction model can adopt any deep vision network architecture, such as ResNet-50, Vision Transformer, etc., and replace its final classification head with a projection head, which consists of one or more fully connected layers to further map the features extracted by the encoder to a lower-dimensional projection space that is more suitable for similarity comparison.
[0030] In some embodiments, in order to improve the performance of anomaly identification in scenarios where anomaly detection strategies are sensitive and anomaly samples are scarce, the feature extraction model can be trained using only normal samples and a contrastive learning loss function to obtain the trained feature extraction model.
[0031] As an example, data augmentation can be performed on any normal sample (e.g., random cropping, random horizontal flipping, random color dithering, random grayscale conversion, Gaussian blurring, etc.) to generate a pair of augmented samples corresponding to that normal sample. Each pair of augmented samples corresponding to any normal sample is a positive sample pair, and any augmented sample corresponding to any normal sample and any augmented sample corresponding to other normal samples is a negative sample pair. The generated augmented samples are input into a feature extraction model to obtain their feature vectors. Based on the similarity between the feature vectors of positive sample pairs and the similarity between the feature vectors of negative sample pairs, a contrastive learning approach is used to train the feature extraction model (the training objective is to maximize the similarity between the feature vectors of positive sample pairs and minimize the similarity between the feature vectors of negative sample pairs), resulting in a trained feature extraction model.
[0032] In some embodiments, a trained feature extraction model can be used to extract features from each normal sample in the normal sample set to obtain the feature vector of each normal sample.
[0033] Step S102: Based on the feature vector of at least one normal sample, determine the first central feature vector of at least one normal sample and the first anomaly distance threshold.
[0034] Among them, the feature vector of at least one normal sample is a vector in the same feature space, and the first central feature vector is the central feature vector / mean feature vector of the feature vector of at least one normal sample.
[0035] The first abnormal distance threshold is determined based on the distance between the feature vector of at least one normal sample and the first central feature vector, and is the critical distance value for determining whether the data is normal or abnormal.
[0036] It should be noted that, since the first anomaly distance threshold is determined based on the distance between the feature vector of at least one normal sample and the first central feature vector, and the first central feature vector is the central feature vector / mean feature vector of the feature vector of at least one normal sample, the first anomaly distance threshold is the maximum value of the distance between the feature vector of a normal sample and the first central feature vector, and also the minimum value of the distance between the feature vector of an anomaly sample and the first central feature vector.
[0037] In some embodiments, the target quantile of the distance distribution between the feature vector of at least one normal sample and the first central feature vector can be used as the first anomaly distance threshold. The target quantile can be, for example, the 95th percentile or the 99th percentile.
[0038] In some embodiments, a first anomaly distance threshold can be determined based on the mean and standard deviation of the distance between the feature vector of at least one normal sample and the first central feature vector.
[0039] As an example, the mean distance between the feature vector of at least one normal sample and the first central feature vector can be determined using the following formula. and standard deviation :
[0040]
[0041] in, Indicates the number of normal samples. , Indicates the first The distance between each normal sample and the first central feature vector ; in, It measures the degree of dispersion of the feature vector of a normal sample relative to the first central feature vector: The smaller value indicates that the feature vectors of normal samples are all close to the first central feature vector. A large value indicates that the distance difference between the feature vector of a normal sample and the feature vector of the first center is large; Then based on the mean and standard deviation Determine the first anomaly distance threshold. , A scaling factor (e.g., a maximum tolerable false alarm rate based on task requirements) is set. =2).
[0042] In some embodiments, a first anomaly distance threshold can be determined based on the median and absolute median difference of the distance between the feature vector of at least one normal sample and the first central feature vector.
[0043] As an example, the median can be determined from the distance between the feature vectors that identify at least one normal sample and the first central feature vector. The absolute median difference is calculated using the following formula. :
[0044]
[0045] in, Indicates the first The distance between each normal sample and the first central feature vector express and The absolute deviation between Indicates from Determine the median; Then, based on the distance distribution between the feature vector of at least one normal sample and the first central feature vector, and the absolute median difference... Determine the equivalent standard deviation ,in, , Let represent a set coefficient. If the distance distribution between the feature vector of at least one normal sample and the first central feature vector conforms to a normal distribution, then... ,otherwise, Other settings are possible (for non-normal data, use a more conservative coefficient, where a smaller coefficient, such as 1 (more conservative), is used for a heavy-tailed distribution, and a larger coefficient, such as 1.2 (medium conservative), is used for a light-tailed distribution). Therefore, it can be based on the median and equivalent standard deviation Determine the first anomaly distance threshold. , A scaling factor (e.g., a maximum tolerable false alarm rate based on task requirements) is set. =2).
[0046] Step S103: Using the trained feature extraction model, feature extraction is performed on the data to be identified to obtain the feature vector of the data to be identified.
[0047] The data to be identified can be any data that needs to be identified as an anomaly.
[0048] In some embodiments, the data to be identified can be data encompassing different information formats. The data to be identified may include, for example, at least one of the following: text, images, audio, video, files, etc., without specific limitations, and can be set according to actual needs.
[0049] As an example, the data to be identified could be data generated from user input during the interaction between a large model and the user, covering different information formats.
[0050] Step S104: Determine whether the data to be identified is abnormal based on the distance between the feature vector of the data to be identified and the first central feature vector, and the first abnormal distance threshold.
[0051] The first anomaly distance threshold is determined based on the distance between the feature vector of at least one normal sample and the first central feature vector, and is a critical distance value for determining whether the data is normal or abnormal. Furthermore, the distance between the feature vector of the data to be identified and the first central feature vector can be compared with the first anomaly distance threshold, and based on the comparison result, it can be determined whether the data to be identified is abnormal.
[0052] As an example, the first anomaly distance threshold is the maximum distance between the feature vector of a normal sample and the first central feature vector, and also the minimum distance between the feature vector of an abnormal sample and the first central feature vector. Therefore, when the distance between the feature vector of the data to be identified and the first central feature vector is greater than the first anomaly distance threshold, the data to be identified can be determined to be abnormal; otherwise, the data to be identified is determined to be normal.
[0053] The anomaly detection method provided in this disclosure can determine whether the data to be identified is abnormal using only normal samples, reducing the requirements for obtaining sample data and improving the anomaly detection effect in scenarios where the anomaly detection strategy is sensitive and abnormal samples are scarce. Moreover, the anomaly detection criteria (first central feature vector and first anomaly distance threshold) are not predefined simple rules, but are dynamically learned from the normal sample set, which increases the difficulty for attackers to construct adversarial examples, making it difficult for attackers to construct adversarial examples through reverse engineering. In addition, when the anomaly detection strategy is adjusted, only the normal sample set needs to be updated and the feature extraction model needs to be fine-tuned to quickly deploy the new anomaly detection strategy, achieving efficient and convenient strategy updates.
[0054] Figure 2This is a flowchart illustrating another anomaly identification method provided in an embodiment of this disclosure.
[0055] like Figure 2 As shown, this anomaly identification method may include the following steps: Step S201: Using the trained feature extraction model, extract features from at least one normal sample in the normal sample set to obtain the feature vector of at least one normal sample.
[0056] In some embodiments, in order to enable the feature extraction model to learn more discriminative and information-rich features, the feature extraction model may include an encoder and a projection head. The encoder is used to extract features from the model input, and the projection head is used to map the features extracted by the encoder to a target projection space. The vector dimension of the target projection space is lower than the dimension of the features extracted by the encoder.
[0057] The encoder is used to extract high-level, general features from the model input (e.g., for image data, the features extracted by the encoder include image edges, textures, object parts, and overall structure; for text data, the features extracted by the encoder include semantics, grammatical structure, logical relationships, and sentiment). The projector is used to map the features extracted by the encoder to a lower-dimensional projection space that is more suitable for specific tasks (e.g., a projection space that is more suitable for similarity comparison).
[0058] The projection head can consist of one or more fully connected layers. The mapping performed by the projection head can be a non-linear mapping.
[0059] As an example, the feature extraction model can adopt any deep visual network architecture, such as ResNet-50, Vision Transformer, etc. In the visual network structure, the encoder is retained, and the classification head is replaced by the projection head. Thus, the feature extraction model includes an encoder and a projection head. The encoder is used to map the essential features of compliance to a region of a high-dimensional feature space, and the projection head is used to further map the features extracted by the encoder to a lower-dimensional projection space that is more suitable for similarity comparison.
[0060] The feature extraction model maps the features extracted by the encoder to the target projection space through the projection head. This not only removes irrelevant and redundant information from the features extracted by the encoder and strengthens the core discriminative features, but also reduces the dimensionality and computational complexity of subsequent calculations. At the same time, it can also enable the features to have better clustering characteristics and discriminativeness in the projection space, thereby enabling the feature extraction model to learn more discriminative and information-rich features.
[0061] The explanation of step S201 can be found in the relevant description in any embodiment of this disclosure, and will not be repeated here.
[0062] Step S202: Determine the first central feature vector of at least one normal sample based on the feature vector of at least one normal sample.
[0063] The first center feature vector is used to indicate the average center of at least one normal sample in the corresponding feature space.
[0064] In this embodiment, the feature vector of at least one normal sample is a vector in the same feature space. Therefore, in some embodiments, the mean of the feature vectors of at least one normal sample can be calculated and the mean can be used as the first central feature vector.
[0065] As an example, the first central characteristic vector of at least one normal sample can be determined using the following formula. :
[0066] in, Indicates the number of normal samples. , Indicates the first The feature vector of a normal sample.
[0067] Step S203: For any normal sample in at least one normal sample, determine the distance between the feature vector of the normal sample and the first central feature vector.
[0068] The distances include, but are not limited to, cosine distance, Euclidean distance, Manhattan distance, Mahalanobis distance, Chebyshev distance, etc.
[0069] In some embodiments, the distance can be a cosine distance. Therefore, for any normal sample in at least one normal sample, the cosine similarity between the feature vector of the normal sample and the first central feature vector can be determined first, and then the distance between the feature vector of the normal sample and the first central feature vector can be determined based on the cosine similarity between the feature vector of the normal sample and the first central feature vector.
[0070] As an example, the distance between the feature vector of any normal sample and the first central feature vector. ,in, Indicates the first The distance between each normal sample and the first central feature vector ( Indicates the number of normal samples. ), Indicates the first The feature vector of a normal sample Represents the first central eigenvector. It is the first Cosine similarity between the feature vectors of a normal sample and the first central feature vector.
[0071] Step S204: Determine the first abnormal distance threshold based on the distance between the feature vector of at least one normal sample and the first central feature vector.
[0072] In some embodiments, the average distance and distance standard deviation can be determined based on the distance between the feature vector of at least one normal sample and the first central feature vector; and a first anomaly distance threshold can be determined based on the average distance, the distance standard deviation, and a scaling factor; wherein the scaling factor is determined based on the target false alarm rate.
[0073] Therefore, by utilizing the distribution characteristics of normal samples, the threshold can be dynamically adapted to the dispersion of specific data, avoiding the blindness of subjectively setting the threshold and improving the objectivity and robustness of anomaly identification.
[0074] The average distance can be the distance between the feature vector of at least one normal sample and the feature vector of the first center. The standard deviation of the distance can be the standard deviation of the distance between the feature vector of at least one normal sample and the first central feature vector. , and The determination process is described in the relevant description of any embodiment of this disclosure and will not be repeated here.
[0075] The target false positive rate can be a tolerable maximum false positive rate determined based on task requirements. The false positive rate refers to the proportion of normal samples that are incorrectly classified as abnormal.
[0076] The higher the false alarm rate, the smaller the scaling factor; the lower the false alarm rate, the larger the scaling factor.
[0077] As an example, for high-security tasks, the goal is to avoid missing any anomalies. Therefore, it's preferable to falsely block some normal samples. In this case, there are more false positives than false negatives, i.e., a high false positive rate but a low false negative rate (the false negative rate refers to the proportion of anomaly samples that are incorrectly identified as normal). Correspondingly, the scaling factor is small, for example, the scaling factor can be in the range of [0.5, 1]. For general anomaly identification tasks, the false positive rate and the false negative rate are both moderate. Correspondingly, the scaling factor is also moderate, for example, the scaling factor can be 2. For low-cost operation and maintenance tasks, the goal is to minimize false positives (because false positives require manual processing, which is costly). Therefore, it's acceptable to miss some anomalies. In this case, there are fewer false positives but more false negatives, i.e., a low false positive rate but a high false negative rate. Correspondingly, the scaling factor is large, for example, the scaling factor can be greater than 3.
[0078] Therefore, by quantifying the acceptable false alarm rate of the task into a scaling factor, precise control of the identification sensitivity can be achieved, which can reasonably balance the core requirements of the task and the execution cost, and enhance the practicality, interpretability and operability of anomaly identification.
[0079] In some embodiments, a scaling factor can be used to scale the distance standard deviation to obtain the target distance; wherein the scaling factor is used to indicate the degree of scaling of the scaling process; and the sum of the average distance and the target distance is determined as the first abnormal distance threshold.
[0080] As an example, a first anomaly distance threshold can be determined. ,in, Indicates the average distance. Indicates the distance from the standard deviation. This represents the scaling factor. The effective radius of the "normal hypersphere" is defined.
[0081] The average distance represents the center position of the normal sample, while the target distance represents the normal fluctuation range determined based on task requirements.
[0082] The target distance is obtained by scaling the distance standard deviation using a scaling factor. This allows for flexible adjustment of the scaling degree according to task requirements, precisely controlling the variation in the distance standard deviation, and thus generating a target distance that better fits the task. The first anomaly distance threshold is obtained by adding the average distance to the target distance. This threshold comprehensively considers both the average level and dispersion of the data, avoiding bias caused by setting a threshold based on a single indicator, and improving the accuracy and reliability of anomaly identification.
[0083] Step S205: Using the trained feature extraction model, feature extraction is performed on the data to be identified to obtain the feature vector of the data to be identified.
[0084] The explanation of step S205 can be found in the relevant description in any embodiment of this disclosure, and will not be repeated here.
[0085] Step S206: Determine whether the data to be identified is abnormal based on the distance between the feature vector of the data to be identified and the first central feature vector, and the first abnormal distance threshold.
[0086] The distance between the feature vector of the data to be identified and the first central feature vector includes, but is not limited to, cosine distance, Euclidean distance, Manhattan distance, Mahalanobis distance, Chebyshev distance, etc.
[0087] In some embodiments, the distance between the feature vector of the data to be identified and the first central feature vector can be a cosine distance. Therefore, the cosine similarity between the feature vector of the data to be identified and the first central feature vector can be determined first. Then, the distance between the feature vector of the data to be identified and the first central feature vector can be determined based on the cosine similarity between the feature vector of the data to be identified and the first central feature vector.
[0088] As an example, the distance between the feature vector of the data to be identified and the first central feature vector. ,in, This represents the distance between the feature vector of the data to be identified and the first central feature vector. This represents the feature vector of the data to be identified. Represents the first central eigenvector. This represents the cosine similarity between the feature vector of the data to be identified and the first central feature vector.
[0089] Cosine similarity, by measuring the directional consistency between vectors, can effectively capture the similarity (such as semantic similarity, structural similarity, etc.) of high-dimensional data (such as text, images, etc.), without being affected by the vector magnitude. By transforming cosine similarity into a distance scalar that can be used for direct comparison or decision-making, it retains the advantages of cosine similarity in characterizing directional features, and uses the distance scalar to quantify the spatial positional differences between two vectors, providing multi-dimensional basis for subsequent identification processing and improving the reliability of anomaly identification results.
[0090] In some embodiments, the first abnormal distance threshold is used to indicate the maximum value of the distance between the feature vector of a normal sample and the first central feature vector. The distance between the feature vector of the data to be identified and the first central feature vector can be compared with the first abnormal distance threshold. In response to the distance between the feature vector of the data to be identified and the first central feature vector being greater than the first abnormal distance threshold, the data to be identified is determined to be abnormal.
[0091] Specifically, if the distance between the feature vector of the data to be identified and the first central feature vector is not greater than the first abnormal distance threshold, the data to be identified is determined to be normal.
[0092] As an example, the first anomaly distance threshold The effective radius of the "normal hypersphere" is defined as the distance between the feature vector of the data to be identified and the first central feature vector. If the distance between the feature vector of the data to be identified and the first central feature vector is considered, it can be determined that the data to be identified falls inside or on the surface of the "normal hypersphere" and is highly similar to normal samples in the normal sample set. Therefore, the data to be identified can be determined to be normal. If the distance between the feature vector of the data to be identified and the first central feature vector is considered... If so, it can be determined that the data to be identified falls outside the "normal hypersphere" and is not similar to the normal samples in the normal sample set, thus it can be determined that the data to be identified is abnormal.
[0093] By setting a first anomaly distance threshold, a distribution boundary for normal samples is established, providing a clear and quantifiable basis for the anomaly identification process. Comparing the distance between the feature vector of the data to be identified and the first central feature vector with the first anomaly distance threshold allows for rapid determination of whether the data is abnormal, thus improving the efficiency of anomaly identification.
[0094] Further explanations of step S206 can be found in the relevant descriptions in any embodiment of this disclosure, and will not be repeated here.
[0095] In some embodiments, in response to determining that the data to be identified is abnormal, the data to be identified may be marked as a target category, or a target operation may be performed on the data to be identified; wherein the target category is used to indicate that the data to be identified should be reviewed; the target operation includes refusing to perform related operations on the data to be identified, and / or generating a modification prompt for the data to be identified.
[0096] The modification prompt is used to suggest modifications to the data to be identified.
[0097] As an example, if the data to be identified is determined to be abnormal, it can be marked as a target category to indicate that it needs to be reviewed (such as manually), or, depending on the configuration, operations related to the data to be identified can be refused, or, depending on the configuration, a modification prompt for the data to be identified can be generated.
[0098] Specifically, when data to be identified as abnormal is marked as requiring review, it ensures that suspicious data is not arbitrarily disposed of but is further clarified through manual or more sophisticated algorithmic review. This reduces the risk of loss of valid data due to machine misjudgment and improves the accuracy of data processing. When data to be identified as abnormal, operations related to that data are refused, preventing suspicious data from interfering with subsequent processes and ensuring their stable operation. When data to be identified as abnormal is generated, modification prompts are generated to assist in correcting the data, enhancing its accuracy and integrity, and improving data flow efficiency.
[0099] The anomaly identification method provided in this disclosure uses the feature distribution of normal samples as its core basis. It accurately anchors the clustering center of normal samples in the corresponding feature space through a first central feature vector, establishing a benchmark that aligns with the essential laws of the data for anomaly identification and avoiding deviations caused by subjectively set judgment standards. Simultaneously, determining a first anomaly distance threshold based on the distance between the characteristic vector of a normal sample and the first central feature vector allows the setting of the first anomaly distance threshold to closely match the feature dispersion of normal samples in the normal sample set. This avoids missing anomaly samples due to an excessively wide threshold, and also prevents misjudging normally fluctuating samples as anomalies due to an excessively narrow threshold, thus improving the accuracy and reliability of anomaly identification.
[0100] Figure 3 This is a flowchart illustrating another anomaly identification method provided in this embodiment. In this embodiment, the normal sample set is determined by domain experts based on an effective anomaly detection strategy.
[0101] like Figure 3 As shown, this anomaly identification method may include the following steps: Step S301: Using the trained feature extraction model, extract features from at least one normal sample in the normal sample set to obtain the feature vector of at least one normal sample.
[0102] Step S302: Based on the feature vector of at least one normal sample, determine the first central feature vector of at least one normal sample and the first anomaly distance threshold.
[0103] Step S303: Using the trained feature extraction model, feature extraction is performed on the data to be identified to obtain the feature vector of the data to be identified.
[0104] Step S304: Determine whether the data to be identified is abnormal based on the distance between the feature vector of the data to be identified and the first central feature vector, and the first abnormal distance threshold.
[0105] The explanation of steps S301-S304 can be found in the relevant descriptions in any embodiment of this disclosure, and will not be repeated here.
[0106] Step S305: In response to the anomaly detection strategy update, obtain the updated set of normal samples.
[0107] Since the definition of the normal sample set is dynamic and can be updated as the effective anomaly detection strategy evolves, in some embodiments, if the effective anomaly detection strategy is updated, a new normal sample set can be redefined by a domain expert based on the updated anomaly detection strategy.
[0108] Step S306: Using the trained feature extraction model, determine at least one feature vector of the updated normal sample in the updated normal sample set.
[0109] In some embodiments, a trained feature extraction model can be used to extract features from each updated normal sample in the updated normal sample set to obtain the feature vector of each updated normal sample.
[0110] Step S307: Based on the feature vector of at least one updated normal sample, determine at least one second center feature vector of the updated normal sample and a second anomaly distance threshold.
[0111] The process of determining at least one second central feature vector of an updated normal sample and a second anomaly distance threshold based on at least one feature vector of an updated normal sample is similar to the process of determining at least one first central feature vector of a normal sample and a first anomaly distance threshold based on the feature vector of at least one normal sample. For related explanations, please refer to the relevant descriptions in any embodiment of this disclosure, which will not be repeated here.
[0112] Step S308: Update the first center feature vector using the second center feature vector, and update the first anomaly distance threshold using the second anomaly distance threshold.
[0113] In some embodiments, after determining the second central feature vector and the second anomaly distance threshold, the first central feature vector can be replaced by the second central feature vector, and the first anomaly distance threshold can be replaced by the second anomaly distance threshold.
[0114] The anomaly identification method provided in this disclosure achieves efficient and adaptive anomaly identification by combining a trained feature extraction model with a distance threshold judgment mechanism based on the feature distribution of normal samples. When the anomaly judgment strategy is updated, there is no need to retrain the feature extraction model; only the central feature vector and the anomaly distance threshold need to be dynamically updated based on the normal sample set under the new strategy to quickly adapt to the new anomaly judgment strategy, thus achieving efficient and convenient strategy updates.
[0115] Figure 4 This is a schematic flowchart of a model training method provided in an embodiment of the present disclosure.
[0116] like Figure 4 As shown, the model training method may include the following steps: Step S401: Select training samples from the normal sample set.
[0117] In some embodiments, at least a portion of normal samples may be selected from the normal sample set as training samples.
[0118] For an explanation of the normal sample set, please refer to the relevant description in any embodiment of this disclosure, and it will not be repeated here.
[0119] As an example, the normal sample set could be D = {x_1, x_2, ..., x_N}. Then, a batch of data {x_1, x_2, ..., x_B} of size B (B≤N) can be randomly sampled from the normal sample set D as training samples.
[0120] Step S402: Perform data augmentation on the training samples to obtain augmented sample pairs corresponding to the training samples.
[0121] Data augmentation processing includes, but is not limited to, random cropping, random horizontal flipping, random color dithering, random grayscale conversion, and Gaussian blurring.
[0122] In some embodiments, for any training sample, two independent random data augmentation processes can be performed on the training sample to generate a set of augmented samples corresponding to the training sample.
[0123] As an example, the normal sample set is D = {x_1, x_2, ..., x_N}. A batch of data {x_1, x_2, ..., x_B} of size B (B≤N) is randomly sampled from the normal sample set D as training samples. Then, for each training sample x_k (1≤K≤B), an augmented view pair x_{k_i} and x_{k_j} can be generated through two independent random data augmentation processes.
[0124] Step S403: Input the augmented sample pairs corresponding to the training samples into the feature extraction model to obtain the feature vectors of the augmented samples in the augmented sample pairs.
[0125] As an example, the normal sample set is D = {x_1, x_2, ..., x_N}. A batch of data {x_1, x_2, ..., x_B} of size B (B≤N) is randomly sampled from the normal sample set D as training samples. Then, the augmented sample pairs {x_{1_i}, x_{1_j}, x_{2_i}, x_{2_j}, ..., x_{B_i}, x_{B_j}} corresponding to the training samples {x_1, x_2, ..., x_B} are input into the feature extraction model to obtain their feature vectors.
[0126] Step S404: Based on the similarity between the feature vectors of the enhanced samples in the enhanced sample pair, train the feature extraction model to obtain the trained feature extraction model.
[0127] In this model, any pair of augmented samples corresponding to any normal sample is a positive sample pair, and any augmented sample corresponding to any normal sample and any augmented sample corresponding to other normal samples is a negative sample pair. In some embodiments, the feature extraction model can be trained using a contrastive learning approach based on the similarity between the feature vectors of positive sample pairs and the similarity between the feature vectors of negative sample pairs (the training objective is to maximize the similarity between the feature vectors of positive sample pairs and minimize the similarity between the feature vectors of negative sample pairs), thus obtaining the trained feature extraction model.
[0128] The model training method provided in this disclosure generates augmented sample pairs through data augmentation, which enhances data diversity, helps the feature extraction model learn more robust features, and avoids overfitting. By training the feature extraction model based on the similarity between multiple augmented samples in the augmented sample pair, the model can be trained to extract similar features for different augmented versions of the same original sample. Furthermore, only normal samples are used as training samples during the training process, reducing the dependence on labeled data. This allows the feature extraction model to learn more discriminative and robust feature representations even in scenarios where anomaly detection strategies are sensitive and anomaly samples are scarce.
[0129] Figure 5 This is a flowchart illustrating another model training method provided in an embodiment of the present disclosure.
[0130] like Figure 5 As shown, the model training method may include the following steps: Step S501: Select training samples from the normal sample set.
[0131] Step S502: Perform data augmentation on the training samples to obtain augmented sample pairs corresponding to the training samples.
[0132] Step S503: Input the augmented sample pairs corresponding to the training samples into the feature extraction model.
[0133] In some embodiments, to enable the feature extraction model to learn more discriminative and information-rich features, the feature extraction model may include an encoder and a projection head. The encoder is used to extract features from the model input, and the projection head is used to map the features extracted by the encoder to a target projection space; wherein the dimension of the vectors in the target projection space is lower than the dimension of the features extracted by the encoder. Related details can be found in the relevant descriptions of any embodiment of this disclosure, and will not be repeated here.
[0134] The explanation of steps S501-S503 can be found in the relevant descriptions in any embodiment of this disclosure, and will not be repeated here.
[0135] Step S504: For any target augmented sample in an augmented sample pair, determine the loss function of the target augmented sample based on the similarity between the feature vectors of the two augmented samples in the augmented sample pair, the similarity between the feature vector of the target augmented sample and the feature vector of at least one augmented sample in the augmented sample pair corresponding to the training sample (excluding the target augmented sample), and the set temperature parameter.
[0136] The temperature parameter is set to control the sharpness of the similarity distribution between the feature vectors of any two enhanced samples.
[0137] As an example, the normal sample set is D = {x_1, x_2, ..., x_N}. A batch of data {x_1, x_2, ..., x_B} of size B (B≤N) is randomly sampled from the normal sample set D as training samples. Then, for the augmented sample pairs (x_{k_i}, x_{k_j}) (1≤K≤B) corresponding to the training samples {x_1, x_2, ..., x_B}, the loss function for x_{k_i} can be determined using the following formula:
[0138] in,
[0139] in, Indicates the first Enhanced samples corresponding to normal samples loss function, Indicates the first Enhanced samples corresponding to normal samples eigenvectors, Indicates the first Enhanced samples corresponding to normal samples eigenvectors, This indicates the set temperature coefficient.
[0140] Similarly, the first Enhanced samples corresponding to normal samples The formula for calculating the loss function is as follows:
[0141] in,
[0142] When calculating the above loss function, the summation term in the denominator iterates through the augmented sample pairs corresponding to the training samples, excluding... All augmented samples other than those in the denominator summation (including the numerator), therefore, the loss function is the normalized temperature-scaled cross-entropy loss.
[0143] Step S505: Train the feature extraction model based on the loss function of the augmented sample in the augmented sample pair corresponding to the training sample, and obtain the trained feature extraction model.
[0144] In some embodiments, the average loss function can be determined based on the loss function of the augmented samples in the augmented sample pair corresponding to the training samples; the feature extraction model is trained based on the average loss function to obtain the trained feature extraction model.
[0145] As an example, the loss function of each augmented sample can be averaged to obtain the average loss function. Then, the loss value is calculated and minimized using the backpropagation algorithm and gradient descent optimizer, iteratively updating the model parameters of the feature extraction model. Essentially, this process brings all normal samples closer together in the projection space while pushing them further away from other normal samples within the batch (which are essentially augmented samples of other normal samples), thus forcing the feature vectors of all normal samples to cluster within a compact region.
[0146] Among them, training the feature extraction model based on the average loss function can make full use of the differentiated performance of different augmented samples during the training process, integrate the valuable information contained in each augmented sample, and enable the feature extraction model to learn data features from a more comprehensive and representative perspective, thereby improving the feature extraction model's ability to capture the essential features of the data and its generalization performance.
[0147] The model training method provided in this disclosure sets a temperature parameter to control the sharpness of the similarity distribution between any two augmented samples, which can avoid the similarity distribution being too concentrated or dispersed. This allows the loss function determined by the set temperature parameter to more accurately reflect the differences and correlations between sample features. Then, based on the determined loss function, the feature extraction model is trained, which can guide the feature extraction model to learn the essential features of the samples more accurately and efficiently, thereby improving the feature extraction model's ability to distinguish between different sample features.
[0148] To clearly illustrate the above embodiments, examples are given below.
[0149] Figure 6(a) is a schematic diagram of the principle of an anomaly identification method provided in an embodiment of this disclosure.
[0150] As shown in Figure 6(a), this anomaly detection method includes two stages: I. Offline Training Phase The goal of this stage is to obtain a feature extraction model that can accurately internalize the concept of "compliance" and to determine the geometric parameters required for anomaly identification.
[0151] Step S601: Determine the normal sample set.
[0152] Domain experts manually select a set of N (N≥1) samples based on currently effective and clearly defined anomaly detection strategies, forming a normal sample set D = {x_1, x_2, ..., x_N}. Each sample x_i in this set is considered a model of "compliance" under the anomaly detection strategy. The definition of this set is dynamic and can be updated as the anomaly detection strategy evolves.
[0153] Step S602: Train the feature extraction model.
[0154] Train a feature extraction model whose encoder can map the essential features of compliance to a region of a high-dimensional feature space.
[0155] The feature extraction model can adopt any deep vision network architecture, such as ResNet-50, VisionTransformer, etc., and replace its final classification head with a projection head. The projection head consists of one or more fully connected layers, which are used to further map the features extracted by the encoder to a lower-dimensional projection space that is more suitable for similarity comparison.
[0156] The training process includes: 1. Training data preparation A batch of data {x_1, x_2, ..., x_B} of size B (B≤N) is randomly sampled from the normal sample set D as training samples. For each training sample x_k (1≤K≤B), an augmented view x_{k_i} and x_{k_j} are generated through two independent random data augmentation processes.
[0157] 2. The feature extraction model is trained using a contrastive learning loss function. All 2B augmented samples in the batch are input into the feature extraction model to obtain their L2 normalized feature vectors (the feature extraction model further maps the features extracted by the encoder to the same feature space through the projection head). Normalized temperature-scaled cross-entropy loss is used as the loss function. For the augmented sample pairs (xki}, xkj} (1≤K≤B) corresponding to the training samples {x1, x2, ..., xB}, the loss function for xki can be determined using the following formula:
[0158] in,
[0159] in, Indicates the first Enhanced samples corresponding to normal samples loss function, Indicates the first Enhanced samples corresponding to normal samples eigenvectors, Indicates the first Enhanced samples corresponding to normal samples eigenvectors, This indicates the set temperature coefficient.
[0160] Similarly, the first Enhanced samples corresponding to normal samples The formula for calculating the loss function is as follows:
[0161] in,
[0162] In the calculation of the above loss function, the summation term in the denominator iterates through the augmented sample pairs corresponding to the training samples, excluding... All augmented samples other than those in the denominator summation (including the numerator), therefore, the loss function is the normalized temperature-scaled cross-entropy loss.
[0163] 3. Model Optimization The final loss is the average of the loss functions of all augmented samples. This loss is minimized using the backpropagation algorithm and gradient descent optimizer, iteratively updating the model parameters of the feature extraction model. Essentially, this process brings all normal samples closer together in the projection space while pushing them further away from other normal samples within the batch (which are essentially augmented versions of those normal samples), thus forcing the feature vectors of all normal samples to cluster within a compact region.
[0164] Step S603: Determine the first central feature vector and the first anomaly distance threshold.
[0165] After obtaining the trained feature extraction model, the feature vectors of all normal samples in the normal sample set D are determined using the trained feature extraction model.
[0166] Based on the feature vector of at least one normal sample in the normal sample set D, a first central characteristic vector of at least one normal sample is determined. The first central characteristic vector is used to indicate the average center of at least one normal sample in the corresponding feature space.
[0167] For example, the first central characteristic vector of at least one normal sample can be determined using the following formula. :
[0168] in, Indicates the number of normal samples. , Indicates the first The feature vector of a normal sample.
[0169] The first anomaly distance threshold is determined based on the distance between the feature vector of at least one normal sample in the normal sample set D and the first central feature vector.
[0170] For example, the average distance can be determined using the following formula based on the distances between the feature vectors of all normal samples in the normal sample set D and the feature vector of the first center. and distance standard deviation :
[0171]
[0172] in, Indicates the first The distance between each normal sample and the first central feature vector This allows us to determine the first anomaly distance threshold. ,in, This represents the scaling factor, determined based on the target false alarm rate, for example... It can be a scaling factor set according to the maximum tolerable false alarm rate based on task requirements (e.g.) =2). The effective radius of the "normal hypersphere" is defined.
[0173] II. Online Identification Stage This stage utilizes the trained feature extraction model obtained from offline training, along with relevant parameters (first central feature vector and first anomaly distance threshold), to perform real-time and automated anomaly identification on the data to be identified during task execution.
[0174] Step S604: Determine the feature vector of the data to be identified. For any data to be identified The normalized feature vector is obtained by inputting it into the trained feature extraction model. .
[0175] Step S605: Determine the distance between the feature vector of the data to be identified and the first central feature vector. Calculate the feature vector of the data to be identified The first central eigenvector calculated in the offline phase Distance between If using cosine distance: .
[0176] Step S606: Anomaly identification based on distance The distance between the feature vector of the data to be identified and the first central feature vector. The first anomaly distance threshold calculated in the offline phase Compare them.
[0177] like Then the data to be identified is determined. If a sample falls inside or onto the surface of a "normal hypersphere," it will be highly similar to a normal sample in the normal sample set, thus confirming the identity of the data to be identified. Normal. If Then the data to be identified is determined. If an anomaly is detected, it can be marked as a target category to indicate that it needs to be reviewed (such as manually), or, depending on the configuration, operations related to the data to be identified can be refused, or, depending on the configuration, modification prompts for the data to be identified can be generated.
[0178] The above-mentioned anomaly identification method can be applied to any field that requires anomaly identification, such as social media platforms, e-commerce platforms, AIGC (Artificial Intelligence Generated Content) platforms, and other products and projects that require refined and strategic content control.
[0179] As an example, Figure 6(b) is a schematic diagram of the application of an anomaly identification method provided in an embodiment of this disclosure. In the AIGC platform shown in Figure 6(b), the user inputs a prompt word, and the generation model generates content based on the prompt word input by the user. Then, the content review model can use the above-mentioned anomaly identification method to identify anomalies in the content generated by the generation model. If it passes, the content generated by the generation model is returned to the user. If it fails, it is marked as a target type, or a target operation is performed. Afterwards, if it is marked as a target type, a review is performed; if a target operation is performed, a modification prompt can be generated to prompt the user to modify the input content. At this time, the user can resubmit or abandon the submission.
[0180] Figure 7 This is a schematic diagram of an anomaly identification device provided in an embodiment of this disclosure.
[0181] like Figure 7 As shown, the anomaly identification device 700 of this embodiment includes a first feature extraction module 701, a first determination module 702, a second feature extraction module 703, and a second determination module 704.
[0182] The first feature extraction module 701 is used to extract features from at least one normal sample in the normal sample set using the trained feature extraction model, so as to obtain the feature vector of at least one normal sample. The first determining module 702 is used to determine a first central feature vector of at least one normal sample and a first anomaly distance threshold based on the feature vector of at least one normal sample. The second feature extraction module 703 is used to extract features from the data to be identified using the trained feature extraction model, and obtain the feature vector of the data to be identified. The second determining module 704 is used to determine whether the data to be identified is abnormal based on the distance between the feature vector of the data to be identified and the first central feature vector, and the first abnormal distance threshold.
[0183] In one embodiment of this disclosure, the first determining module 702 includes: a first determining unit, configured to determine a first central feature vector of at least one normal sample based on the feature vector of at least one normal sample; wherein the first central feature vector is used to indicate the average center of at least one normal sample in a corresponding feature space; a second determining unit, configured to determine the distance between the feature vector of the normal sample and the first central feature vector for any normal sample among the at least one normal sample; and a third determining unit, configured to determine a first abnormal distance threshold based on the distance between the feature vector of the at least one normal sample and the first central feature vector.
[0184] In one embodiment of this disclosure, the third determining unit is further configured to: determine an average distance and a distance standard deviation based on the distance between the feature vector of at least one normal sample and the first central feature vector; and determine a first abnormal distance threshold based on the average distance, the distance standard deviation, and a scaling factor; wherein the scaling factor is determined based on the target false alarm rate.
[0185] In one embodiment of this disclosure, the third determining unit is further configured to: scale the distance standard deviation using a scaling factor to obtain the target distance; wherein the scaling factor is used to indicate the scaling degree of the scaling process; and determine the sum of the average distance and the target distance as a first abnormal distance threshold.
[0186] In one embodiment of this disclosure, a first abnormal distance threshold is used to indicate the maximum value of the distance between the feature vector of a normal sample and the first central feature vector; the second determining module 704 is further used to: compare the distance between the feature vector of the data to be identified and the first central feature vector with the first abnormal distance threshold; and determine that the data to be identified is abnormal in response to the distance between the feature vector of the data to be identified and the first central feature vector being greater than the first abnormal distance threshold.
[0187] In one embodiment of this disclosure, the apparatus further includes: a third determining module, configured to determine the cosine similarity between the feature vector of the data to be identified and the first central feature vector; and a fourth determining module, configured to determine the distance between the feature vector of the data to be identified and the first central feature vector based on the cosine similarity between the feature vector of the data to be identified and the first central feature vector.
[0188] In one embodiment of this disclosure, the apparatus further includes: a first processing module, configured to, in response to determining that the data to be identified is abnormal, mark the data to be identified as a target category, or perform a target operation on the data to be identified; wherein the target category is used to indicate that the data to be identified needs to be reviewed; the target operation includes refusing to perform related operations on the data to be identified, and / or generating a modification prompt for the data to be identified.
[0189] In one embodiment of this disclosure, the normal sample set is determined by a domain expert based on an effective anomaly detection strategy; the apparatus further includes: an acquisition module, configured to acquire an updated normal sample set in response to an anomaly detection strategy update; a fifth determination module, configured to determine a feature vector of at least one updated normal sample in the updated normal sample set using a trained feature extraction model; a sixth determination module, configured to determine a second central feature vector of at least one updated normal sample and a second anomaly distance threshold based on the feature vector of at least one updated normal sample; and an update module, configured to update a first central feature vector using the second central feature vector and update a first anomaly distance threshold using the second anomaly distance threshold.
[0190] In one embodiment of this disclosure, the feature extraction model includes an encoder and a projection head. The encoder is used to extract features from the model input, and the projection head is used to map the features extracted by the encoder to a target projection space. The dimension of the vectors in the target projection space is lower than the dimension of the features extracted by the encoder.
[0191] The anomaly detection device provided in this disclosure can determine whether the data to be identified is abnormal using only normal samples, reducing the requirements for obtaining sample data and improving the anomaly detection effect in scenarios where the anomaly detection strategy is sensitive and abnormal samples are scarce. Moreover, the anomaly detection criteria (first central feature vector and first anomaly distance threshold) are not predefined simple rules, but are dynamically learned from the normal sample set, which increases the difficulty for attackers to construct adversarial examples, making it difficult for attackers to construct adversarial examples through reverse engineering. In addition, when the anomaly detection strategy is adjusted, only the normal sample set needs to be updated and the feature extraction model needs to be fine-tuned to quickly deploy the new anomaly detection strategy, achieving efficient and convenient strategy updates.
[0192] Figure 8This is a schematic diagram of the structure of a model training device provided in an embodiment of this disclosure.
[0193] like Figure 8 As shown, the model training device 800 of this embodiment includes a selection module 801, a second processing module 802, an input module 803, and a training module 804.
[0194] The selection module 801 is used to select training samples from the normal sample set; The second processing module 802 is used to perform data augmentation processing on the training samples to obtain augmented sample pairs corresponding to the training samples. The input module 803 is used to input the augmented sample pairs corresponding to the training samples into the feature extraction model to obtain the feature vectors of the augmented samples in the augmented sample pairs. Training module 804 is used to train the feature extraction model based on the similarity between the feature vectors of the augmented samples in the augmented sample pair, resulting in the trained feature extraction model.
[0195] In one embodiment of this disclosure, the training module 804 is further configured to: for any target augmented sample in an augmented sample pair, determine a loss function for the target augmented sample based on the similarity between the feature vectors of the two augmented samples in the augmented sample pair, the similarity between the feature vector of the target augmented sample and the feature vector of at least one augmented sample other than the target augmented sample in the augmented sample pair corresponding to the training sample, and a set temperature parameter; wherein the set temperature parameter is used to control the sharpness of the similarity distribution between the feature vectors of any two augmented samples; and train a feature extraction model based on the loss function of the augmented samples in the augmented sample pair corresponding to the training sample to obtain a trained feature extraction model.
[0196] In one embodiment of this disclosure, the training module 804 is further configured to: determine an average loss function based on the loss function of the augmented samples in the augmented sample pair corresponding to the training samples; and train a feature extraction model based on the average loss function to obtain a trained feature extraction model.
[0197] In one embodiment of this disclosure, the feature extraction model includes an encoder and a projection head. The encoder is used to extract features from the model input, and the projection head is used to map the features extracted by the encoder to a target projection space. The dimension of the vectors in the target projection space is lower than the dimension of the features extracted by the encoder.
[0198] The model training apparatus provided in this disclosure generates augmented sample pairs through data augmentation processing, which enhances the diversity of data, helps the feature extraction model learn more robust features, and avoids overfitting. By training the feature extraction model based on the similarity between multiple augmented samples in the augmented sample pair, the feature extraction model can be trained to extract similar features for different augmented versions of the same original sample. Furthermore, only normal samples are used as training samples during the training process, reducing the dependence on labeled data. This allows the feature extraction model to learn more discriminative and robust feature representations even in scenarios where anomaly detection strategies are sensitive and anomaly samples are scarce.
[0199] The acquisition, storage, and application of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0200] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0201] Figure 9 A schematic block diagram of an example electronic device 900 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0202] like Figure 9 As shown, device 900 includes a computing unit 901, which can perform various appropriate actions and processes based on computer programs / instructions stored in read-only memory (ROM) 902 or loaded into random access memory (RAM) 903 from storage unit 908. RAM 903 may also store various programs and data required for the operation of device 900. The computing unit 901, ROM 902, and RAM 903 are interconnected via bus 904. Input / output (I / O) interface 905 is also connected to bus 904.
[0203] Multiple components in device 900 are connected to I / O interface 905, including: input units 906 such as keyboard, mouse, etc.; output units 907 such as various types of displays, speakers, etc.; storage units 908 such as disks, optical disks, etc.; and communication units 909 such as network interface cards, modems, wireless transceivers, etc. Communication unit 909 allows device 900 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0204] The computing unit 901 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 901 performs the various methods and processes described above, such as anomaly detection methods or model training methods. For example, in some embodiments, the anomaly detection method or model training method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 908. In some embodiments, part or all of the computer program / instructions may be loaded and / or installed on device 900 via ROM 902 and / or communication unit 909. When the computer program / instructions are loaded into RAM 903 and executed by the computing unit 901, one or more steps of the anomaly detection method or model training method described above may be performed. Alternatively, in other embodiments, the computing unit 901 may be configured to perform anomaly detection or model training methods by any other suitable means (e.g., by means of firmware).
[0205] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs / instructions that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transferring data and instructions to the storage system, the at least one input device, and the at least one output device.
[0206] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0207] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0208] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0209] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), the Internet, and blockchain networks.
[0210] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. The client-server relationship is created by computer programs / instructions running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0211] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in the disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this document does not impose any restrictions.
[0212] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. An anomaly identification method, the method comprising: Using the trained feature extraction model, feature extraction is performed on at least one normal sample in the normal sample set to obtain the feature vector of the at least one normal sample. Based on the feature vectors of the at least one normal sample, determine the first central feature vector of the at least one normal sample and the first anomaly distance threshold; Using the trained feature extraction model, feature extraction is performed on the data to be identified to obtain the feature vector of the data to be identified. Based on the distance between the feature vector of the data to be identified and the first central feature vector, and the first abnormal distance threshold, it is determined whether the data to be identified is abnormal.
2. The method according to claim 1, wherein, The step of determining the first center feature vector and the first anomaly distance threshold of the at least one normal sample based on the feature vector of the at least one normal sample includes: Based on the feature vectors of the at least one normal sample, a first central feature vector of the at least one normal sample is determined; wherein, the first central feature vector is used to indicate the average center of the at least one normal sample in the corresponding feature space; For any one of the at least one normal sample, determine the distance between the feature vector of the normal sample and the first central feature vector; The first abnormal distance threshold is determined based on the distance between the feature vector of the at least one normal sample and the first central feature vector.
3. The method according to claim 2, wherein, Determining the first anomaly distance threshold based on the distance between the feature vector of the at least one normal sample and the first central feature vector includes: The average distance and the standard deviation of the distance are determined based on the distance between the feature vector of the at least one normal sample and the first central feature vector; The first abnormal distance threshold is determined based on the average distance, the standard deviation of the distance, and the scaling factor; wherein the scaling factor is determined based on the target false alarm rate.
4. The method according to claim 3, wherein, Determining the first abnormal distance threshold based on the average distance, the standard deviation of the distance, and the scaling factor includes: The target distance is obtained by scaling the distance standard deviation using the scaling factor; wherein the scaling factor indicates the degree of scaling in the scaling process. The sum of the average distance and the target distance is determined as the first abnormal distance threshold.
5. The method according to claim 1, wherein, The first anomaly distance threshold is used to indicate the maximum value of the distance between the feature vector of a normal sample and the first central feature vector; determining whether the data to be identified is abnormal based on the distance between the feature vector of the data to be identified and the first central feature vector, and the first anomaly distance threshold, includes: The distance between the feature vector of the data to be identified and the first central feature vector is compared with the first anomaly distance threshold. In response to the distance between the feature vector of the data to be identified and the first central feature vector being greater than the first abnormal distance threshold, the data to be identified is determined to be abnormal.
6. The method according to claim 1, wherein, The method further includes: Determine the cosine similarity between the feature vector of the data to be identified and the first central feature vector; The distance between the feature vector of the data to be identified and the first central feature vector is determined based on the cosine similarity between the feature vector of the data to be identified and the first central feature vector.
7. The method according to claim 1, wherein, The method further includes: In response to determining that the data to be identified is abnormal, the data to be identified is marked as a target category, or a target operation is performed on the data to be identified; The target category is used to indicate that the data to be identified needs to be reviewed. The target operation includes refusing to perform operations related to the data to be identified, and / or generating a modification prompt for the data to be identified.
8. The method according to claim 1, wherein, The set of normal samples is determined by domain experts based on an effective anomaly detection strategy; the method further includes: In response to the update of the anomaly detection strategy, obtain the updated set of normal samples; Using the trained feature extraction model, determine the feature vector of at least one updated normal sample in the updated normal sample set; Based on the feature vector of the at least one updated normal sample, determine the second center feature vector of the at least one updated normal sample, and the second anomaly distance threshold; The first central feature vector is updated using the second central feature vector, and the first anomaly distance threshold is updated using the second anomaly distance threshold.
9. The method according to any one of claims 1-8, wherein, The feature extraction model includes an encoder and a projection head. The encoder is used to extract features from the model input, and the projection head is used to map the features extracted by the encoder to a target projection space. The dimension of the vector in the target projection space is lower than the dimension of the features extracted by the encoder.
10. A model training method, the method comprising: Select training samples from the normal sample set; The training samples are subjected to data augmentation processing to obtain augmented sample pairs corresponding to the training samples; The augmented sample pairs corresponding to the training samples are input into the feature extraction model to obtain the feature vectors of the augmented samples in the augmented sample pairs; Based on the similarity between the feature vectors of the enhanced samples in the enhanced sample pair, the feature extraction model is trained to obtain the trained feature extraction model.
11. The method according to claim 10, wherein, The step of training the feature extraction model based on the similarity between the feature vectors of the enhanced samples in the enhanced sample pair to obtain the trained feature extraction model includes: For any target augmented sample in any augmented sample pair, the loss function of the target augmented sample is determined based on the similarity between the feature vectors of the two augmented samples in the augmented sample pair, the similarity between the feature vector of the target augmented sample and the feature vector of at least one augmented sample in the augmented sample pair corresponding to the training sample (excluding the target augmented sample), and a set temperature parameter; wherein, the set temperature parameter is used to control the sharpness of the similarity distribution between the feature vectors of any two augmented samples; The feature extraction model is trained based on the loss function of the augmented sample in the augmented sample pair corresponding to the training sample, and the trained feature extraction model is obtained.
12. The method according to claim 11, wherein, The step of training the feature extraction model based on the loss function of the augmented samples in the augmented sample pair corresponding to the training samples, to obtain the trained feature extraction model, includes: The average loss function is determined based on the loss function of the augmented samples in the augmented sample pair corresponding to the training samples; The feature extraction model is trained based on the average loss function to obtain the trained feature extraction model.
13. The method according to any one of claims 10-12, wherein, The feature extraction model includes an encoder and a projection head. The encoder is used to extract features from the model input, and the projection head is used to map the features extracted by the encoder to a target projection space. The dimension of the vector in the target projection space is lower than the dimension of the features extracted by the encoder.
14. An anomaly detection device, the device comprising: The first feature extraction module is used to extract features from at least one normal sample in the normal sample set using a trained feature extraction model, and obtain the feature vector of the at least one normal sample. The first determining module is used to determine a first central feature vector and a first anomaly distance threshold of the at least one normal sample based on the feature vector of the at least one normal sample. The second feature extraction module is used to extract features from the data to be identified using the trained feature extraction model, and obtain the feature vector of the data to be identified. The second determining module is used to determine whether the data to be identified is abnormal based on the distance between the feature vector of the data to be identified and the first central feature vector, and the first abnormal distance threshold.
15. A model training apparatus, the apparatus comprising: The selection module is used to select training samples from the normal sample set; The second processing module is used to perform data augmentation processing on the training samples to obtain augmented sample pairs corresponding to the training samples. The input module is used to input the augmented sample pairs corresponding to the training samples into the feature extraction model to obtain the feature vectors of the augmented samples in the augmented sample pairs; The training module is used to train the feature extraction model based on the similarity between the feature vectors of the enhanced samples in the enhanced sample pair, so as to obtain the trained feature extraction model.
16. An electronic device comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the method as described in any one of claims 1-9, or to perform the method as described in any one of claims 10-13.
17. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method as described in any one of claims 1-9, or to perform the method as described in any one of claims 10-13.
18. A computer program product comprising a computer program / instructions, wherein, When the computer program / instructions are executed by the processor, they implement the method as described in any one of claims 1-9, or the method as described in any one of claims 10-13.