Data equalization method based on density ratio estimation, electronic equipment and storage medium
By dynamically adjusting the category weights in the deep learning model based on density ratio estimation, the problem of degradation of generalization performance of deep learning models under unbalanced data is solved, and stronger robustness and generalization capabilities are achieved.
Patent Information
- Application Number
- CN202411795130.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-05-13
AI Technical Summary
When processing unbalanced data, deep learning models tend to tend to be biased towards categories with a large number of samples, resulting in a decline in generalization performance for a few classes, and the existing technology is difficult to adapt to dynamic changes in the training process.
Through a method based on density ratio estimation, the characteristic density ratio of each category of samples is calculated in real time, and the category weight is dynamically adjusted, so as to balance the influence of various types of samples and update the parameters of the deep learning model.
It improves the robustness and generalization ability of the model, reduces the phenomenon of overfitting on most classes or underfitting on a few classes, and allows the model to more flexibly cope with changes in data distribution.
Smart Images

Figure CN119988962A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of artificial intelligence and deep learning, and in particular to a data equalization method, electronic device, and storage medium based on density ratio estimation. Background Art
[0002] With the rapid development of deep learning technology, models have made significant progress in processing large-scale data sets and complex tasks. However, data in the real world is often unbalanced and presents a long-tail distribution, that is, a few categories have a large number of samples, while most categories have less data. In the case of such an unbalanced data distribution, deep learning models tend to be biased towards categories with a large number of samples, resulting in a decrease in the generalization performance of minority classes. This problem is particularly prominent in fields such as medical diagnosis, autonomous driving, and financial risk control, because these fields usually require models to maintain high accuracy, robustness, and fairness under unbalanced data.
[0003] In order to deal with the problem of unbalanced data distribution, academia and industry have proposed a variety of solutions. Existing technologies mainly focus on two types of methods: reweighted methods and non-reweighted methods.
[0004] Although existing re-weighting-based methods improve the performance of minority classes to a certain extent, most of them rely on static weight adjustments and cannot adapt to dynamic changes during training.
[0005] Non-reweighted methods based on data sampling, such as oversampling and downsampling, can balance data distribution to a certain extent, but they also bring new problems. Oversampling may lead to overfitting of minority class samples, while downsampling may lead to information loss of majority class samples. In addition, when faced with high-dimensional data, these methods have low sampling efficiency and high computational overhead, making them difficult to apply to large-scale data sets.
[0006] In summary, existing technical solutions mostly rely on static weight adjustment or sampling strategies, which are difficult to cope with the dynamic changes in the distribution of features of each category during training. Therefore, there is an urgent need for a method that can dynamically adjust weights to ensure that the model has stronger adaptability and generalization ability on unbalanced datasets. Summary of the invention
[0007] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and to provide a data balancing method, electronic device, and storage medium based on density ratio estimation, so as to solve or partially solve the problem of performance degradation of deep learning models when processing unbalanced data.
[0008] The purpose of the present invention can be achieved by the following technical solutions:
[0009] One aspect of the present invention provides a data equalization method based on density ratio estimation, comprising the following steps:
[0010] Step S1, obtain the training data set and the deep learning model to be trained, and repeat steps S2-S3 until the target training batch is reached;
[0011] Step S2, extract the features of the samples in the training data set under the current batch, determine whether the current batch exceeds the preset critical batch, if not, configure the category weights to be equal weights, if so, based on the features of each sample under the current batch, the current feature prototype and the loss of the current batch, calculate the category weights of each category through density ratio estimation, calculate the weighted loss after obtaining the category weights, and update the parameters of the deep learning model;
[0012] Step S3: Based on the features of each sample in the current batch, the feature prototype is momentum updated.
[0013] As a preferred technical solution, the calculation of the category weights of each category by density ratio estimation is implemented based on the following formula:
[0014]
[0015] Among them, R is the sample weight, n is the total number of samples in the training data set, r(x i |y i ; ω) is the density ratio, which is defined as the ratio of the actual density of a category under an unbalanced data distribution to the assumed density under an ideal balanced distribution. is the training data set, l(x i ,y i ;ω) is the loss function, x i ,y i are sample input and corresponding category, π yi Represents y i The ratio of the total number of samples of the corresponding category to the total number of all samples, ω is the deep learning model parameter.
[0016] As a preferred technical solution, when the preset critical batch is exceeded, the category weight is calculated using the following formula:
[0017]
[0018] Among them, R is the sample weight, d is the total number of categories, Φ P =(f(x1),...,f(x n )), x i ,y i are sample input and corresponding category respectively, f() is feature extraction operator, T represents transposition, () -1 Indicates the inverse, is the current feature prototype, l(x i ,y i ; ω) is the loss function, and ω is the deep learning model parameter.
[0019] As a preferred technical solution, the momentum update of the feature prototype is implemented by the following formula:
[0020]
[0021] Among them, ← represents assignment, m is the momentum factor, is the feature prototype, represents the average value of feature z of all samples in category i.
[0022] As a preferred technical solution, in the step S2, after the category weights are calculated, the step also includes normalizing the category weights.
[0023] As a preferred technical solution, in step S2, the parameters of the deep learning model are updated by back propagation.
[0024] As a preferred technical solution, the training data set is an image data set, and the deep learning model is an image classification model.
[0025] As a preferred technical solution, the parameters of the deep learning model include feature extractor parameters and classifier parameters.
[0026] Another aspect of the present invention provides an electronic device, comprising: one or more processors and a memory, wherein the memory stores one or more programs, and the one or more programs include instructions for executing the aforementioned data equalization method based on density ratio estimation.
[0027] Another aspect of the present invention provides a computer-readable storage medium, comprising one or more programs for execution by one or more processors of an electronic device, wherein the one or more programs include instructions for executing the aforementioned data equalization method based on density ratio estimation.
[0028] Compared with the prior art, the present invention has at least the following beneficial effects:
[0029] Realize dynamic weight adjustment based on adaptive density ratio estimation: The present invention estimates the feature density ratio of samples of each category in real time, and adaptively and dynamically adjusts the category weights according to the actual distribution of different categories, so as to balance the influence of various types of samples during the training process. By adopting dynamic adaptive adjustment based on density ratio estimation, the robustness of the model can be improved. This adaptive adjustment method enables the model to respond to changes in data distribution more flexibly, significantly reducing the phenomenon of overfitting of the model on the majority class or underfitting on the minority class. Through the dynamic update of the density ratio, the model can maintain a higher generalization ability in unbalanced data scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 is a flow chart of a data equalization method based on density ratio estimation in an embodiment;
[0031] Figure 2 Schematic diagram of a data equalization algorithm framework based on density ratio estimation in an embodiment;
[0032] Figure 3 Schematic diagram of an electronic device in an embodiment. DETAILED DESCRIPTION
[0033] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are 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 creative work should fall within the scope of protection of the present invention.
[0034] Example 1
[0035] This embodiment provides a data balancing method based on density ratio estimation, which aims to solve the problem of performance degradation of deep learning models under unbalanced data. This method estimates the feature density ratio of each category in real time and dynamically adjusts the weight of each category, thereby effectively coping with the problem of unbalanced data, improving the overall performance and robustness of the model, and ensuring that the influence of minority and majority classes is balanced during the training process.
[0036] See also Figure 1 The method includes steps S1-S3, and each step is described in detail below.
[0037] Step S1, obtain the training data set and the deep learning model to be trained, initialize the model parameters and feature prototypes, and then repeat steps S2-S3 until the preset target training batch T is reached, where batch represents epoch.
[0038] In this example, given a typical classification task in imbalanced learning, the training data set is n is the total number of samples, n i and π i are the number of samples of category i and the ratio of samples to the total number, and the total number of categories is d. The deep learning model consists of a feature extractor and classifier h θ Composition, among which and θ are the parameters of the feature extractor and classifier respectively, and the total parameters of the deep learning model Feature Extractor The output is z. In this embodiment, the density ratio r is defined as the actual density P of the category under the imbalanced data distribution and the assumed density P under the ideal balanced distribution bal The basic loss function l can be any task loss function. This embodiment uses the cross entropy classification loss function and the logit adjustment loss function. It should be noted that the deep learning model can be any neural network including a convolutional layer or a residual layer.
[0039] Step S2: extract the features of the samples in the training data set under the current batch, and update the parameters of the deep learning model based on the category weights calculated by the feature prototype.
[0040] First, the model's feature extractor extracts high-dimensional feature representations from the input data to obtain the features of the samples in the training dataset under the current batch. Through these features, the category information of the captured samples and their distribution in the feature space can be characterized.
[0041] Then, determine whether the current batch exceeds the preset critical batch. If not, it is considered that the current batch is in the warm-up stage and the category weights are configured as equal weights. If so, based on the characteristics of each sample in the current batch, the current feature prototype and the loss of the current batch, the category weights of each category are calculated through density ratio estimation. After obtaining the category weights, the weighted loss is calculated to update the parameters of the deep learning model.
[0042] Specifically, during model training, the objective function to be optimized is (Formula 1):
[0043]
[0044] Based on the objective function of the above formula, in this embodiment, during the model training process, Φ P Dynamically reflects the knowledge learned from the distribution P, that is, Φ P =(f(x1),...,f(x n )).
[0045] By deducing Formula 1, the objective function to be optimized is obtained as follows (Formula 3):
[0046]
[0047] In the above formula, F i represents the feature prototype of the i-th category, l(x j ,y j ω) is the basic loss value of each sample, and the previous items are the weights corresponding to this sample. The objective function to be optimized represents the loss function in deep learning. The model parameters are updated through gradient calculation and back propagation optimization methods to obtain a more effective model.
[0048] Step S3: Based on the features of each sample in the current batch, the feature prototype is momentum updated.
[0049] Specifically, for the ideal balanced data distribution P bal In this embodiment, a momentum mechanism is designed to gradually estimate the feature expectations learned from the balanced data distribution during training. For each category, a feature prototype F is maintained throughout the training process, and momentum is updated using the feature expectations of each batch. set up in Represents the average value of the feature extractor output z of all samples in category i. The momentum mechanism update process is (Formula 2):
[0050]
[0051] Here, m is a momentum factor with a value between 0 and 1.
[0052] Preferably, the updating process of the feature prototype can add different dynamic adjustment strategies, including but not limited to adding a temperature coefficient, a sliding average constraint, etc.
[0053] See also Figure 2 , a typical algorithm process includes the following steps:
[0054] Step 1: Get the training data set and initialize the model parameters and θ, will Initialized to 0.
[0055] Step 2: For batches 0 to T, repeat Step 3-Ste7 until the training is completed, that is, the target training batch is reached.
[0056] Step 3: Randomly split the training data set into several small batches B(x,y) and calculate z←f(x).
[0057] Step 4: If the batch number is less than T0, it is in the warm-up phase and the weight of each category is set to 1 (i.e., equal weight). If the batch number is greater than or equal to T0, for each category from i to d: where yj =i, and the category weight of each sample in the category is calculated according to Formula 3. By setting a warm-up phase, feature information can be extracted in advance to improve the accuracy of the method.
[0058] Step 5: Normalize the weights of all categories.
[0059] Step 6, calculate the weighted loss function and perform back propagation to update the network parameters.
[0060] Step 7: Update according to formula 2
[0061] In summary, this embodiment achieves performance optimization of deep learning models on unbalanced data sets through technical means such as dynamic adjustment of weights, density ratio estimation, and adaptive updating, effectively improving the generalization ability and robustness of the model, and is suitable for various practical application scenarios of long-tail distributions.
[0062] In a specific application scenario, the method of this embodiment can be applied in the training process of an image classification deep learning model. It should be noted that the actual application scenario can be various downstream tasks in any actual application scenario.
[0063] To verify the effectiveness of this method, experimental verification was carried out on multiple commonly used long-tail distribution data sets, which have different degrees of imbalance and are ideal for testing model robustness and generalization ability. By comparing the dynamic class weight adjustment method of this embodiment with the existing static reweighting method and non-reweighting method, the results show that the method of this embodiment has achieved significant performance improvement on various data sets. In the CIFAR-10-LT and CIFAR-100-LT data sets, the recognition accuracy of this method in minority classes is significantly higher than that of traditional methods, especially in scenes with extremely unbalanced data, the accuracy of minority classes is significantly improved, indicating that this method can effectively solve the problem of insufficient attention to minority classes by traditional methods. At the same time, this method also maintains a high competitiveness in most classes. In large-scale data sets such as ImageNet-LT and Places-LT, the overall classification accuracy of this method is significantly improved compared with related methods, proving that while optimizing the performance of minority classes, it avoids the performance degradation of majority classes and optimizes the overall performance of the model.
[0064] In summary, this method has the following characteristics:
[0065] (1) This method improves the robustness of the model by dynamically and adaptively adjusting the density ratio estimation. This adaptive adjustment method enables the model to respond more flexibly to changes in data distribution, significantly reducing the phenomenon of overfitting the model on the majority class or underfitting on the minority class. By dynamically updating the density ratio, the model can maintain a higher generalization ability in unbalanced data scenarios.
[0066] (2) The algorithm provided by this method has a certain theoretical guarantee for the generalization error upper bound of the proposed objective function, which can significantly improve the effectiveness and reliability of the algorithm.
[0067] (3) This method has achieved excellent performance on multiple small-scale and large-scale benchmark datasets.
[0068] Example 2
[0069] This embodiment provides an electronic device, including: one or more processors and a memory, wherein the memory stores one or more programs, and the one or more programs include instructions for executing the data equalization method based on density ratio estimation as described in Example 1.
[0070] like Figure 2 As mentioned above, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 The data equalization method based on density ratio estimation. Of course, in addition to the software implementation, the present invention does not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0071] Example 3
[0072] This embodiment provides a computer-readable storage medium, including one or more programs for execution by one or more processors of an electronic device, wherein the one or more programs include instructions for executing the data equalization method based on density ratio estimation as described in Example 1.
[0073] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0074] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0075] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0076] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A data equalization method based on density ratio estimation, characterized in that: The steps include: Step S1, obtain the training data set and the deep learning model to be trained, and repeat steps S2-S3 until the target training batch is reached; Step S2, extract the features of the samples in the training data set under the current batch, determine whether the current batch exceeds the preset critical batch, if not, configure the category weights to be equal weights, if so, based on the features of each sample under the current batch, the current feature prototype and the loss of the current batch, calculate the category weights of each category through density ratio estimation, calculate the weighted loss after obtaining the category weights, and update the parameters of the deep learning model; Step S3: Based on the features of each sample in the current batch, the feature prototype is momentum updated.
2. The data equalization method based on density ratio estimation according to claim 1, characterized in that: The calculation of the category weights of each category through density ratio estimation is based on the following formula: Among them, R is the sample weight, n is the total number of samples in the training data set, r(x i |y i ; ω) is the density ratio, which is defined as the ratio of the actual density of a category under an unbalanced data distribution to the assumed density under an ideal balanced distribution. is the training data set, l(x i ,y i ;ω) is the loss function, x i ,y i are sample input and corresponding categories respectively, Represents y i The ratio of the total number of samples of the corresponding category to the total number of all samples, ω is the deep learning model parameter.
3. The data equalization method based on density ratio estimation according to claim 1, characterized in that: When the preset critical batch is exceeded, the category weight is calculated using the following formula: Among them, R is the sample weight, d is the total number of categories, Φ P =(f(x1),...,f(x n )), x i ,y i are sample input and corresponding category respectively, f() is feature extraction operator, T represents transposition, () -1 Indicates the inverse, is the current feature prototype, l(x i ,y i ; ω) is the loss function, and ω is the deep learning model parameter.
4. The data equalization method based on density ratio estimation according to claim 1, characterized in that: The momentum update of the feature prototype is implemented by the following formula: Among them, ← represents assignment, m is the momentum factor, is the feature prototype, represents the average value of feature z of all samples in category i.
5. The data equalization method based on density ratio estimation according to claim 1, characterized in that: In the step S2, after the category weights are calculated, the category weights are normalized.
6. The data equalization method based on density ratio estimation according to claim 1, characterized in that: In step S2, the parameters of the deep learning model are updated through back propagation.
7. The data equalization method based on density ratio estimation according to claim 1, characterized in that: The training data set is an image data set, and the deep learning model is an image classification model.
8. The data equalization method based on density ratio estimation according to claim 7, characterized in that: The parameters of the deep learning model include feature extractor parameters and classifier parameters.
9. An electronic device, characterized in that: include: One or more processors and a memory, wherein the memory stores one or more programs, and the one or more programs include instructions for executing the data equalization method based on density ratio estimation as claimed in any one of claims 1-8.
10. A computer-readable storage medium, characterized in that: The method comprises one or more programs executed by one or more processors of an electronic device, wherein the one or more programs comprise instructions for executing the data equalization method based on density ratio estimation as claimed in any one of claims 1 to 8.