Out-of-distribution data detection method and system based on attention mechanism and adversarial enhancement training

By using an attention mechanism and adversarial enhancement training method, pseudo-out-of-distribution samples are generated and feature attention modules and discriminators are constructed. This solves the problem of deep neural networks recognizing semantic and covariate out-of-distribution samples in open environments, improves the robustness and security of the model, and is applicable to complex environments such as autonomous driving, medical image analysis, and intelligent transportation.

CN122176439APending Publication Date: 2026-06-09CHONGQING UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHONGQING UNIV
Filing Date
2026-03-09
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

When faced with out-of-distribution samples in open environments, existing deep neural networks struggle to simultaneously identify both semantic out-of-distribution samples and covariate out-of-distribution samples. This leads to overconfident and erroneous predictions in practical applications, impacting system reliability and security.

Method used

By using an attention mechanism and adversarial enhancement training method, a pseudo-out-of-distribution sample set is generated, and a covariate-semantic feature attention module and an in-distribution-out-of-distribution discriminator are constructed. Adversarial enhancement training is then used to optimize the feature attention module and discriminator, thereby achieving unified recognition of semantic and covariate out-of-distribution samples.

Benefits of technology

Without altering the original model structure, it can simultaneously identify multiple types of out-of-distribution samples, improving the model's robustness and security in complex environments, reducing dependence on real out-of-distribution data, and exhibiting strong adaptability and ease of integration into existing artificial intelligence systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122176439A_ABST
    Figure CN122176439A_ABST
Patent Text Reader

Abstract

This invention relates to an out-of-distribution data detection method and system based on attention mechanisms and adversarial reinforcement training, belonging to the field of artificial intelligence technology. The method specifically includes the following steps: S1, generating a pseudo-out-of-distribution sample set by applying randomly combined covariate perturbations based on in-distribution training samples; S2, constructing a detection model including a covariate-semantic feature attention module and an in-distribution-out-of-distribution discriminator; S3, jointly optimizing the feature attention module and discriminator using the pseudo-out-of-distribution sample set and the in-distribution sample set through adversarial reinforcement training; S4, for the sample to be detected, extracting weighted features using the trained model and performing discrimination, outputting the detection result of whether it is an out-of-distribution sample. This method and system can simultaneously identify semantic out-of-distribution samples and covariate out-of-distribution samples, improving the robustness and security of artificial intelligence systems in complex and open environments.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of artificial intelligence technology and relates to an out-of-distribution data detection method and system based on attention mechanism and adversarial enhancement training. Background Technology

[0002] With the continuous evolution of computer architecture and high-performance computing platforms, artificial intelligence (AI) technology is developing at an unprecedented pace. Among these advancements, deep neural networks, with their powerful feature modeling capabilities, have become a core method in current AI research and applications, achieving breakthroughs in numerous practical scenarios. For example, in autonomous driving systems, deep neural network models undertake crucial tasks of environmental perception and decision support; in high-risk applications such as medical image analysis, their diagnostic capabilities have also demonstrated significant value. Overall, the widespread deployment of deep neural networks is not only improving productivity and intelligence levels but is also profoundly changing the way society operates and human lifestyles.

[0003] However, the design and training of existing deep neural networks are usually based on an implicit assumption: that the data distribution encountered during training can completely cover the sample distribution that may be encountered during testing. Under this closed-world assumption, training data and test data are considered to follow the same probability distribution, and the model can therefore maintain high prediction accuracy and stable generalization performance during testing. Although this assumption holds true in controlled environments, it is often difficult to meet in real-world applications. When the model is deployed to an open environment, the system will inevitably encounter novel samples or unknown categories that have never appeared during training, namely, out-of-distribution (OOD) samples. Depending on their cause, OOD samples can usually be further divided into two categories: one is semantic-shift OOD, whose semantic category is completely different from the in-distribution samples during training; the other is covariate-shift OOD, whose semantic category still belongs to the in-distribution category, but due to factors such as weather changes, differences in lighting conditions, changes in imaging equipment, or noise disturbances, the overall input distribution is shifted. These two types of out-of-distribution (OOD) samples often coexist in real-world environments, posing a more severe challenge to the reliable deployment of models. However, numerous studies have shown that standard deep neural networks may still output highly confident but incorrect predictions when faced with such out-of-distribution inputs. This overconfidence not only weakens the reliability of model decisions but may even lead to serious consequences in security-sensitive scenarios. Therefore, enabling models to distinguish between in-distribution (ID) and out-of-distribution samples has become a key issue in current deep learning research.

[0004] To address this issue, existing research has primarily developed two technical approaches. One approach addresses the root cause, arguing that neural networks lack the ability to recognize out-of-distribution samples during training. Therefore, it introduces real out-of-distribution auxiliary data or synthesizes virtual OOD samples using specific strategies to participate in training, enabling the model to acquire a certain degree of OOD awareness while learning the discrimination task. The other approach takes a more lightweight approach, not modifying the original model's training process. Instead, it uses the trained model to design effective OOD detection scores and extracts distributional difference information from the model's output or intermediate representations, thereby achieving the identification of out-of-distribution samples. It should be noted that most existing OOD detection methods focus primarily on semantic OOD scenarios, assuming that OOD samples differ significantly from in-distribution data at the semantic level. However, these methods often struggle to effectively identify covariate OOD samples where the semantics remain unchanged and only the input distribution shifts. More realistically, in real-world open environments, semantic out-of-distribution and covariate distribution shifts are usually not independent but may occur simultaneously, making detection strategies designed for a single OOD type insufficient for practical applications. Therefore, how to address out-of-distribution risks at both the semantic and covariate levels without compromising the model's original discriminative capabilities remains a critical issue that urgently needs to be addressed. Summary of the Invention

[0005] In view of this, the purpose of this invention is to provide an out-of-distribution data detection method and system based on attention mechanism and adversarial enhancement training. This method and system can simultaneously identify semantic out-of-distribution samples and covariate out-of-distribution samples, which can improve the robustness and security of artificial intelligence systems in complex and open environments.

[0006] To achieve the above objectives, the present invention provides the following technical solution: An out-of-distribution data detection method based on attention mechanism and adversarial enhancement training, the method specifically includes the following steps: S1. Based on the in-distribution training samples, a pseudo-out-of-distribution sample set is generated by applying a random combination of covariate perturbations; S2. Construct a detection model that includes a covariate-semantic feature attention module and an in-distribution-out-distribution discriminator; S3. Using the pseudo-out-of-distribution sample set and the in-distribution sample set, jointly optimize the feature attention module and the discriminator through adversarial enhancement training; S4. For the sample to be detected, use the trained model to extract weighted features and make a judgment, and output the detection result of whether it is an out-of-distribution sample.

[0007] Furthermore, in step S1, the specific steps for generating the pseudo-distribution out-of-sample set include: S11. Define a set of class-independent covariate perturbation operators; S12. For each sample within the distribution, randomly select the perturbation combination length and the corresponding perturbation operator sequence; S13. Apply the perturbation operator sequence sequentially to generate corresponding pseudo-out-of-distribution samples.

[0008] Furthermore, the covariate perturbation includes at least one of the following: noise interference, blurring, color shift, contrast change, geometric deformation, or compression distortion.

[0009] Furthermore, in step S2, the covariate-semantic feature attention module specifically includes: S21, Channel Attention Submodule, is used to generate weights for each channel of the feature map; S22, Spatial Attention Submodule, used to generate weights for each spatial location of the feature map; S23. Based on the channel weights and spatial weights, the original features are reweighted to obtain feature representations that are sensitive to covariate perturbations or semantic changes.

[0010] Furthermore, the feature attention module is applied to the shallow and deep features of the convolutional neural network, respectively, where the shallow features are used to capture covariate shifts and the deep features are used to capture semantic shifts.

[0011] Furthermore, in step S3, the adversarial enhancement training is optimized using the following loss function: in Collect all trainable parameters and perform unified optimization.

[0012] Furthermore, the discriminator receives a feature vector that is concatenated and projected from shallow weighted features and deep weighted features, and outputs the probability that a sample belongs to the distribution or is outside the distribution.

[0013] Furthermore, the method trains the model without altering its core structure and maintains its original classification performance.

[0014] This invention also provides an out-of-distribution data detection system based on attention mechanism and adversarial enhancement training. The system includes: a pseudo-sample generation module, a feature extraction and attention module, a discrimination module, and a training module. The pseudo-sample generation module is used to generate pseudo-out-of-distribution samples based on in-distribution samples. The feature extraction and attention module is used to extract shallow and deep features from input samples and perform adaptive weighting. The discrimination module is used to determine whether a sample is an out-of-distribution sample based on the weighted features. The training module is used to optimize the attention module and the discrimination module through adversarial enhancement training.

[0015] The system is integrated into the intelligent perception module of autonomous driving, medical image analysis, smart transportation, or unmanned systems to improve the robustness and safety of the model in open environments.

[0016] The beneficial effects of this invention are as follows: Compared with existing OOD detection technologies, this invention has the following significant advantages: 1) Simultaneously covers multiple types of distributed outdoor scenes This invention can simultaneously detect semantic OOD samples and covariate OOD samples within a unified framework, effectively overcoming the shortcomings of existing methods that mainly target scenarios outside the semantic distribution and are difficult to cope with covariate distribution shifts. It is more in line with the application needs of multiple out-of-distribution risks coexisting in real open environments.

[0017] 2) No need to rely on auxiliary datasets outside the real distribution This invention employs a pseudo-OOD data generation strategy based on ID sample scrambling, enabling model training without introducing real OOD datasets. This reduces the cost of relying on data acquisition and annotation, and improves the versatility and deployability of the method in real-world scenarios.

[0018] 3) It does not damage the original model's discrimination ability and has strong adaptability. This invention introduces a covariate-semantic feature attention and discrimination module without changing the original model's backbone structure and classification performance. It can be flexibly combined with various mainstream deep neural network models, is easy to integrate into existing artificial intelligence systems, and has good scalability and engineering practical value.

[0019] Other advantages, objectives, and features of the invention will be set forth in part in the description which follows, and in part will be apparent to those skilled in the art from the following examination, or may be learned from practice of the invention. The objectives and other advantages of the invention can be realized and obtained through the following description. Attached Figure Description

[0020] To make the objectives, technical solutions, and advantages of the present invention clearer, the preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings, wherein: Figure 1 This is a flowchart illustrating the overall training process of the method of the present invention. Detailed Implementation

[0021] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Unless otherwise specified, the following embodiments and features can be combined with each other.

[0022] The accompanying drawings are for illustrative purposes only and are schematic diagrams, not actual pictures. They should not be construed as limiting the invention. To better illustrate the embodiments of the invention, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions. It is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.

[0023] In the accompanying drawings of the embodiments of the present invention, the same or similar reference numerals correspond to the same or similar components. In the description of the present invention, it should be understood that if terms such as "upper," "lower," "left," "right," "front," and "rear" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, they are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, the terms used to describe positional relationships in the drawings are only for illustrative purposes and should not be construed as limiting the present invention. For those skilled in the art, the specific meaning of the above terms can be understood according to the specific circumstances.

[0024] This invention proposes a detection method capable of simultaneously identifying out-of-distribution samples of semantics and out-of-distribution samples of covariates, aiming to improve the robustness and security of artificial intelligence systems in complex and open environments. Its core motivation stems from the following key understanding: In typical convolutional neural networks, features at different levels have significant functional divisions. Shallow layers primarily represent low-level visual attributes of images, such as texture, color, and local structural information, while deeper features reflect higher-level semantic information and category discrimination cues. These two types of features have complementary roles in out-of-distribution detection: shallow features are more sensitive to covariate perturbations such as changes in illumination and imaging conditions, while deep features help distinguish unknown categories at the semantic level.

[0025] This scheme first designs a pseudo-out-of-distribution data generation strategy based on scrambling in-distribution samples. Specifically, by randomly superimposing one or more common covariate perturbations (such as illumination changes, noise interference, blurring, or color shifts) onto in-distribution images, different levels of distribution shift samples are generated under controlled perturbation intensity and combination. Mild or single perturbations mainly introduce covariate distribution shifts, while multiple or strong perturbations may disrupt the original semantic structure, allowing the samples to naturally transition into semantically out-of-distribution samples (when the perturbation intensity is too large or two or more perturbations are superimposed, making it difficult to distinguish the semantic subject of the image, it is considered that a semantic shift has occurred). This strategy does not rely on real out-of-distribution data and can provide the model with diverse distribution shift scenarios during the training phase. Based on this, the generated pseudo-out-of-distribution samples are introduced into the adversarial enhancement training process to jointly optimize the covariate-semantic feature attention module and the in-distribution-out-of-distribution discriminator. The feature attention module is trained to adaptively extract key information regions that differ significantly under covariate perturbations or semantic changes from shallow and deep network features, thereby forming feature representations with discriminative ability against different types of out-of-distribution factors. Subsequently, these weighted features are input into the in-distribution-out-distribution discriminator to output the final detection result, achieving unified recognition of semantic out-of-distribution samples and covariate out-of-distribution samples.

[0026] Figure 1 The overall training flowchart of the method of the present invention is shown below. The specific scheme of the present invention is as follows: 1. A pseudo-OOD data generation strategy based on ID sample scrambling Set the ID training set as The set of covariate perturbation operators that are independent of category labels is ,in Indicates the perturbation operator. This represents the total number of perturbation operators in the set. Each perturbation operator applies a distribution shift to the sample in pixel space, such as noise or blur perturbation, color and contrast changes, compression distortion, and geometric jitter. These perturbations significantly alter the distribution characteristics of the sample without depending on class information. For any ID sample Randomly sample the length of a perturbation combination: And from the set of perturbation operators defined above. Randomly select a non-repeating and ordered index sequence: Based on this, a perturbation generation operator is constructed. And generate corresponding pseudo-OOD samples. : By applying the above random perturbation combination operation to all samples in the ID training set, a pseudo-OOD dataset is finally constructed. , means as follows: 2. Covariate-Semantic Feature Attention Module Given an input image It is processed by a convolutional neural network feature extractor. After encoding, multi-layer feature representations are obtained. Assume... Depend on The image is composed of several convolutional layers. The feature representations in the first and last layers are denoted as follows: and Based on the first layer of features For example, this scheme introduces a feature attention module to adaptively reweight features. This attention module consists of a channel attention submodule. Spatial attention submodule This is composed of modules designed to adaptively mine key information regions that differ significantly under changes in covariate perturbations. Specifically, the channel attention module and the spatial attention module generate corresponding weight tensors: in, Represents the number of feature channels, and These represent the height and width of the feature map, respectively. These are learnable parameters. Based on the aforementioned channel and spatial attention weights, the original features are reweighted to obtain a feature representation that is more sensitive to covariate perturbations: in This indicates element-wise multiplication. Similarly, following the steps above, we can obtain feature representations that are more sensitive to semantic perturbations. The channel attention module adopts a dual-branch parallel structure. The two branches are a global average pooling branch and a global max pooling branch, sharing a common structure. The two-layer convolutional network reduces the dimensionality of the channels by a reduction factor in the first layer, and restores the number of channels to the original dimension in the second layer. The outputs of the two branches are element-wise summed and then multiplied by the sigmoid function to generate channel attention weights. These weights are then multiplied by the original feature map channel-wise to achieve adaptive weighting of important channels. The spatial attention module adopts a single-branch structure. First, average pooling and max pooling are performed along the channel dimension to obtain two spatial description maps. These maps are then concatenated along the channel dimension and then processed... Structural generative spatial attention weights, where The kernel size is multiplied position-by-position with the original feature map to achieve adaptive focusing on key spatial regions.

[0027] 3. Increased resistance training After obtaining the key feature map, the mapping operator Align their dimensions and input them into the ID-OOD discriminator. In the process, the final classification result is obtained: in For the sigmod function, The temperature parameter, set to 2, is used to adjust the smoothness of the discriminator output distribution in the Sigmoid function. By scaling the logits, the steepness of the output probability can be controlled, thereby enhancing the stability and discriminative power of ID-OOD discrimination. In the specific implementation, It is usually set as a hyperparameter or tuned using a validation set. During the training phase, a fixed temperature strategy (such as...) can be used. To ensure the stability of the training process, temperature scaling can be used to post-process logits during the inference phase, resulting in a more reliable confidence estimate. Alternatively, a learnable temperature parameter can be used to... As an optimizable parameter, the optimal temperature value is automatically determined by minimizing the negative log-likelihood loss on the validation set.

[0028] All the trainable parameters mentioned above are optimized using the following loss function: in All trainable parameters are collected and uniformly optimized. The ID-OOD discriminator adopts a lightweight structure of "global average pooling + multilayer perceptron", specifically including the following steps: 1. Spatial compression of the input feature map is performed through an adaptive global average pooling layer, aggregating the spatial response of each channel into a single global feature value; 2. The above global features are fed into a multilayer perceptron consisting of three fully connected layers for layer-by-layer mapping. The output dimensions of the first and second fully connected layers are set to half and a quarter of the number of input channels, respectively, with a minimum lower bound to ensure sufficient feature representation capability under different channel scales. After each fully connected layer, a ReLU activation function and a Dropout regularization layer are sequentially set to introduce nonlinearity and suppress overfitting. The third fully connected layer maps the features to a single scalar, serving as the discriminant logit value for that sample; 3. The logit value is temperature-scaled and then fed into a Sigmoid function to obtain the final OOD discriminant probability.

[0029] The discriminator trained using this method can be used in autonomous driving systems to help identify unknown OOD objects on the road, respond promptly, and alert for human intervention.

[0030] Out-of-Depth (OOD) detection and model robustness assurance are key research directions in the secure deployment of current artificial intelligence systems, with wide application needs in complex and open environments such as autonomous driving, medical image analysis, intelligent transportation, and unmanned systems. This invention proposes a unified detection method for both semantic OOD samples and covariate OOD samples, which can effectively improve the anomaly perception and risk identification capabilities of artificial intelligence models in variable environments. This provides crucial security assurance for intelligent perception and decision-making systems in the aforementioned application scenarios, reducing the risk of erroneous decisions caused by model distribution shifts. It is of great significance for promoting the practical application of highly reliable and secure artificial intelligence technologies in real-world scenarios.

[0031] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A method for detecting out-of-distribution data based on attention mechanisms and adversarial reinforcement training, characterized in that, The method specifically includes the following steps: S1. Based on the in-distribution training samples, a pseudo-out-of-distribution sample set is generated by applying a random combination of covariate perturbations; The method of applying randomly combined covariate perturbations includes: setting an ID training set and a set of class label-independent covariate perturbation operators. Each perturbation operator is used to apply a distribution shift to the sample in the pixel space, including noise or blur perturbation, color and contrast changes, compression distortion, and geometric jitter. For any ID sample, a perturbation combination length is randomly sampled, and a non-repeating and ordered index sequence is randomly selected from the perturbation set. Based on this, a perturbation generation operator is constructed, and a corresponding pseudo-OOD sample is generated. By applying the above random perturbation combination operation to all samples in the ID training set, a pseudo-OOD dataset is finally constructed. S2. Construct a detection model that includes a covariate-semantic feature attention module and an in-distribution-out-distribution discriminator; S3. Using the pseudo-out-of-distribution sample set and the in-distribution sample set, jointly optimize the feature attention module and the discriminator through adversarial enhancement training; S4. For the sample to be detected, use the trained model to extract weighted features and make a judgment, and output the detection result of whether it is an out-of-distribution sample.

2. The out-of-distribution data detection method based on attention mechanism and adversarial enhancement training according to claim 1, characterized in that, In step S1, the specific steps for generating the pseudo-distribution out-of-sample set include: S11. Define a set of class-independent covariate perturbation operators; S12. For each sample within the distribution, randomly select the perturbation combination length and the corresponding perturbation operator sequence; S13. Apply the perturbation operator sequence sequentially to generate corresponding pseudo-out-of-distribution samples.

3. The out-of-distribution data detection method based on attention mechanism and adversarial enhancement training according to claim 2, characterized in that, The covariate perturbation includes at least one of the following: noise interference, blurring, color shift, contrast change, geometric deformation, or compression distortion.

4. The out-of-distribution data detection method based on attention mechanism and adversarial enhancement training according to claim 1, characterized in that, In step S2, the covariate-semantic feature attention module specifically includes: S21, Channel Attention Submodule, is used to generate weights for each channel of the feature map; S22, Spatial Attention Submodule, used to generate weights for each spatial location of the feature map; S23. Based on the channel weights and spatial weights, the original features are reweighted to obtain feature representations that are sensitive to covariate perturbations or semantic changes.

5. The out-of-distribution data detection method based on attention mechanism and adversarial enhancement training according to claim 4, characterized in that, The feature attention module is applied to the shallow and deep features of the convolutional neural network, respectively. The shallow features are used to capture covariate shifts, and the deep features are used to capture semantic shifts.

6. The out-of-distribution data detection method based on attention mechanism and adversarial enhancement training according to claim 1, characterized in that, In step S3, the adversarial enhancement training is optimized using the following loss function: in, and These represent the ID training set and the generated OOD dataset, respectively. This represents the mean operation. The discriminator's predicted output. For temperature parameters, Collect all trainable parameters and perform unified optimization.

7. The out-of-distribution data detection method based on attention mechanism and adversarial enhancement training according to claim 1, characterized in that, The discriminator receives a feature vector that is concatenated and projected from shallow weighted features and deep weighted features, and outputs the probability that a sample belongs to the distribution or is outside the distribution.

8. An out-of-distribution data detection system based on attention mechanisms and adversarial reinforcement training, characterized in that, The system includes: a pseudo-sample generation module, a feature extraction and attention module, a discrimination module, and a training module; the pseudo-sample generation module is used to generate pseudo-out-of-distribution samples based on in-distribution samples; the feature extraction and attention module is used to extract shallow and deep features from input samples and perform adaptive weighting; the discrimination module is used to determine whether a sample is an out-of-distribution sample based on the weighted features; and the training module is used to optimize the attention module and the discrimination module through adversarial enhancement training.

9. The out-of-distribution data detection system based on attention mechanism and adversarial enhancement training according to claim 8, characterized in that, The system is integrated into the intelligent perception module of autonomous driving, medical image analysis, smart transportation, or unmanned systems to improve the robustness and safety of the model in open environments.