A method and system for detecting out-of-distribution samples based on an adaptive distribution ball framework

Through dynamic distribution boundary adjustment, multi-scale feature fusion and energy optimization of the adaptive distribution spherical framework, the static threshold and feature characterization problems of deep neural networks in out-of-distribution sample detection are solved, and higher detection accuracy and adaptability are achieved.

CN120375097BActive Publication Date: 2025-08-26ZHEJIANG NORMAL UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510840204.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-23
Publication Date
2025-08-26
Estimated Expiration
2045-06-23

AI Technical Summary

Technical Problem

The existing deep neural networks have problems such as static threshold mechanisms and dynamic data environments in the detection of out-of-distributed samples, limited feature representation capabilities, and lack of dynamic optimization closed loops, resulting in a decrease in detection accuracy, especially in complex multimodal data and adversarial attack scenarios.

Method used

Adaptive distribution ball framework is adopted, and through the dynamic distribution boundary adjustment module, the dynamic multi-scale feature fusion module and the dynamic energy optimization module, the enhanced samples satisfying global semantic alignment and local detail offset optimization are generated, the feature boundaries are dynamically adjusted and end-to-end optimization is achieved.

Benefits of technology

It improves the accuracy and scene adaptability of out-of-distribution sample detection, breaks through the limitations of traditional static boundary modeling, enhances the adaptability to complex distribution offsets, and improves the accuracy and efficiency of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120375097B_ABST
    Figure CN120375097B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for detecting out-of-distribution samples based on an adaptive distribution ball framework, relating to the fields of artificial intelligence and machine learning technology. The method constructs an out-of-distribution sample detection model based on the adaptive distribution ball framework; inputs training data into a dynamic distribution boundary adjustment module, generates enhanced samples through a generative adversarial network to expand the distribution boundary; inputs the enhanced samples into a dynamic multi-scale feature fusion module, fuses global features and local features based on fusion weights to generate fused features; inputs the fused features into a dynamic energy optimization module, calculates energy values ​​through an energy function, dynamically adjusts classification thresholds using a closed-loop feedback mechanism, and applies an energy loss gradient to the dynamic distribution boundary adjustment module and the dynamic multi-scale feature fusion module for parameter adjustment, outputting recognition results. By combining dynamic boundary adjustment, feature fusion, and energy optimization, the present invention significantly improves the accuracy and robustness of out-of-distribution detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence and machine learning technologies, and more particularly to a method and system for detecting out-of-distribution samples based on an adaptive distribution sphere framework. Background Art

[0002] Currently, deep neural networks have developed a robust framework of methods for out-of-distribution (OOD) detection, represented by maximum soft probability (MSP), ODIN, and OpenMax. MSP constructs a detection threshold using the maximum probability value in the output layer, while ODIN enhances confidence discrimination by introducing temperature scaling and input perturbations. Mahalanobis distance methods and energy-based models, based on the statistical properties of feature spaces, improve detection performance by modeling feature distributions. These methods have demonstrated effectiveness on standard benchmark datasets and are finding initial application in scenarios such as autonomous driving perception modules and medical image-assisted diagnosis.

[0003] However, existing technologies suffer from three key flaws: First, static threshold mechanisms are inherently incompatible with dynamic data environments. MSP and ODIN rely on preset fixed thresholds, making them unable to adapt to the constantly changing modal distributions and adversarial sample interference in real-world scenarios. Second, feature representation capabilities are limited. Traditional methods often use global semantic features or single-scale statistics, making it difficult to capture the local details and cross-scale contextual associations of tiny lesions in medical images. Third, they lack a dynamic optimization loop. The offline parameter fixation of methods like OpenMax makes them ineffective when dealing with the distribution drift of real-time data streams. The high-dimensional computational complexity and energy model of static threshold strategies based on Mahalanobis distance further restrict actual deployment efficiency. These issues lead to a significant decrease in the detection accuracy of existing systems in complex multimodal data and adversarial attack scenarios, resulting in high-risk risks such as misjudgment of road signs in autonomous driving and missed diagnosis of early lesions in medical imaging.

[0004] Therefore, how to develop a solution that can dynamically adjust feature boundaries, fuse multi-scale information and achieve end-to-end optimization to improve the accuracy and scene adaptability of out-of-distribution detection is an urgent problem that technicians in this field need to solve. Summary of the Invention

[0005] In view of this, the present invention provides an out-of-distribution sample detection method and system based on an adaptive distribution sphere framework, which overcomes the above-mentioned defects.

[0006] In order to achieve the above object, the present invention adopts the following technical solutions:

[0007] A method for detecting out-of-distribution samples based on an adaptive distribution ball framework is proposed, specifically:

[0008] Training steps:

[0009] Building an out-of-distribution sample detection model based on an adaptive distribution ball framework, the adaptive distribution ball framework includes a dynamic distribution boundary adjustment module, a dynamic multi-scale feature fusion module, and a dynamic energy optimization module;

[0010] Inputting training data into the dynamic distribution boundary adjustment module, generating enhanced samples that meet global semantic alignment and local detail offset optimization through a generative adversarial network to expand the distribution boundary; the training data comes from a training dataset constructed by in-distribution data and auxiliary out-distribution data;

[0011] Inputting the enhanced sample into the dynamic multi-scale feature fusion module, extracting global features and local features, dynamically calculating fusion weights based on the distribution differences between the global features and the local features, and fusing the global features and the local features based on the fusion weights to generate fused features;

[0012] Inputting the fusion features into the dynamic energy optimization module, calculating the energy value through the energy function and dynamically adjusting the classification threshold using a closed-loop feedback mechanism; and applying the energy loss gradient to the dynamic distribution boundary adjustment module and the dynamic multi-scale feature fusion module for parameter adjustment;

[0013] Testing steps:

[0014] Obtain the image to be detected;

[0015] The image to be detected is input into the out-of-distribution sample detection model to perform OOD sample recognition, and the recognition result is output.

[0016] Optionally, a preprocessing module is further included, which is used to perform standardization and enhancement processing on the training data or the image to be detected to generate preprocessed data.

[0017] Optionally, global semantic alignment uses Wasserstein distance to quantify global semantic differences, which is expressed as:

[0018] ;

[0019] Where, is the probability distribution of the data within the distribution; is the probability distribution of out-of-distribution data; For all satisfying marginal distribution and The joint distribution set of ; is the expectation operation on the joint distribution γ; for and The L2 norm distance between them.

[0020] Optionally, the local detail offset optimization is to enhance the sensitivity to fine-grained anomalies through the Sinkhorn distance, which is expressed as:

[0021] ;

[0022] Where, is the probability distribution of the data within the distribution; is the probability distribution of out-of-distribution data; For all satisfying marginal distribution and The joint distribution set of ;γ is the joint distribution; is the expected value; is the cost function; is the entropy regularization coefficient; H(γ) is the entropy of the joint distribution γ.

[0023] Optionally, the dynamic distribution boundary adjustment module further adjusts the weights of global and local distribution modeling through a dynamic weight strategy to achieve hierarchical boundary modeling, and the defined joint optimization objective is:

[0024] ,

[0025] Where, is the global semantic alignment loss, Optimize loss for local details; is the weight coefficient, which changes with time Adjust the balance between global and local losses, the expression is:

[0026] ;

[0027] Where, is the initial weight coefficient; is the maximum number of training steps; is a nonlinear growth factor.

[0028] Optionally, the calculation formula of the fusion weight is:

[0029] ;

[0030] Where, is the activation function; Global features With local features Wasserstein distance between them; Global features With local features Sinkhorn distance between; is a very small constant; is the weight coefficient of the regularization term; is the covariance consistency regularization term.

[0031] Optionally, hierarchical contrastive learning is further introduced in the dynamic multi-scale feature fusion module to optimize feature space discriminability, including:

[0032] Global contrast loss enhances the compactness of the feature space by aggregating the high-level semantics of samples within a class. Its expression is:

[0033] ;

[0034] Local contrast loss enhances sensitivity to local anomalies by amplifying fine-grained differences:

[0035] ;

[0036] Where, is the number of samples in the batch; For the The global feature vector of samples; For The global feature vector of positive samples of the same category; is the global feature vector of negative samples; is the temperature coefficient of global contrast loss; Calculate the cosine similarity function; For the The local feature vector of samples; For Local feature vectors of positive samples of the same category; is the local feature vector of the negative sample; is the temperature coefficient of local contrast loss; is the number of negative samples in contrastive learning.

[0037] Optionally, the energy function is defined as:

[0038] ;

[0039] Where, is the confidence of the model output; C is the total number of categories.

[0040] Optionally, the calculation formula of the classification threshold is:

[0041] ;

[0042] Where, is the exponentially weighted moving average of the sample energies within the distribution; is the threshold adjustment coefficient; is the exponentially weighted moving average of the standard deviation of the sample energies within the distribution.

[0043] An out-of-distribution sample detection system based on an adaptive distribution ball framework comprises:

[0044] A model building module, configured to build an out-of-distribution sample detection model based on an adaptive distribution ball framework, wherein the adaptive distribution ball framework includes a dynamic distribution boundary adjustment module, a dynamic multi-scale feature fusion module, and a dynamic energy optimization module;

[0045] A sample generation module is configured to input training data into the dynamic distribution boundary adjustment module and generate enhanced samples that meet global semantic alignment and local detail offset optimization through a generative adversarial network to expand the distribution boundary; the training data comes from a training dataset constructed from in-distribution data and auxiliary out-distribution data;

[0046] a feature fusion module, configured to input the enhanced sample into the dynamic multi-scale feature fusion module, extract global features and local features, dynamically calculate fusion weights based on the distribution differences between the global features and the local features, and fuse the global features and the local features based on the fusion weights to generate fused features;

[0047] A decision and feedback module is configured to input the fusion features into the dynamic energy optimization module, calculate the energy value through the energy function, and dynamically adjust the classification threshold using a closed-loop feedback mechanism; and apply the energy loss gradient to the dynamic distribution boundary adjustment module and the dynamic multi-scale feature fusion module for parameter adjustment;

[0048] The sample recognition module is used to obtain the image to be detected, input the image to be detected into the out-of-distribution sample detection model to perform OOD sample recognition, and output the recognition result.

[0049] From the above technical solutions, it can be seen that the present invention provides a method and system for detecting out-of-distribution samples based on an adaptive distribution ball framework, which has the following beneficial effects compared with the existing technology:

[0050] 1. The Dynamic Distribution Boundary Adjustment (DBA) module uses a multi-scale distance collaborative optimization mechanism (dynamic weight allocation of Wasserstein and Sinkhorn distances) to generate enhanced samples that cover both global semantic differences and local detail anomalies, effectively alleviating the distribution deviation between auxiliary data and real OOD data. This module uses a phased boundary evolution strategy, gradually transitioning from global alignment to local refinement, overcoming the limitations of traditional static boundary modeling and enhancing the model's adaptability to complex distribution shifts.

[0051] 2. The dynamic multi-scale feature fusion module (MFF) first upsamples local features to 128 dimensions, then dynamically assigns fusion weights based on the ratio of Wasserstein to Sinkhorn distances. It combines covariance consistency regularization to suppress covariate shift and leverages the synergy of global contrastive loss (high-level semantic aggregation) and local contrastive loss (low-temperature, fine-grained optimization) to achieve complementary modeling of cross-scale features.

[0052] 3. The Dynamic Energy Optimization (EGO) module dynamically adjusts the classification threshold using an exponentially weighted moving average (EMA) based on the real-time statistical characteristics (mean and standard deviation) of ID sample energy, addressing the lack of robustness of traditional static thresholds. Furthermore, energy gradients drive the weight allocation of the MFF module and the direction of adversarial example generation in the DBA module through backpropagation, forming an end-to-end collaborative optimization loop. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0054] Figure 1 The present invention provides a flow chart of the method.

[0055] Figure 2 A schematic diagram of the model training process provided by the present invention;

[0056] Figure 3 A schematic diagram of the data processing flow of the DBA module provided by the present invention;

[0057] Figure 4 A flowchart of the interaction between the Generative Adversarial Network (DBA module) and the backbone network provided by the present invention;

[0058] Figure 5 A schematic diagram of the ADSF backbone network provided by the present invention;

[0059] Figure 6 A schematic diagram of the internal structure of BasicBlock provided by the present invention;

[0060] Figure 7 A schematic diagram of the data processing flow of the MFF module provided by the present invention;

[0061] Figure 8 This is a schematic diagram of the data processing flow of the EGO module provided by the present invention. DETAILED DESCRIPTION

[0062] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0063] On the one hand, the embodiment of the present invention discloses a method for detecting out-of-distribution samples based on an adaptive distribution ball framework, such as Figure 1 As shown, the following steps are included:

[0064] Specific steps of the training phase:

[0065] Step 1: Build an out-of-distribution sample detection model based on the adaptive distribution ball framework, which includes a dynamic distribution boundary adjustment module, a dynamic multi-scale feature fusion module, and a dynamic energy optimization module;

[0066] Step 2: Input the training data into the dynamic distribution boundary adjustment module, and generate enhanced samples that meet the requirements of global semantic alignment and local detail offset optimization through the adversarial generative network to expand the distribution boundary. The training data comes from the training dataset constructed by the in-distribution data and the auxiliary out-distribution data.

[0067] Step 3: Input the enhanced sample into the dynamic multi-scale feature fusion module to extract global features and local features, dynamically calculate the fusion weight based on the distribution difference between global features and local features, and fuse the global features and local features based on the fusion weight to generate fusion features;

[0068] Step 4: Input the fused features into the dynamic energy optimization module, calculate the energy value through the energy function, and dynamically adjust the classification threshold using the closed-loop feedback mechanism; and apply the energy loss gradient to the dynamic distribution boundary adjustment module and the dynamic multi-scale feature fusion module to adjust the parameters;

[0069] Specific steps in the detection phase:

[0070] Step 5: Obtain the image to be detected;

[0071] Step 6: Input the image to be detected into the out-of-distribution sample detection model for OOD sample recognition and output the recognition result.

[0072] In one embodiment, a pre-processing module is further included, which is used to perform standardization and enhancement processing on the training data or the image to be detected to generate pre-processed data.

[0073] Furthermore, this embodiment obtains in-distribution (ID) data based on the CIFAR-10 / CIFAR-100 dataset, obtains auxiliary out-of-distribution (OOD) data based on 300K Random Images, and performs normalization and enhancement operations on the processed images to obtain preprocessed data.

[0074] The specific steps of standardization are: using bilinear interpolation to adjust the input image to a preset resolution (e.g., 32×32 pixels) to ensure input consistency;

[0075] Normalize the pixel values ​​using the formula:

[0076] ;

[0077] Where, is the original pixel value of the input image, that is, the data to be normalized; and are the mean and standard deviation, respectively; is the normalized pixel value, that is, the standardized input.

[0078] Subsequently, random horizontal flipping (probability 50%) and random cropping (pad 4 pixels and then crop to 32×32) are applied to enhance data diversity; finally, the ID data and auxiliary OOD data are mixed in a 1:2 ratio, with an ID batch size of 128 and an OOD batch size of 256.

[0079] Furthermore, in the testing phase, real OOD datasets (such as SVHN, Textures, LSUN_resize, iSUN, and Places365) are used to verify the generalization ability of the model; the test data is a mixture of ID and OOD samples, with a batch size of 256 and data augmentation operations disabled.

[0080] In one embodiment, the adaptive distribution sphere framework consists of a dynamic distribution boundary adjustment module, a dynamic multi-scale feature fusion module, and a dynamic energy optimization module, wherein:

[0081] The dynamic distribution boundary adjustment module generates enhanced samples that satisfy global semantic alignment (constrained by Wasserstein distance) and local detail offset optimization (constrained by Sinkhorn distance) through a generative adversarial network, and adjusts the weights of global and local distribution modeling based on a dynamic weight strategy;

[0082] Dynamic multi-scale feature fusion module dynamically calculates the fusion weights of global and local features. The fusion weights are allocated based on the ratio of the global Wasserstein distance to the local Sinkhorn distance, and the covariance consistency regularization term is used to suppress noise interference.

[0083] The dynamic energy optimization module dynamically adjusts the classification threshold based on the sample energy score and applies gradient penalties to high-energy samples.

[0084] Further, if Figure 2 As shown in the figure, starting from the input in-distribution data and auxiliary out-of-distribution data, the dynamic distribution boundary adjustment (DBA) module is first used to generate adversarial samples to extend the distribution boundary. Then, the Wasserstein distance is used to quantify the global semantic difference and the Sinkhorn distance is combined to optimize the local details to generate enhanced samples. The global and local distribution modeling weights are dynamically adjusted to achieve hierarchical boundary modeling. Subsequently, the dynamic multi-scale feature fusion (MFF) module dynamically assigns feature weights based on the global and local distribution differences, and combines hierarchical contrastive learning (high temperature coefficients aggregate intra-class semantics and low temperature coefficients amplify fine-grained differences) to optimize the feature space discriminability. Finally, the dynamic energy optimization (EGO) module defines an energy function to quantify the sample separability, dynamically adjusts the classification threshold based on real-time statistical characteristics, and feeds back the energy gradient to the dynamic distribution boundary adjustment module and the dynamic multi-scale feature fusion module, forming a "generation-fusion-decision-feedback" closed-loop optimization process, which significantly improves the ability to distinguish between in-distribution and out-of-distribution samples.

[0085] In one embodiment, the preprocessed data is input into the dynamic distribution boundary adjustment module to generate adversarial samples to expand the distribution boundary. The DBA module implements hierarchical boundary modeling through a multi-scale distance collaborative optimization mechanism.

[0086] In one embodiment, the processing flow of the DBA module is as follows: Figure 3 As shown, specifically:

[0087] Global semantic alignment: The Wasserstein distance is used to quantify the overall distribution offset of ID and OOD samples, and its expression is:

[0088] ;

[0089] Where, is the probability distribution of the data within the distribution; is the probability distribution of out-of-distribution data; For all satisfying marginal distribution and The joint distribution set of ; is the expectation operation on the joint distribution γ; is the L2 norm distance between x and y.

[0090] Local detail offset optimization: Enhance sensitivity to fine-grained anomalies through Sinkhorn distance, which is expressed as:

[0091] ;

[0092] Where, is the probability distribution of the data within the distribution; is the probability distribution of out-of-distribution data; For all satisfying marginal distribution and The joint distribution set of ;γ is the joint distribution; is the expected value; is the cost function, defined as and The difference measure between is the entropy regularization coefficient, which is used to balance the weights of the cost term and the entropy term; H(γ) is the entropy of the joint distribution γ, which is calculated as .

[0093] Dynamic weight strategy: Dynamically adjust the global and local distribution modeling weights and define the joint optimization objective, which is expressed as:

[0094] ;

[0095] Where, is the global semantic alignment loss, Optimize loss for local details; is the weight coefficient, which can be dynamically increased with the training stage. The formula is:

[0096] ;

[0097] Where, is the initial weight coefficient, In this embodiment ; is the maximum number of training steps, ≤2000, in this embodiment =1000; is a nonlinear growth factor, , this embodiment .

[0098] Adversarial sample generation: The Dynamic Distribution Boundary Adjustment module (DBA) generates samples through an independent adversarial generation network. The adversarial generation network uses a lightweight fully connected architecture to achieve adversarial sample generation. Figure 4As shown, the generative network inputs the 128-dimensional high-level semantic feature vectors of in-distribution (ID) samples extracted from the backbone network. The network first performs feature compression (dimension 128→64) through the first fully connected layer (BN), and uses the ReLU activation function to enhance nonlinear representation. This is followed by further dimensionality reduction through the second fully connected layer (BN) (dimension 64→32), outputting the perturbed feature vectors of the generated samples. The final output of the generative network is constrained to perturb the amplitude within 10% of the original feature vector using the L2 norm constraint, ensuring that the generated adversarial examples effectively extend the distribution boundary while avoiding excessive deviation from the true data distribution. The generated perturbed features are linearly superimposed with the original ID features to form enhanced samples. The global semantic features of the enhanced samples are constrained to move away from the ID distribution using the Wasserstein distance constraint, while the local details are optimized using the Sinkhorn distance to approximate the fine-grained anomaly patterns of true OOD samples. The entire generation process is implemented through end-to-end adversarial training, with the parameters of the generative network and the backbone network updated using an alternating optimization strategy.

[0099] Among them, the backbone network consists of an input layer, three stage blocks and an output layer, such as Figure 4 and Figure 5 As shown in Figure 1, the input layer uses a 3×3 convolution kernel to process a 32×32 pixel RGB image and outputs a 16-channel feature map. The network consists of three main stages (block1, block2, block3), each of which is composed of multiple improved BasicBlocs with 32, 64, and 128 channels respectively. Block2 and block3 perform 2x downsampling respectively. Their structures are shown in Figure 1. Figure 6As shown in the figure, each BasicBloc integrates three attention mechanisms based on the traditional residual architecture (N layers of stacked residual blocks (Network Blocks)). First, the Convolutional Block Attention Module (CBAM) is applied to enhance the response of important features through channel attention and spatial attention. Second, the Squeeze-and-Excitation (SE) module is introduced to dynamically calibrate channel importance using a squeeze-and-excitation mechanism. Finally, the Efficient Channel Attention (ECA) module is added to achieve cross-channel interaction through lightweight 1D convolution. This multi-attention collaborative design significantly improves the network's sensitivity to distribution shift. The network output layer includes global average pooling and a fully connected layer, ultimately outputting 128-dimensional high-level semantic features. Dropout (drop rate = 0.3), batch normalization (Bn1), and ReLU activation function are applied after the convolutional layer of each BasicBlock. The 128-dimensional input is then converted to a num-classes-dimensional output through a two-dimensional average pooling layer (AvgPool2d(8)) and a fully connected layer (fc layer) to obtain logits (confidence), where num-classes is the number of classes; finally, the energy calculation operation logsumexp(logits) is used to calculate the energy. In particular, temperature scaling (temp=2.0) is introduced in the classification layer to smooth the logits (confidence) output. The network is trained using an energy-based constraint mechanism, which is implemented through the energy function To distinguish samples inside and outside the distribution. In terms of feature extraction, the 128-dimensional global features output from block 3 are used to capture high-level semantic information, while the 64-dimensional local features output from block 2 retain more spatial details.

[0100] When generating adversarial samples, energy constraints are combined to force the generated samples to stay away from the ID distribution and approach the true OOD characteristics. The expression of the adversarial loss function is:

[0101] ;

[0102] Where, is the ID rejection coefficient, which controls the degree to which the generated samples are away from the ID distribution; is the OOD attraction coefficient, which controls the degree to which the generated samples are close to the auxiliary OOD distribution; To generate samples ( ) and ID data ( )’s Wasserstein distance; To generate sample and auxiliary OOD data ( ) is the Wasserstein distance.

[0103] Furthermore, in this embodiment, the expression of the adversarial loss function is:

[0104] .

[0105] Where, the ID rejection coefficient α=-0.8 forces the generated samples to stay away from the ID distribution (minimizing ) maximizes the difference between the generated sample and the ID data to avoid the generated sample being misjudged as ID. The OOD attraction coefficient δ = 0.2 guides the generated sample to approach the auxiliary OOD distribution (maximize ), making the distribution of generated samples close to the auxiliary OOD data and expanding the model's recognition boundary for true OOD. Experiments have shown that overfitting the auxiliary OOD data can lead to boundary overfitting. Therefore, a weight ratio of 4:1 is selected to prioritize ensuring that the generated samples are far away from the ID distribution.

[0106] The optimizer uses Adam, with a learning rate of 0.001 and a weight decay of 1e-4.

[0107] In one embodiment, the features output by the DBA module are input into the dynamic multi-scale feature fusion module, and the discriminability is optimized by combining global and local features, such as Figure 7 shown.

[0108] In one embodiment, the MFF module processing flow is as follows:

[0109] Extract 128-dimensional high-level semantic features (global feature extraction) from the last convolutional output of the backbone network, and then extract 64-dimensional detail features from the backbone network mid-level feature maps (such as the output of the second stage);

[0110] Dynamically allocate fusion weight α based on the difference between global and local distribution:

[0111] ;

[0112] Where, is the activation function; Global features With local features Wasserstein distance between them; Global features With local features Sinkhorn distance between; is a very small constant (such as 1×10 −5 ), to prevent the denominator from being zero; is the weight coefficient of the regularization term (value range [5,15]); is the covariance consistency regularization term, defined as .

[0113] Furthermore, global feature extraction: 128-dimensional high-level semantic features are extracted through the last layer output of the backbone network (WideResNet);

[0114] Local feature extraction: Extract 64-dimensional detail features from the output of the middle layer of the backbone network (stage 2).

[0115] In this embodiment, λ=10 to balance the contribution of the regularization term.

[0116] In one embodiment, in an autonomous driving scenario, the method dynamically adjusts the fusion weight α based on the global-local feature mapping relationship of the lidar point cloud data, specifically:

[0117] Global feature weights ;

[0118] Local feature weight ;

[0119] When a dynamic obstacle is detected, Automatically increases by 0.1.

[0120] In one embodiment, a covariance consistency regularization term suppresses noise interference, where the regularization term is:

[0121] .

[0122] Furthermore, the covariance consistency regularization term is only Activated when ; where F is the Frobenius norm.

[0123] In one embodiment, a hierarchical contrastive learning strategy is used to optimize the feature space, including:

[0124] Global contrast loss (high temperature coefficient =1.0) by aggregating the high-level semantics of samples within a class to enhance the compactness of the feature space, which is expressed as:

[0125] ;

[0126] Local contrast loss (low temperature coefficient = 0.1) amplifies fine-grained differences and enhances sensitivity to local anomalies, and its expression is:

[0127] ;

[0128] Where, is the temperature coefficient of the global contrast loss (e.g. =1.0), controlling the degree of aggregation of samples within a class; is the temperature coefficient of local contrast loss (e.g. = 0.1), amplifying fine-grained differences; is the number of samples in the batch; is the number of negative samples in contrastive learning; For the The global feature vector of samples; For The global feature vector of positive samples of the same category; is the global feature vector of other samples (negative samples); For the The local feature vector of samples; For Local feature vectors of positive samples of the same category; is the local feature vector of the negative sample; Calculates the cosine similarity function.

[0129] In one embodiment, the dynamic multi-scale feature fusion module compresses the global feature dimension to 256 dimensions and the local feature dimension to 64 dimensions through knowledge distillation technology, and adopts a pruning strategy to reduce the amount of fusion weight calculation (parameter compression rate ≥ 50%, computing power consumption ≤ 5W).

[0130] In one embodiment, the fusion features output by the MFF module are input into the dynamic energy optimization module to calculate the energy value and dynamically adjust the classification threshold, such as Figure 8 shown.

[0131] The energy function is defined as:

[0132] ;

[0133] Where, is the confidence output of the i-th category of the classification network. The energy value of ID samples is low, and the energy value of OOD samples is high. C is the number of categories.

[0134] In one embodiment, the closed-loop feedback mechanism includes:

[0135] The energy loss gradient acts on the gradient back propagation path through the chain rule: the perturbation direction of the adversarial generative network, the weight calculation of dynamic multi-scale feature fusion, and the parameter optimization of the classifier, driving the distribution of generated samples to approach the real OOD characteristics and improving the discriminability of the feature space.

[0136] Parameter update strategy: Use exponentially weighted moving average (EMA) to update the dynamic threshold. The formula is: , ensuring smooth adjustment of the threshold.

[0137] Stability monitoring: Training stability is monitored in real time through the variance of the loss function. If the variance exceeds a preset threshold, the early stopping mechanism is triggered.

[0138] Furthermore, the threshold T is dynamically updated based on the real-time statistical characteristics of the ID sample energy, and its expression is:

[0139] , ;

[0140] Where, is the energy mean of ID samples, is the standard deviation of ID sample energy, is a tunable hyperparameter.

[0141] Where, and Updated by Exponentially Weighted Moving Average (EMA):

[0142] ;

[0143] In this embodiment, ;

[0144] ;

[0145] Where, is the mean of the sample energy in the current batch distribution; is the standard deviation of the sample energy within the current batch distribution.

[0146] The energy gradient is back-propagated to the DBA module, which can adjust the direction of the adversarial perturbation and balance the global and local generation strategies;

[0147] The energy gradient is back-propagated to the MFF module to optimize the fusion weight α and enhance the contribution of local features.

[0148] Furthermore, during the training process, the threshold T is updated after each batch iteration, and the OOD sample energy value is constrained by a piecewise linear loss function:

[0149] ;

[0150] Where, is the energy constraint loss of the OOD sample; is the number of OOD samples in the current batch; is the OOD sample set of the current batch; is the dynamic classification threshold; is a piecewise linear activation function.

[0151] In one embodiment, the model training uses the SGD optimizer, with an initial learning rate of 0.07, a momentum parameter of 0.9, a weight decay coefficient of 0.0005, and a cosine annealing strategy to adjust the learning rate. The training cycle is set to 50 epochs.

[0152] During the training process, the energy distribution curves of ID and OOD samples, FPR95 (OOD false positive rate when ID true positive rate is 95%), and AUROC (area under the receiver operating characteristic curve) indicators are recorded in each round to monitor the convergence status of the model;

[0153] During the testing phase, the same normalization process is performed on the image to be tested (data enhancement is disabled), and the trained model is input to calculate the energy value. If the energy value exceeds the dynamic threshold T, it is determined to be an OOD sample; the dynamic threshold is updated based on the real-time statistics of the ID sample energy, and the fluctuations during training are smoothed by the exponentially weighted moving average (EMA) strategy;

[0154] The auxiliary OOD data can be extended to datasets such as LSUN and iSUN to verify the cross-domain generalization capability, and the hyperparameters can be adjusted according to the complexity of the scenario (such as setting γ0=0.5 and λ=5 to balance efficiency and accuracy).

[0155] On the other hand, this embodiment discloses an out-of-distribution sample detection system based on an adaptive distribution sphere framework, comprising:

[0156] A model building module is used to build an out-of-distribution sample detection model based on an adaptive distribution ball framework. The adaptive distribution ball framework includes a dynamic distribution boundary adjustment module, a dynamic multi-scale feature fusion module, and a dynamic energy optimization module.

[0157] The sample generation module is used to input training data into the dynamic distribution boundary adjustment module. The module generates enhanced samples that meet the requirements of global semantic alignment and local detail offset optimization through the adversarial generative network to expand the distribution boundary. The training data comes from the training dataset constructed by the in-distribution data and the auxiliary out-distribution data.

[0158] The feature fusion module is used to input the enhanced samples into the dynamic multi-scale feature fusion module, extract global features and local features, dynamically calculate the fusion weight based on the distribution difference between global features and local features, and fuse the global features and local features based on the fusion weight to generate fusion features;

[0159] The decision and feedback module is used to input the fusion features into the dynamic energy optimization module, calculate the energy value through the energy function, and dynamically adjust the classification threshold through a closed-loop feedback mechanism. The energy loss gradient is applied to the dynamic distribution boundary adjustment module and the dynamic multi-scale feature fusion module for parameter adjustment;

[0160] The sample recognition module is used to obtain the image to be detected, input the image to be detected into the out-of-distribution sample detection model for OOD sample recognition, and output the recognition result.

[0161] Furthermore, the dynamic distribution boundary adjustment module is deployed on GPU accelerators (such as NVIDIA architecture) to support batch parallel generation of adversarial samples (single-card throughput ≥ 500 samples / second);

[0162] Dynamic multi-scale feature fusion module: Integrates a high-performance inference engine (such as TensorRT) to support real-time feature fusion (throughput ≥ 1000 samples / second, latency ≤ 1ms);

[0163] Dynamic Energy Optimization Module: Energy calculation is implemented through hardware acceleration (such as GPU / FPGA), supporting FP16 / FP32 mixed precision, and dynamic threshold update delay ≤ 2ms (including EMA smoothing time).

[0164] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Reference can be made to the common and similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method description.

[0165] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for detecting out-of-distribution samples based on an adaptive distribution ball framework, characterized in that: Specifically: Training steps: Building an out-of-distribution sample detection model based on an adaptive distribution ball framework, the adaptive distribution ball framework includes a dynamic distribution boundary adjustment module, a dynamic multi-scale feature fusion module, and a dynamic energy optimization module; Training data is input into the dynamic distribution boundary adjustment module, and enhanced samples that meet global semantic alignment and local detail offset optimization are generated through a generative adversarial network to expand the distribution boundary. The training data comes from a training dataset constructed by in-distribution data and auxiliary out-distribution data. The weights of global and local distribution modeling are adjusted through a dynamic weight strategy to achieve hierarchical boundary modeling. The global semantic alignment is constrained by the Wasserstein distance, and the local detail offset optimization is constrained by the Sinkhorn distance. Inputting the enhanced sample into the dynamic multi-scale feature fusion module, extracting global features and local features, dynamically calculating fusion weights based on the distribution difference between the global features and the local features, fusing the global features and the local features based on the fusion weights to generate fusion features; the fusion weights are allocated based on the ratio of the Wasserstein distance to the Sinkhorn distance, and noise interference is suppressed by a covariance consistency regularization term; Inputting the fusion features into the dynamic energy optimization module, calculating the energy value through the energy function and dynamically adjusting the classification threshold using a closed-loop feedback mechanism; and applying the energy loss gradient to the dynamic distribution boundary adjustment module and the dynamic multi-scale feature fusion module for parameter adjustment; Testing steps: Obtain the image to be detected; The image to be detected is input into the out-of-distribution sample detection model to perform OOD sample recognition, and the recognition result is output.

2. The out-of-distribution sample detection method based on the adaptive distribution ball framework according to claim 1 is characterized in that: It also includes a preprocessing module for performing standardization and enhancement processing on the training data or the image to be detected to generate preprocessed data.

3. The out-of-distribution sample detection method based on the adaptive distribution ball framework according to claim 1 is characterized in that: Global semantic alignment uses Wasserstein distance to quantify global semantic differences, which is expressed as: ; Where, is the probability distribution of the data within the distribution; is the probability distribution of out-of-distribution data; For all satisfying marginal distribution and The joint distribution set of ; is the expectation operation on the joint distribution γ; for and The L2 norm distance between them.

4. The out-of-distribution sample detection method based on the adaptive distribution ball framework according to claim 1 is characterized in that: The local detail offset optimization is to enhance the sensitivity to fine-grained anomalies through the Sinkhorn distance, which is expressed as: ; Where, is the probability distribution of the data within the distribution; is the probability distribution of out-of-distribution data; For all satisfying marginal distribution and The joint distribution set of ;γ is the joint distribution; is the expected value; is the cost function; is the entropy regularization coefficient; H ( γ ) is the entropy of the joint distribution γ.

5. The out-of-distribution sample detection method based on the adaptive distribution ball framework according to claim 1 is characterized in that: The joint optimization objective defined by the dynamic distribution boundary adjustment module is: ; Where, is the global semantic alignment loss, Optimize loss for local details; is the weight coefficient, which changes with time Adjust the balance between global and local losses, the expression is: ; Where, is the initial weight coefficient; is the maximum number of training steps; is a nonlinear growth factor.

6. The out-of-distribution sample detection method based on the adaptive distribution ball framework according to claim 1 is characterized in that: The calculation formula of the fusion weight is: ; Where, is the activation function; Global features With local features Wasserstein distance between them; Global features With local features Sinkhorn distance between; is a very small constant; is the weight coefficient of the regularization term; is the covariance consistency regularization term.

7. The out-of-distribution sample detection method based on the adaptive distribution ball framework according to claim 1 is characterized in that: The dynamic multi-scale feature fusion module also introduces hierarchical contrastive learning to optimize the discriminability of feature space, including: Global contrast loss enhances the compactness of the feature space by aggregating the high-level semantics of samples within a class. Its expression is: ; Local contrast loss enhances sensitivity to local anomalies by amplifying fine-grained differences: ; Where, is the number of samples in the batch; For the The global feature vector of samples; For The global feature vector of positive samples of the same category; is the global feature vector of negative samples; is the temperature coefficient of global contrast loss; sin(.) is the cosine similarity calculation function; For the The local feature vector of samples; For Local feature vectors of positive samples of the same category; is the local feature vector of the negative sample; is the temperature coefficient of local contrast loss; is the number of negative samples in contrastive learning.

8. The out-of-distribution sample detection method based on the adaptive distribution ball framework according to claim 1 is characterized in that: The energy function is defined as: ; Where, is the confidence of the model output; C is the total number of categories.

9. The out-of-distribution sample detection method based on the adaptive distribution ball framework according to claim 1, characterized in that: The calculation formula of the classification threshold is: ; Where, is the exponentially weighted moving average of the sample energies within the distribution; is the threshold adjustment coefficient; is the exponentially weighted moving average of the standard deviation of the sample energies within the distribution.

10. An out-of-distribution sample detection system based on an adaptive distribution ball framework, characterized in that: include: A model building module, configured to build an out-of-distribution sample detection model based on an adaptive distribution ball framework, wherein the adaptive distribution ball framework includes a dynamic distribution boundary adjustment module, a dynamic multi-scale feature fusion module, and a dynamic energy optimization module; A sample generation module is configured to input training data into the dynamic distribution boundary adjustment module and generate enhanced samples that satisfy global semantic alignment and local detail offset optimization through a generative adversarial network to expand the distribution boundary; the training data comes from a training dataset constructed from in-distribution data and auxiliary out-of-distribution data, and the weights of global and local distribution modeling are adjusted through a dynamic weight strategy to achieve hierarchical boundary modeling; wherein global semantic alignment is constrained by the Wasserstein distance, and local detail offset optimization is constrained by the Sinkhorn distance; a feature fusion module, configured to input the enhanced sample into the dynamic multi-scale feature fusion module, extract global features and local features, dynamically calculate fusion weights based on the distribution difference between the global features and the local features, and fuse the global features and the local features based on the fusion weights to generate fused features; the fusion weights are allocated based on the ratio of the Wasserstein distance to the Sinkhorn distance, and noise interference is suppressed by a covariance consistency regularization term; A decision and feedback module is configured to input the fusion features into the dynamic energy optimization module, calculate the energy value through the energy function, and dynamically adjust the classification threshold using a closed-loop feedback mechanism; and apply the energy loss gradient to the dynamic distribution boundary adjustment module and the dynamic multi-scale feature fusion module for parameter adjustment; The sample recognition module is used to obtain the image to be detected, input the image to be detected into the out-of-distribution sample detection model to perform OOD sample recognition, and output the recognition result.

Citation Information

Patent Citations

  • New intention recognition method, training method and device of distributed external monitoring model, and electronic equipment

    CN116702048A

  • Multi-modal data-driven education large model distribution external detection method and multi-modal data-driven education large model distribution external detection system

    CN119339398A