A robust out-of-distribution data detection method and device, a terminal and a storage medium
By constructing a target autoencoder to filter hidden layer neuron nodes and using reconstruction error values to determine the data to be detected, the problem that existing autoencoder methods are difficult to detect low-complexity OOD data is solved, and more robust OOD detection is achieved.
Patent Information
- Application Number
- CN202210582711.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-26
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2042-05-26
AI Technical Summary
Existing OOD detection methods based on autoencoders lack interpretability, making it difficult to detect OOD data with image complexity lower than that of the ID training data.
By constructing a target autoencoder, the hidden layer neuron nodes are pre-screened, and only the neuron nodes that represent the first feature in the data to be detected with a content ratio less than a preset value are retained. The reconstruction error value is used to determine whether the data to be detected is out-of-distribution data.
It enhances the robustness of OOD detection, effectively detects OOD data that is difficult to detect by existing methods, and improves the interpretability of OOD detection.
Smart Images

Figure CN114936628B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data detection, and more particularly to a robust method, apparatus, terminal, and storage medium for detecting distributed out-of-region data. Background Technology
[0002] In recent years, deep learning methods, represented by neural networks, have been widely applied in complex tasks such as image classification, tracking, and segmentation. However, machine learning models typically rely on a common assumption: that training and test data samples must come from the same distribution. When the distribution of the test data differs from that of the training data, it affects model performance and reliability. In practical applications, however, after a model is deployed, it may encounter out-of-distribution (OOD) samples from a different source than the in-distribution samples seen during training. For example, in autonomous driving, the driving scenario may shift from an urban setting to a rural setting, potentially capturing previously unseen roads and pedestrians. To ensure safe decision-making, abnormal out-of-distribution (OOD) samples should be identified promptly, an alert issued, and appropriate adjustments made by designated personnel.
[0003] However, existing neural network classification models still tend to categorize OOD image samples into an incorrect in-distribution (ID) data category. Moreover, these models often assign high confidence scores to these samples [Nguyen A, 2015]. This is not merely a simple misclassification problem; it reveals the inherent lack of interpretability in deep neural networks. Because humans cannot characterize the specific behavior of a network, such as the features extracted at each layer, it is difficult to provide concrete analysis and targeted solutions for this phenomenon of networks making highly confident but incorrect judgments about certain OOD data. In fields with high model security requirements, this problem can have serious consequences. Therefore, it is necessary to add an OOD detector before the classification decision model, and to have the detected OOD data processed by a specialist, while the classification model is only allowed to make normal decisions on ID data. In short, the detection of OOD data is of great significance for the application and deployment of neural network models.
[0004] Existing OOD detection methods typically require a certain amount of real or artificially generated OOD data, which is then combined with ID data to train the detection model. However, real OOD data is often unavailable during the training phase, so some existing works require artificially generated OOD data. However, artificially generated OOD data may limit the detection algorithm's ability to detect different types of OOD data. Therefore, some recent OOD detection research tends to construct self-supervised algorithms that do not rely on any OOD information. One type of method uses autoencoders. Compared to other self-supervised detectors, such as generative model-based methods, these methods are less energy-intensive and do not require any assumptions about the distribution of the training data.
[0005] An autoencoder is a self-supervised model that learns automatically from data samples. It learns representations of the input information by using the input information as the learning target. These methods achieve detection by comparing reconstruction errors on test data. Their basic assumption is that an autoencoder trained on ID data should reconstruct data more similar to the ID data better, and samples with larger reconstruction errors are more likely to be OOD (Out-of-Depth) data. However, this assumption is not always valid. Features learned by the autoencoder can still reconstruct OOD data well through different combinations. Especially for OOD data with image complexity far lower than ID data, existing autoencoders can even achieve lower reconstruction errors than ID data.
[0006] Therefore, existing OOD detection methods based on autoencoders lack interpretability, making it difficult to detect certain types of OOD data. Summary of the Invention
[0007] The technical problem to be solved by the present invention is to provide a robust out-of-distribution data detection method, device, terminal and storage medium to address the above-mentioned deficiencies of the prior art. The aim is to solve the problem that the existing OOD detection methods based on autoencoders lack interpretability, making it difficult to detect specific types of OOD data, such as images with lower complexity than ID training data.
[0008] The technical solution adopted by this invention to solve the problem is as follows:
[0009] In a first aspect, embodiments of the present invention provide a robust out-of-distribution data detection method, wherein the method includes:
[0010] Obtain the data to be detected, wherein the data to be detected is located in the test dataset, and the test dataset includes the test data corresponding to the target model;
[0011] The data to be detected is input into the target autoencoder to obtain the reconstructed data output by the target autoencoder based on the data to be detected. The hidden layer corresponding to the target autoencoder includes several target neuron nodes, and the several target neuron nodes are used to characterize the first feature in the data to be detected whose content proportion is less than a preset value.
[0012] Obtain the reconstruction error value between the data to be detected and the reconstructed data. When the reconstruction error value is greater than the reconstruction error threshold, determine that the data to be detected is out-of-distribution data. The out-of-distribution data and the training dataset belong to different sources. The training dataset includes the training data corresponding to the target model.
[0013] In one implementation, the target autoencoder is pre-built, and the construction process of the target autoencoder includes:
[0014] Obtain a sequential autoencoder, wherein the hidden layer corresponding to the sequential autoencoder includes a plurality of neuron nodes;
[0015] Based on the order position corresponding to the plurality of neuron nodes, the plurality of neuron nodes are divided into deletion neuron nodes and target neuron nodes, wherein the deletion neuron nodes are used to characterize the second feature in the data to be detected whose content proportion is greater than or equal to the preset value;
[0016] The deleted neuron node is removed from the hidden layer corresponding to the sequential autoencoder to obtain the target autoencoder.
[0017] In one implementation, the sequential autoencoder is pre-built, and the construction process of the sequential autoencoder includes:
[0018] Obtain a standard autoencoder and reset the parameters of the decoder corresponding to the standard autoencoder, wherein the standard autoencoder has been pre-trained;
[0019] A new neuron node is added to the hidden layer corresponding to the standard autoencoder to obtain an updated autoencoder, wherein the newly added neuron node is connected to the encoder and decoder corresponding to the standard autoencoder respectively.
[0020] The training data in the training dataset is input into the update autoencoder;
[0021] Obtain the training reconstruction data output by the updated autoencoder based on the training data, and adjust the network parameters to be adjusted of the updated autoencoder according to the training data and the training reconstruction data, wherein the network parameters to be adjusted are the parameters of the decoder corresponding to each neuron node in the hidden layer of the updated autoencoder and the parameters of the encoder corresponding to the newly added neuron node.
[0022] The updated autoencoder is then used as the standard autoencoder again. The process of adding a neuron node to the hidden layer corresponding to the standard autoencoder is repeated until the preset training conditions are met, so as to obtain the trained sequential autoencoder.
[0023] In one implementation, adjusting the network parameters to be adjusted for the updated autoencoder based on the training data and the training reconstruction data includes:
[0024] Calculate the loss function value corresponding to the updated autoencoder based on the training data and the training reconstruction data;
[0025] The update autoencoder is backpropagated based on the loss function value to adjust the network parameters to be adjusted.
[0026] In one embodiment, the standard autoencoder is trained based on an initial autoencoder, wherein the number of neurons in the hidden layer corresponding to the initial autoencoder is 1, and the training process corresponding to the standard autoencoder is used to update the parameters of the encoder and decoder in the initial autoencoder.
[0027] In one embodiment, dividing the plurality of neuron nodes into deleted neuron nodes and target neuron nodes according to the order positions corresponding to the plurality of neuron nodes respectively includes:
[0028] Obtain the reconstruction error values corresponding to each of the aforementioned neuron nodes;
[0029] Based on the reconstruction error values corresponding to the aforementioned neuron nodes, a target sequence position is determined, wherein the fluctuation change of the reconstruction error value of each neuron node after the target sequence position is less than a preset change threshold.
[0030] Based on the target sequence position, the plurality of neuron nodes are divided into deleted neuron nodes and target neuron nodes, wherein the sequence position of the deleted neuron node is less than the target sequence position, and the sequence position of the target neuron node is greater than or equal to the target sequence position.
[0031] In one embodiment, the method for determining the reconstruction error threshold includes:
[0032] Each training data point in the training dataset is input into the target autoencoder to obtain the reconstruction error value corresponding to each training data point in the training dataset.
[0033] The reconstruction error threshold is determined based on the reconstruction error value and preset percentile corresponding to each training data in the training dataset.
[0034] Secondly, embodiments of the present invention also provide a robust out-of-distribution data detection device, wherein the device includes:
[0035] An acquisition module is used to acquire data to be detected, wherein the data to be detected is located in a test dataset, and the test dataset includes test data corresponding to the target model;
[0036] The input module is used to input the data to be detected into the target autoencoder and obtain the reconstructed data output by the target autoencoder based on the data to be detected. The hidden layer corresponding to the target autoencoder includes a plurality of target neuron nodes, and the plurality of target neuron nodes are used to characterize a first feature in the data to be detected whose content proportion is less than a preset value.
[0037] The determination module is used to obtain the reconstruction error value between the data to be detected and the reconstructed data. When the reconstruction error value is greater than the reconstruction error threshold, the data to be detected is determined to be out-of-distribution data. The out-of-distribution data and the training dataset belong to different sources. The training dataset includes the training data corresponding to the target model.
[0038] Thirdly, embodiments of the present invention also provide a terminal, wherein the terminal includes a memory and one or more processors; the memory stores one or more programs; the programs include instructions for executing the robust out-of-distribution data detection method as described above; and the processor is used to execute the programs.
[0039] Fourthly, embodiments of the present invention also provide a computer-readable storage medium storing a plurality of instructions, wherein the instructions are adapted to be loaded and executed by a processor to implement the steps of any of the robust out-of-distribution data detection methods described above.
[0040] The beneficial effects of this invention are as follows: The hidden layer neurons of the target autoencoder in this invention are pre-screened, retaining only the neurons used to characterize the first feature whose content proportion in the data to be detected is less than a preset value. Therefore, it can effectively detect OOD data that is difficult to detect by existing OOD detection methods based on autoencoders, thus enhancing the robustness of OOD detection. It also solves the problem that existing OOD detection methods based on autoencoders lack interpretability, making it difficult to detect specific types of OOD data. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0042] Figure 1 This is a flowchart illustrating the robust out-of-distribution data detection method provided in this embodiment of the invention.
[0043] Figure 2 This is a flowchart illustrating the process of adding a new neuron node according to an embodiment of the present invention.
[0044] Figure 3 This is a schematic diagram of the training process of the sequential autoencoder provided in an embodiment of the present invention.
[0045] Figure 4 This is a schematic diagram of the internal structure of the sequential autoencoder when adding new neuron nodes, provided in an embodiment of the present invention.
[0046] Figure 5 This is a flowchart of the training phase of an OOD detector based on a sequential autoencoder provided in an embodiment of the present invention.
[0047] Figure 6 This is a flowchart of the testing phase of the OOD detection model based on a sequential autoencoder provided in an embodiment of the present invention.
[0048] Figure 7 This is a schematic diagram of the internal modules of the robust distributed out-of-systems data detection device provided in an embodiment of the present invention.
[0049] Figure 8 This is a schematic diagram of the terminal provided in the embodiment of the present invention. Detailed Implementation
[0050] This invention discloses a robust method, apparatus, terminal, and storage medium for detecting out-of-distribution data. To make the objectives, technical solutions, and effects of this invention clearer and more explicit, the invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only for explaining the invention and are not intended to limit the invention.
[0051] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this specification means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.
[0052] It will be understood by those skilled in the art that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0053] To address the aforementioned deficiencies of existing technologies, this invention provides a robust out-of-distribution (OOD) data detection method. The method involves: acquiring data to be detected, wherein the data to be detected is located in a test dataset, and the test dataset includes test data corresponding to a target model; inputting the data to be detected into a target autoencoder to obtain reconstructed data output by the target autoencoder based on the data to be detected; wherein the hidden layer of the target autoencoder includes several target neuron nodes, which are used to represent a first feature in the data to be detected whose content proportion is less than a preset value; obtaining a reconstruction error value between the data to be detected and the reconstructed data; and determining that the data to be detected is out-of-distribution data when the reconstruction error value is greater than a reconstruction error threshold, wherein the out-of-distribution data and the training dataset belong to different sources, and the training dataset includes the training data corresponding to the target model. In this invention, the hidden layer neuron nodes of the target autoencoder are pre-screened, retaining only the neuron nodes used to represent the first feature in the data to be detected whose content proportion is less than a preset value. Therefore, it can effectively detect OOD data that is difficult for existing autoencoder-based OOD detection methods to find, enhancing the robustness of OOD detection. This solves the problem that existing OOD detection methods based on autoencoders lack interpretability, making it difficult to detect specific types of OOD data.
[0054] like Figure 1 As shown, the method includes the following steps:
[0055] Step S100: Obtain the data to be detected, wherein the data to be detected is located in the test dataset, and the test dataset includes the test data corresponding to the target model.
[0056] Specifically, the target model in this embodiment can be any machine learning model, which can be used to perform classification, tracking, or segmentation tasks. Ideally, the training and test datasets corresponding to the target model should come from the same distribution; otherwise, the performance and reliability of the target model will be affected. However, in practical applications, out-of-distribution data may appear in the test dataset. Therefore, to ensure the performance and reliability of the target model, this embodiment needs to perform robust out-of-distribution detection on the test data in the test dataset to ensure that out-of-distribution data in the test dataset is detected in a timely manner. Therefore, any test data in the test dataset can be used as the data to be detected in this embodiment.
[0057] like Figure 1 The method further includes the following steps:
[0058] Step S200: Input the data to be detected into the target autoencoder and obtain the reconstructed data output by the target autoencoder based on the data to be detected. The hidden layer corresponding to the target autoencoder includes several target neuron nodes, and the several target neuron nodes are used to characterize the first feature in the data to be detected whose content proportion is less than a preset value.
[0059] Specifically, to achieve robust out-of-distribution data detection, this embodiment pre-constructs a target autoencoder. The hidden layer neurons in this target autoencoder are pre-selected, retaining only those target neurons used to represent the first feature whose content proportion in the data to be detected is less than a preset value. Therefore, compared to traditional autoencoders, the target autoencoder in this embodiment has stronger interpretability and can identify out-of-distribution data of varying complexity. In practical applications, the data to be detected is input into the target autoencoder, and the hidden layer of the target autoencoder performs representation learning on the data to be detected, outputting the reconstructed data corresponding to the data to be detected.
[0060] In one implementation, the target autoencoder is pre-built, and the construction process of the target autoencoder includes:
[0061] Step S10: Obtain the sequential autoencoder, wherein the hidden layer corresponding to the sequential autoencoder includes a number of neuron nodes;
[0062] Step S20: According to the order position corresponding to the plurality of neuron nodes respectively, the plurality of neuron nodes are divided into deletion neuron nodes and target neuron nodes, wherein the deletion neuron nodes are used to characterize the second feature in the data to be detected whose content proportion is greater than or equal to the preset value.
[0063] Step S30 removes the deleted neuron node from the hidden layer corresponding to the sequential autoencoder to obtain the target autoencoder.
[0064] In simple terms, the target autoencoder in this embodiment is built on the framework of the sequential autoencoder. The difference between the target autoencoder and the sequential autoencoder lies in the hidden layers; the hidden layers of the target autoencoder are obtained by pruning the hidden layers of the sequential autoencoder. Specifically, the sequential autoencoder in this embodiment has a sequential advantage, characterized by the decreasing significance of hidden layer neurons in the reconstruction task. Neurons with earlier positions in the sequence contain representational information that is more helpful in quickly reducing reconstruction errors, such as large areas of image background and contour information. During training, only after the neurons with earlier positions in the sequence have sufficiently represented the second feature with a content proportion greater than or equal to the preset value can the neurons with later positions focus on capturing the first feature information with a content proportion less than the preset value. The neurons with later positions in the sequence contain more representative detailed information in the training (ID) image, and are also more meaningful information for OOD image detection. Therefore, this embodiment classifies the neurons in the hidden layer of the sequential autoencoder into deleted neurons and target neurons based on the different representation learning types. Deleted neurons, corresponding to the earlier neurons, are used to represent the second feature whose content proportion in the data to be detected is greater than or equal to the preset value. Target neurons, corresponding to the later neurons, are used to represent the first feature whose content proportion in the data to be detected is less than the preset value. For OOD images, which are more complex and have more detailed information than ID images, the representations corresponding to both earlier and later neurons can provide good discriminative power. However, for OOD images, which are less complex and have less detailed information than ID images, the representations corresponding to later neurons contain more discriminative information; conversely, earlier neurons may be misleading. Therefore, this embodiment deletes all the earlier neurons (i.e., deleted neurons) in the hidden layer of the sequential autoencoder, retaining only the later neurons (i.e., target neurons), thus obtaining the target autoencoder. Because the target autoencoder uses later neurons to construct a sub-feature space to reconstruct the input data, it can achieve a more robust OOD detection effect.
[0065] In one implementation, the sequential autoencoder is pre-built, and the construction process of the sequential autoencoder includes:
[0066] Step S11: Obtain a standard autoencoder and reset the parameters of the decoder corresponding to the standard autoencoder, wherein the standard autoencoder has been pre-trained;
[0067] Step S12: Add a new neuron node to the hidden layer corresponding to the standard autoencoder to obtain the updated autoencoder, wherein the newly added neuron node is connected to the encoder and decoder corresponding to the standard autoencoder respectively.
[0068] Step S13: Input the training data from the training dataset into the update autoencoder;
[0069] Step S14: Obtain the training reconstruction data output by the updated autoencoder based on the training data, and adjust the network parameters to be adjusted of the updated autoencoder according to the training data and the training reconstruction data, wherein the network parameters to be adjusted are the parameters of the decoder corresponding to each neuron node in the hidden layer of the updated autoencoder and the parameters of the encoder corresponding to the newly added neuron node.
[0070] Step S15: Continue to add a neuron node to the hidden layer corresponding to the standard autoencoder to obtain the updated autoencoder, until the preset training conditions are met, so as to obtain the trained sequential autoencoder.
[0071] In simple terms, this embodiment uses a pre-trained standard autoencoder to construct a sequential autoencoder. One neuron node is added sequentially to the hidden layer of the standard autoencoder, and training is performed on the standard autoencoder after each new neuron node is added, until a preset training condition is met. At this point, adding more neurons stops, and the final trained standard autoencoder is used as the sequential autoencoder. It should be noted that the generation process of the sequential autoencoder uses a special training method different from the conventional training method. Conventional training usually updates the parameters of both the encoder and decoder connected to each neuron node in the autoencoder. However, the special training method in this embodiment updates only the parameters of the decoder corresponding to each newly added neuron node in the hidden layer and the parameters of the encoder of the newly added neuron node (e.g., ...). Figure 2 As shown). Specifically, as Figure 4As shown, after obtaining the standard autoencoder, an independent neuron node is added to the original hidden layer of the standard autoencoder, and its connection to the encoder and decoder of the standard autoencoder is established, thus obtaining an updated autoencoder. The encoder parameters of each previously trained neuron node in the hidden layer of the updated autoencoder are frozen, and the frozen parameters are not updated in subsequent training. The decoder parameters of each neuron node in the hidden layer of the updated autoencoder are reset, and then the updated encoder is iteratively trained using the training dataset. In each iteration, only the decoder parameters corresponding to each neuron node in the hidden layer and the encoder parameters of the newly added neuron node are updated. The training steps are executed repeatedly until the preset training conditions are met. After training, a sequential autoencoder is obtained, which includes an encoder h = f(·) and a decoder r = g(h).
[0072] In another implementation, the construction process of the sequential autoencoder includes:
[0073] Obtain a traditional autoencoder, wherein the traditional autoencoder is an autoencoder trained based on a traditional training method, and the hidden layer nodes of the traditional autoencoder are set to M (i.e., the maximum value of the hidden layer dimension range of the sequential autoencoder);
[0074] By sequentially deleting one of the M hidden layer neurons, we obtain M sub-encoders with a hidden layer dimension of M-1;
[0075] The training samples are input into each sub-encoder in sequence to obtain the reconstructed samples corresponding to each sub-encoder;
[0076] The average reconstruction error is calculated based on the reconstruction samples corresponding to each sub-encoder. The hidden layer neurons missing by the sub-encoder with the largest average reconstruction error are taken as the first sequence neurons of the hidden layer of the sequential autoencoder, and their corresponding encoder and decoder nodes and connection weights are retained.
[0077] The process of sequentially deleting one node at a time is repeated on the sub-encoder with the largest average reconstruction error and a hidden layer dimension of M-1. The nodes are then sorted according to their reconstruction errors, and sequentially selected from the hidden layers of the sequential autoencoder until a preset training condition is triggered. This results in a sequential autoencoder containing an encoder h = f(·) and a decoder r = g(h).
[0078] It should be noted that the second sequential autoencoder construction method provided in this embodiment can only select and combine a given set of M hidden layer neurons, which limits its interpretability compared to the first construction method. However, the second construction method has lower computational complexity and time cost, and is easier to implement in certain situations, such as when a traditional autoencoder is already provided.
[0079] In one implementation, the preset training conditions can be determined based on the number of hidden layer nodes. For example, it can be determined whether the number of hidden layer nodes has reached a preset value. If it has, training ends; if not, training continues. The preset value can be different depending on the input dataset, or determined by combining industry expert knowledge and experience. For example, if the preset value is 1, the number of hidden layer neurons is equal to 1, and training can be considered to have ended; if the preset value is m, the number of hidden layer neurons is equal to 1, and m > 1, then training continues. Typically, autoencoders are lossy, meaning the number of hidden layer nodes is less than the dimension of the input features.
[0080] In another implementation, the preset training conditions can also be determined based on the reconstruction error value corresponding to the updated autoencoder. For example, it can be determined whether the reconstruction error is less than a preset value. If it is less, the training ends; if it is greater than or equal to the preset value, the training continues.
[0081] In one implementation, step S14 specifically includes the following steps:
[0082] Step S141: Calculate the loss function value corresponding to the updated autoencoder based on the training data and the training reconstruction data;
[0083] Step S142: Perform backpropagation on the update autoencoder based on the loss function value to adjust the network parameters to be adjusted.
[0084] Specifically, such as Figure 3 As shown, since the updating autoencoder is not fully trained, there is a significant gap between its input and output. To converge the error, this embodiment calculates the loss function value of the updating autoencoder based on the training data and the training reconstruction data, and uses the loss function value as a guide to perform backpropagation on the updating autoencoder to adjust the network parameters that are not frozen in the updating autoencoder.
[0085] In one implementation, the standard autoencoder is trained based on an initial autoencoder, wherein the number of neurons in the hidden layer corresponding to the initial autoencoder is 1, and the training process corresponding to the standard autoencoder is used to update the parameters of the encoder and decoder in the initial autoencoder.
[0086] In simple terms, the standard autoencoder in this embodiment is obtained by conventionally training an initial autoencoder. During training, the parameters of both the encoder and decoder of the initial autoencoder need to be updated. Specifically, the training process of the initial autoencoder first iterates based on a given input dataset (i.e., the training dataset / in-distribution dataset): the input data propagates forward layer by layer through the encoder, decoder, and other structures in the initial autoencoder (e.g., including convolutional layers, downsampling layers, fully connected layers, etc.) until the output value of the initial autoencoder is obtained. Then, the reconstruction error value between the input and output values is calculated, and the gradient of the initial autoencoder is calculated. The reconstruction error value is then backpropagated back to the parameters of the initial autoencoder to update the weights of the initial autoencoder. Iteration continues until the training termination requirement is met, such as reaching a certain number of pre-set iterations or an error convergence range. The initial autoencoder after training is the standard autoencoder. It should be noted that the initial autoencoder, like the traditional autoencoder, also includes conventional designs such as an encoder, decoder, and loss objective function. Taking a convolutional neural network (CNN)-based autoencoder as an example, when building the initial autoencoder, it is necessary to determine parameters such as the number of channels, number of layers, convolutional kernels, padding, stride, and activation function of the CNNs in the encoder and decoder. For example, when the initial autoencoder processes color image data, the number of input channels of the convolutional layer directly connected to the input layer is 3 (because it contains the R, G, and B color matrices). After construction, if the initial autoencoder uses a rectified linear unit (ReLU) as the neuron activation function, the parameters of the initial autoencoder can be initialized using the Kaiming initialization method suitable for ReLU networks. The difference between the initial autoencoder and a traditional autoencoder is that the number of neurons in the hidden layer of the initial autoencoder is 1, that is, the number of output channels of the convolutional layer connected to the encoder and hidden layer in the initial autoencoder is 1. In one implementation, the loss objective function and gradient optimization algorithm of the initial autoencoder can be combined and selected according to the focus of OOD detection, such as the most basic minimization of reconstruction error (i.e., mean squared error), or simultaneously adding category information, covariance error, coupling error, etc. Gradient optimization algorithms can employ methods such as the Adam method.
[0087] In one implementation, step 20 specifically includes the following steps:
[0088] Step S201: Obtain the reconstruction error values corresponding to the plurality of neuron nodes respectively;
[0089] Step S202: Determine the target sequence position based on the reconstruction error values corresponding to the several neuron nodes respectively, wherein the fluctuation change of the reconstruction error value of each neuron node after the target sequence position is less than a preset change threshold.
[0090] Step S203: According to the target sequence position, divide the plurality of neuron nodes into deleted neuron nodes and target neuron nodes, wherein the sequence position of the deleted neuron node is less than the target sequence position, and the sequence position of the target neuron node is greater than or equal to the target sequence position.
[0091] Specifically, in this embodiment, neurons with earlier sequence positions are designated as deleted neurons, while those with later sequence positions are designated as target neurons to be retained. Therefore, this embodiment sets a target sequence position, defining neurons before the target sequence position as neurons with earlier sequence positions and neurons after the target sequence position as neurons with later sequence positions. The selection of the target sequence position is determined based on the reconstruction error value corresponding to each neuron node. Taking a single neuron node as an example, the error value between the input and output data of the autoencoder after adding the neuron node during the construction of the sequential autoencoder is obtained, thus yielding the reconstruction error value corresponding to that neuron node. As the sequence position increases, the reconstruction error values corresponding to each neuron gradually stabilize. This embodiment uses the sequence position corresponding to the neuron node whose reconstruction error value begins to stabilize as the target sequence position. Therefore, the fluctuation of the reconstruction error value of neurons after the target sequence position is smaller, i.e., the fluctuation is less than a preset threshold.
[0092] It's important to note that traditional autoencoders tend to require the model to accurately reconstruct the input at the pixel level. However, the representation space most favorable for reconstruction is not necessarily the most favorable for OOD detection. An autoencoder that can reconstruct complex images well can also achieve pixel-level accuracy in simple images, leading to the inability to correctly detect OOD data with low image complexity. While image reconstruction and OOD detection are related, they are not equivalent. The goal of image reconstruction is to minimize the reconstruction error of the test image, while the goal of OOD detection is to maximize the difference in reconstruction errors between ID data and OOD data. However, due to the black-box nature of neural networks, it's impossible to determine which nodes or layers have a greater impact on the target task, thus making it impossible to extract the most suitable feature space for a given task. Therefore, this embodiment prunes the neurons in the hidden layers of the sequential autoencoder, retaining only the later neurons, thereby giving the hidden space more concrete interpretable meaning and obtaining a sub-feature space more suitable for completing the OOD detection task. Features within this space are then used to reconstruct the samples.
[0093] In another implementation, a line graph can be drawn based on the reconstruction error value corresponding to each neuron node. The horizontal axis of the line graph is used to reflect each neuron node, and the vertical axis is used to reflect the reconstruction error value corresponding to each neuron node. Based on the line graph, the neuron nodes whose reconstruction error values tend to stabilize (i.e., the fluctuation change is less than the preset change threshold) are determined, and these neuron nodes are taken as target neuron nodes.
[0094] In another implementation, the target sequence position can also be determined by retaining a fixed number or a fixed proportion of neuron nodes. For example, the last 1 / 3 of the neuron nodes can be pre-set as the target neuron nodes, and the target sequence position can be calculated accordingly.
[0095] like Figure 1 As shown, the method further includes the following steps:
[0096] Step S300: Obtain the reconstruction error value between the data to be detected and the reconstructed data. When the reconstruction error value is greater than the reconstruction error threshold, determine that the data to be detected is out-of-distribution data. The out-of-distribution data and the training dataset belong to different sources. The training dataset includes the training data corresponding to the target model.
[0097] Specifically, since the target autoencoder is trained on a training dataset, it will reconstruct data from the same distribution as the training dataset better, meaning the reconstruction error between the input and output data will be smaller; conversely, it will reconstruct data from a different distribution than the training dataset poorly, meaning the reconstruction error between the input and output data will be larger. For example... Figure 6 As shown, by obtaining the reconstruction error value between the data to be detected and its corresponding reconstructed data, if the reconstruction error value is greater than the preset reconstruction error threshold, the data to be detected is determined to be out-of-distribution data; if the reconstruction error value is less than or equal to the reconstruction error threshold, the data to be detected is determined to be in-distribution data.
[0098] In one implementation, the method for determining the reconstruction error threshold includes:
[0099] Step S40: Input each training data in the training dataset into the target autoencoder to obtain the reconstruction error value corresponding to each training data in the training dataset.
[0100] Step S41: Determine the reconstruction error threshold based on the reconstruction error value and preset percentile corresponding to each training data in the training dataset.
[0101] Specifically, for each training data point in the training dataset, the training data is input into the target autoencoder. The hidden layers of the target autoencoder reconstruct the training data, obtaining the corresponding reconstructed data. For example, if the function h*=f*(x) represents the pruned encoder and r*=g*(h*) represents the decoder, then for data x, the generated reconstructed data can be expressed as x'=g*(f*(x)). Then, based on the training data and its corresponding reconstructed data, the reconstruction error value corresponding to the training data is calculated. Figure 5 As shown, the reconstruction error values corresponding to each training data point are recorded. Then, a percentile method is used to determine the reconstruction error threshold based on the reconstruction error values corresponding to each training data point. For example, the reconstruction error values corresponding to each training data point are arranged in ascending order, and the p-th percentile is calculated. The number corresponding to the p-th percentile is used as the reconstruction error threshold. In another implementation, a suitable reconstruction error threshold can be found directly by combining knowledge from other domains. The target autoencoder in this embodiment can better capture the nonlinear manifold in the input image, thereby improving the detection performance on various types of OOD (especially OODs with different image complexities).
[0102] Based on the above embodiments, the present invention also provides a robust out-of-distribution data detection device, such as... Figure 7 As shown, the device includes:
[0103] The acquisition module 01 is used to acquire the data to be detected, wherein the data to be detected is located in the test dataset, and the test dataset includes the test data corresponding to the target model;
[0104] Input module 02 is used to input the data to be detected into the target autoencoder and obtain the reconstructed data output by the target autoencoder based on the data to be detected. The hidden layer corresponding to the target autoencoder includes a plurality of target neuron nodes, and the plurality of target neuron nodes are used to characterize a first feature in the data to be detected whose content proportion is less than a preset value.
[0105] The determination module 03 is used to obtain the reconstruction error value between the data to be detected and the reconstructed data. When the reconstruction error value is greater than the reconstruction error threshold, the data to be detected is determined to be out-of-distribution data. The out-of-distribution data and the training dataset have different sources. The training dataset includes the training data corresponding to the target model.
[0106] Based on the above embodiments, the present invention also provides a terminal, the principle block diagram of which can be as follows: Figure 8As shown, the terminal includes a processor, memory, network interface, and display screen connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a robust off-grid data detection method. The display screen can be a liquid crystal display (LCD) or an e-ink display.
[0107] Those skilled in the art will understand that Figure 8 The schematic diagram shown is merely a partial structural diagram related to the present invention and does not constitute a limitation on the terminal to which the present invention is applied. A specific terminal may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0108] In one implementation, the terminal's memory stores one or more programs, and is configured to be executed by one or more processors, the one or more programs containing instructions for performing a robust out-of-distribution data detection method.
[0109] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0110] In summary, this invention discloses a robust out-of-distribution (OOD) data detection method, apparatus, terminal, and storage medium. The method involves acquiring data to be detected, wherein the data is located in a test dataset, which includes test data corresponding to a target model; inputting the data to be detected into a target autoencoder to obtain reconstructed data output by the target autoencoder based on the data to be detected, wherein the hidden layer of the target autoencoder includes several target neuron nodes, which are used to represent a first feature in the data to be detected whose content proportion is less than a preset value; obtaining a reconstruction error value between the data to be detected and the reconstructed data; and determining that the data to be detected is out-of-distribution data when the reconstruction error value is greater than a reconstruction error threshold, wherein the out-of-distribution data and the training dataset belong to different sources, and the training dataset includes the training data corresponding to the target model. The hidden layer neuron nodes of the target autoencoder in this invention are pre-screened, retaining only the neuron nodes used to represent the first feature in the data to be detected whose content proportion is less than a preset value. Therefore, it can effectively detect OOD data that is difficult to detect by existing autoencoder-based OOD detection methods, enhancing the robustness of OOD detection. This solves the problem that existing OOD detection methods based on autoencoders lack interpretability, making it difficult to detect specific types of OOD data.
[0111] It should be understood that the application of the present invention is not limited to the examples above. Those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.
Claims
1. A method for detecting out-of-distribution data, characterized in that, The method comprises: acquiring to-be-detected data, wherein the to-be-detected data is located in a test data set, and the test data set comprises test data corresponding to a target model; inputting the to-be-detected data into a target autoencoder to acquire reconstruction data output by the target autoencoder based on the to-be-detected data, wherein a hidden layer corresponding to the target autoencoder comprises a plurality of target neuron nodes, and the plurality of target neuron nodes are used to represent first features in the to-be-detected data with a content proportion less than a preset value; acquiring a reconstruction error value between the to-be-detected data and the reconstruction data, and judging that the to-be-detected data is out-of-distribution data when the reconstruction error value is greater than a reconstruction error threshold, wherein the out-of-distribution data and a training data set correspond to different sources respectively, and the training data set comprises training data corresponding to the target model; the target model is a machine learning model, and is used to perform a classification task, a tracking task or a segmentation task; the target autoencoder is constructed based on a framework of a sequential autoencoder; the first features contain detailed information of in-distribution images in training data, so as to detect out-of-distribution images; the target autoencoder is pre-constructed, and a construction process of the target autoencoder comprises: acquiring a sequential autoencoder, wherein a hidden layer corresponding to the sequential autoencoder comprises a plurality of neuron nodes; dividing the plurality of neuron nodes into deleted neuron nodes and the target neuron nodes according to sequential positions of the plurality of neuron nodes respectively, wherein the deleted neuron nodes are used to represent second features in the to-be-detected data with a content proportion greater than or equal to the preset value; deleting the deleted neuron nodes from the hidden layer corresponding to the sequential autoencoder to obtain the target autoencoder; the sequential autoencoder is pre-constructed, and a construction process of the sequential autoencoder comprises: acquiring a standard autoencoder, and resetting parameters of a decoder corresponding to the standard autoencoder, wherein the standard autoencoder is pre-trained; adding a neuron node to a hidden layer corresponding to the standard autoencoder to obtain an updated autoencoder, wherein the added neuron node is connected to an encoder and a decoder corresponding to the standard autoencoder respectively; inputting training data in a training data set into the updated autoencoder; acquiring training reconstruction data output by the updated autoencoder based on the training data, and adjusting to-be-adjusted network parameters of the updated autoencoder according to the training data and the training reconstruction data, wherein the to-be-adjusted network parameters are parameters of a decoder corresponding to each neuron node in a hidden layer of the updated autoencoder and parameters of an encoder corresponding to the added neuron node; reusing the updated autoencoder as the standard autoencoder to continue the step of adding a neuron node to a hidden layer corresponding to the standard autoencoder to obtain an updated autoencoder until a preset training condition is met, so as to obtain a trained sequential autoencoder.
2. The method of claim 1, wherein, The adjusting the to-be-adjusted network parameter of the updated autoencoder according to the training data and the training reconstruction data comprises: calculating a loss function value corresponding to the updated autoencoder according to the training data and the training reconstruction data; performing back propagation on the updated autoencoder according to the loss function value to realize the adjusting of the to-be-adjusted network parameter.
3. The method of claim 1, wherein, The standard autoencoder is trained based on an initial autoencoder, wherein the number of neuron nodes of a hidden layer corresponding to the initial autoencoder is 1, and a training process corresponding to the standard autoencoder is used to update parameters of an encoder and a decoder in the initial autoencoder.
4. The method of claim 1, wherein, The dividing the plurality of neuron nodes into the deleted neuron nodes and the target neuron nodes according to the sequence positions corresponding to the plurality of neuron nodes comprises: obtaining reconstruction error values corresponding to the plurality of neuron nodes respectively; determining a target sequence position according to the reconstruction error values corresponding to the plurality of neuron nodes respectively, wherein fluctuation change amounts of the reconstruction error values corresponding to the neuron nodes after the target sequence position are less than a preset change threshold; dividing the plurality of neuron nodes into the deleted neuron nodes and the target neuron nodes according to the target sequence position, wherein the sequence positions of the deleted neuron nodes are less than the target sequence position, and the sequence positions of the target neuron nodes are greater than or equal to the target sequence position.
5. The method of claim 1, wherein, The method for determining the reconstruction error threshold comprises: inputting each training data in a training data set into the target autoencoder to obtain a reconstruction error value corresponding to each training data in the training data set respectively; determining the reconstruction error threshold according to the reconstruction error values corresponding to each training data in the training data set respectively and a preset percentile.
6. A distribution outside data detecting apparatus characterized by comprising: The device comprises: an obtaining module configured to obtain to-be-detected data, wherein the to-be-detected data is located in a test data set, and the test data set comprises test data corresponding to a target model; an inputting module configured to input the to-be-detected data into a target autoencoder to obtain reconstruction data output by the target autoencoder based on the to-be-detected data, wherein a hidden layer corresponding to the target autoencoder comprises a plurality of target neuron nodes, and the plurality of target neuron nodes are used to represent a first feature with a content proportion less than a preset value in the to-be-detected data; a determining module configured to obtain a reconstruction error value between the to-be-detected data and the reconstruction data, and determine that the to-be-detected data is out-of-distribution data when the reconstruction error value is greater than a reconstruction error threshold, wherein the out-of-distribution data and training data in a training data set correspond to different sources respectively, and the training data set comprises training data corresponding to the target model; the target model is a machine learning model used to perform a classification task, a tracking task, or a segmentation task; the target autoencoder is constructed based on a framework of a sequential autoencoder; the first feature contains detailed information of an in-distribution image in training data to detect an out-of-distribution image; the target autoencoder is constructed in advance, and a construction process of the target autoencoder comprises: An acquisition sequence auto-encoder, wherein the sequence auto-encoder corresponds to a hidden layer including a plurality of neuron nodes; According to a plurality of sequence bits corresponding to the plurality of neuron nodes, the plurality of neuron nodes are divided into deletion neuron nodes and target neuron nodes, wherein the deletion neuron nodes are used to represent a second feature in the to-be-detected data, and a content proportion of the second feature is greater than or equal to the preset value; The deletion neuron nodes are deleted from the hidden layer corresponding to the sequence auto-encoder to obtain the target auto-encoder; The sequence auto-encoder is pre-constructed, and a construction process of the sequence auto-encoder includes: An acquisition standard auto-encoder, wherein the standard auto-encoder is pre-trained; An updated auto-encoder is obtained by adding a neuron node to a hidden layer corresponding to the standard auto-encoder, wherein the added neuron node is connected to an encoder and a decoder corresponding to the standard auto-encoder, respectively; Training data in the training data set is input into the updated auto-encoder; Training reconstruction data output by the updated auto-encoder based on the training data is acquired, and a to-be-adjusted network parameter of the updated auto-encoder is adjusted according to the training data and the training reconstruction data, wherein the to-be-adjusted network parameter is a parameter of a decoder corresponding to each neuron node in a hidden layer of the updated auto-encoder and a parameter of an encoder corresponding to the added neuron node; The updated auto-encoder is re-used as the standard auto-encoder, and the step of adding a neuron node to a hidden layer corresponding to the standard auto-encoder to obtain an updated auto-encoder is continuously executed until a preset training condition is met, so as to obtain a trained sequence auto-encoder.
7. A terminal, characterized by comprising: The terminal includes a memory and one or more processors; the memory stores one or more programs; the programs include instructions for executing the out-of-distribution data detection method of any one of claims 1-5; and the processor is configured to execute the programs.
8. A computer-readable storage medium storing a plurality of instructions, characterized in that, The instructions are adapted to be loaded and executed by the processor to implement the steps of the out-of-distribution data detection method of any one of claims 1-5.
Citation Information
Patent Citations
Out-of-distribution image detection method based on uncertainty and attention enhancement of generative adversarial network
CN112668655A
Flow identification method and electronic equipment
CN113037687A