Model training method and device, computer equipment and storage medium
By adding a new debias classifier to the source domain model and using multiple loss functions to train the target network structure, the problems of inter-domain differences and class imbalance are solved, and the overall performance of the target domain model and the tail class are improved. Performance.
Patent Information
- Application Number
- CN202411415967.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-11
- Publication Date
- 2025-02-18
AI Technical Summary
The prior art is difficult to effectively migrate the source domain model to the target domain in scenarios where there are simultaneous interdomain differences and category imbalances, resulting in a degradation in the performance of the target domain model, especially in poor performance on the tail class.
By adding a new debias classifier to the network structure of the source domain model, a target network structure is formed, and the pseudo-label and adaptive weights in the target domain sample data are used, based on multiple loss functions (including information maximization loss and self-training). Loss, consistency loss and classifier debias loss) iteratively trains the target network structure.
It effectively improves the performance of the target domain model, reduces bias against head classes, improves performance on tail classes, and meets the higher accuracy requirements of specific application scenarios.
Smart Images

Figure CN119476408A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer vision, and in particular to a model training method, apparatus, computer device and storage medium. Background Art
[0002] In recent years, the rapid development of artificial intelligence technology has led to industrial changes. Artificial intelligence based on deep learning has been applied to many fields such as sentiment analysis, artistic creation, and computer vision. In the field of computer vision, transfer learning can effectively use the knowledge learned by the trained model from the source domain (training data set) to improve the performance of the model in the target domain (application scenarios in the real world). Therefore, it has been widely used in tasks such as image recognition, object detection, and image segmentation.
[0003] In current transfer learning related technologies, domain differences (referring to the differences between the source domain and the target domain, such as feature distribution offset) and category imbalance (referring to the imbalance of category distribution between the source domain and the target domain) are usually considered separately. One is to assume that the category distribution of the source domain and the target domain is balanced, and then study how to overcome the problems caused by domain differences. The other is to assume that domain differences do not exist, and then study how to overcome the problems caused by category imbalance. However, in the real world, domain differences and category imbalance often exist at the same time. If the impact of domain differences is ignored, the performance of the model trained in the source domain may be significantly reduced in the target domain. If the impact of category imbalance is ignored, the model trained in the source domain may be too biased towards the head class, resulting in much lower performance on the tail class than the head class. Summary of the invention
[0004] In response to the above-mentioned deficiencies or shortcomings, the present application provides a model training method, apparatus, computer device and storage medium.
[0005] The present application provides a model training method based on passive domain adaptation according to a first aspect. In some embodiments, the method includes:
[0006] A new classifier is added to the network structure of the source domain model to obtain a target network structure; the source domain model is a deep learning classification model pre-trained based on source domain sample data; the target network structure includes the original classifier from the network structure of the source domain model and the newly added debiased classifier;
[0007] Initialize the weight of the debiased classifier based on the weight of the original classifier, set the weight of the original classifier to a non-updatable state, and set the weight of the debiased classifier to an updateable state;
[0008] Obtain target domain sample data; the target domain sample data includes multiple target domain samples and a pseudo label and an initial adaptive weight corresponding to each target domain sample; the category distribution of the target domain sample data and the source domain sample data is unbalanced;
[0009] The target network structure is iteratively trained according to the target domain sample data and the preset objective function to obtain a trained target domain model; the objective function is constructed based on multiple loss functions; the multiple loss functions include one or more of the information maximization loss function, the self-training loss function, the consistency loss function and the classifier debiasing loss function.
[0010] In some embodiments, there are multiple categories of target domain samples in the target domain sample data; before obtaining the target domain sample data, the method further includes:
[0011] Determine the cluster centers of each category through a pre-specified clustering algorithm;
[0012] Calculate the distance between each target domain sample and the cluster center of each category, and assign a corresponding pseudo label to each target domain sample based on the distance between each target domain sample and the cluster center of each category;
[0013] The uncertainty of the pseudo-label corresponding to each target domain sample is calculated, and the initial adaptive weight corresponding to each target domain sample is calculated according to the uncertainty of the pseudo-label corresponding to each target domain sample.
[0014] In some embodiments, before determining the cluster centers of each category using a pre-specified clustering algorithm, the method further includes:
[0015] Obtain a target domain unlabeled dataset; the target domain unlabeled dataset includes unlabeled data of multiple categories;
[0016] Construct corresponding weak data enhancement versions and strong data enhancement versions for each unlabeled data;
[0017] Each unlabeled data and its corresponding weak data enhancement version and strong data enhancement version are taken as target domain samples.
[0018] In some embodiments, the method further comprises:
[0019] After each training, the information entropy of each target domain sample is calculated;
[0020] The adaptive weight corresponding to each target domain sample is updated according to the information entropy of each target domain sample.
[0021] In some embodiments, the information maximization loss function is:
[0022]
[0023] in, represents the information maximization loss, represents the entropy minimization loss based on negative sample learning, represents a smoothly decaying class diversity loss;
[0024] The entropy minimization loss based on negative sample learning is calculated by the following formula:
[0025]
[0026] in, represents the maximum square loss, represents the negative sample learning loss, α represents the weight coefficient that controls the ratio of the maximum square loss to the negative sample learning loss;
[0027] The maximum square loss is calculated by the following formula:
[0028]
[0029] Among them, δ k (f t (x t )) represents the target domain sample x t The K-dimensional vector f output after passing through the target network structure t (x t ) The Kth dimension of the prediction result obtained after softmax processing;
[0030] The negative sample learning loss is calculated by the following formula:
[0031]
[0032] in, is the indicator function, when δ k (f t (x t ))<θ, and takes the value 1, and takes the value 0 when δk(ft(xt))≥θ; θ is the preset value;
[0033] The smoothly decaying class diversity loss is calculated by the following formula:
[0034]
[0035] in, The Kth dimension represents the average prediction result of the entire target domain; the average prediction result is obtained by Calculated; ω1 represents the smooth attenuation coefficient, which is calculated by ω1=cos((arccose)·t), where t changes linearly from 0 to 1 during training, and e is a hyperparameter used to control the strength of attenuation;
[0036] The self-training loss function is:
[0037]
[0038] in, represents the self-training loss, ω2 represents the target domain sample x t The corresponding adaptive weights, Represents the target domain sample x t The corresponding pseudo-label,;
[0039] The consistency loss function is:
[0040]
[0041] in, represents consistency loss; H(p,q) represents cross entropy loss;
[0042] Represents the target network structure for the target domain sample x t The prediction result of the strongly data-enhanced version; p(y|α(x t )) represents the target network structure for the target domain sample x t The prediction result of the weak data enhancement version; γ is the preset threshold; is an indicator function, when max(p(y|α(x t )))≥γ, and when max(p(y|α(x t )))<γ, the value is 0;
[0043] The classifier debiasing loss function is:
[0044]
[0045] in, Represents the target network structure for the target domain sample x t The prediction results output by the strong data augmentation sample after passing through the debiased classifier.
[0046] In some embodiments, the cross entropy loss is based on the target domain samples x t The corresponding pseudo soft label is calculated.
[0047] In some embodiments, the adaptive weight corresponding to each target domain sample is calculated by the following formula:
[0048]
[0049] Among them, ω2 represents the target domain sample x t The corresponding adaptive weights.
[0050] According to a second aspect, the present application provides a model training device based on passive domain adaptation. In some embodiments, the device includes:
[0051] The target domain model network construction module is used to add a classifier to the network structure of the source domain model to obtain the target network structure; the source domain model is a deep learning classification model pre-trained based on source domain sample data; the target network structure includes the original classifier from the network structure of the source domain model and the newly added debiased classifier;
[0052] A setting module, used for initializing the weight of the debiased classifier based on the weight of the original classifier, setting the weight of the original classifier to a non-updatable state, and setting the weight of the debiased classifier to an updateable state;
[0053] The target domain sample acquisition module is used to acquire target domain sample data; the target domain sample data includes multiple target domain samples and pseudo labels and initial adaptive weights corresponding to each target domain sample; the category distribution of the target domain sample data and the source domain sample data is unbalanced;
[0054] The target domain model training module is used to iteratively train the target network structure according to the target domain sample data and the preset objective function to obtain a trained target domain model; the objective function is constructed based on multiple loss functions; the multiple loss functions include one or more of the information maximization loss function, the self-training loss function, the consistency loss function and the classifier debiasing loss function.
[0055] According to a third aspect, the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the model training method based on passive domain adaptation provided in any of the above embodiments are implemented.
[0056] According to a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the model training method based on passive domain adaptation provided in any of the above embodiments are implemented.
[0057] The above-mentioned embodiments of the present application can migrate the source domain model (i.e., the model trained in the source domain) to the target domain in the scenario of inter-domain differences and category imbalance. During the migration, a new classifier is added on the basis of the network structure of the source domain model to obtain the target network structure for training the target domain model; the target network structure includes the original classifier (i.e., the original classifier in the network structure of the source domain model) and the debiasing classifier (i.e., the newly added classifier). Before training, the weight of the debiasing classifier needs to be initialized based on the weight of the original classifier, and the weight of the original classifier is set to a non-updatable state so that it is not updated during the training process, and the weight of the debiasing classifier is set to an updateable state so that its weight can be continuously updated as the training progresses; during the migration, the target network structure is iteratively trained through the preset objective function and the target domain sample data with unbalanced category distribution. Based on the above operations, the embodiments of the present application can effectively improve the performance of the trained target domain model, while making the target domain model not too biased towards the head class, effectively improving its performance on the tail class. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 Comparison results of cross-domain adaptation between the model trained by the method provided by this application and other passive domain adaptation algorithms in scenarios with imbalanced categories;
[0059] Figure 2 A schematic diagram of a flow chart of a model training method based on passive domain adaptation provided by the present application according to one or more embodiments;
[0060] Figure 3 A schematic diagram of a passive domain adaptation framework provided by the present application according to one or more embodiments;
[0061] Figure 4 A structural block diagram of a model training device based on passive domain adaptation provided by the present application according to one or more embodiments;
[0062] Figure 5 This is a diagram of the internal structure of a computer device provided by the present application according to one or more embodiments. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below in conjunction with the accompanying drawings. It should be clear that the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0064] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0065] In the description of the present application, it should be understood that the terms "first", "second", "third", etc. are only used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances. In addition, in the description of the present application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0066] In order to better understand the technical solution of the present application, the background technology is described in more detail below.
[0067] In the field of computer vision, transfer learning has been widely used in tasks such as image recognition, object detection, and image segmentation. Domain adaptation is a specific research direction of transfer learning, which mainly solves the problem of model performance degradation caused by the difference in feature distribution between the source domain and the target domain. Traditional domain adaptation usually assumes that there is a fully annotated source domain and an unannotated target domain, and improves the performance of the model in the target domain by fully mining the knowledge of the source domain. However, in practical applications, the problem of unavailable source domain data is often faced. Because the amount of data in the source domain is usually huge, especially for data sets dominated by high-definition videos or high-resolution remote sensing images, the storage space occupied by them even reaches TB level. Therefore, it is unrealistic to transfer source domain data for training target domain models. In addition, due to data privacy and security considerations, in some fields (such as medical and financial), source domain data may contain sensitive personal information or commercial secrets, which are protected by law and are usually difficult to obtain or share.
[0068] To this end, some researchers have proposed passive domain adaptation, which aims to study how to transfer the knowledge learned by the model from the source domain to the unlabeled target domain without source domain data. However, these methods usually assume that the source domain and the target domain are balanced in categories, which limits the application of these methods in the real world. In many application scenarios in the real world, in addition to style differences, there is often a class imbalance between them. This is because the category distribution of species in nature generally presents a long-tail form, some species have an absolute advantage in quantity, and some species are relatively small in quantity. The proportion of each category in different application scenarios is different, or even completely opposite. For example, on the highway, cars are the head class (the class with a large number of samples) and people are the tail class (the class with a small number of samples), while in commercial areas, people are the head class and cars are the tail class. Existing studies have shown that ignoring the class imbalance problem will make the trained model too biased towards the head class, resulting in much lower performance on the tail class than the head class. In the real world where there are both style differences and class imbalance, the performance of the tail class decreases more significantly. In application scenarios that require extremely high accuracy, such as autonomous driving, precision guidance, and medical image diagnosis, a significant performance degradation in certain categories is unacceptable, so current passive domain adaptation related technologies usually cannot meet the requirements of these application scenarios.
[0069] Taking into account that class imbalance and inter-domain differences often exist simultaneously in real-world application scenarios, this application assumes that class imbalance and inter-domain differences exist simultaneously, and provides a model training method based on passive domain adaptation, which incorporates the class imbalance problem and the inter-domain difference problem into a unified framework and solves them simultaneously. It can complete the migration of the source domain model to the target domain by only using the unlabeled data of the target domain and the trained source domain model, and can effectively improve the performance of the migrated model, that is, the target domain model, while making the target domain model not overly biased towards the head class, effectively improving its performance on the tail class, thereby meeting the higher accuracy requirements of specific application scenarios.
[0070] For example, see Figure 1 , Figure 1Shown is the comparison result of the model trained by the method provided by the present application (hereinafter referred to as the present method) and other passive domain adaptation algorithms based on the VISDA-C (RSUT) dataset, in the scenario of class imbalance. It can be seen from the figure that most of the traditional passive domain adaptation methods have significant performance degradation on the large-scale long-tail dataset VISDAC (RSUT), especially for the detection accuracy of the tail category. While methods such as BSP, PADA, and BBSE show better performance than this method (i.e., Our Method in the figure) on some head classes, there is a significant performance degradation on some tail categories. For some tail categories, such as train (train) and truck (truck), the accuracy is only about 0.1%. Compared with the classic method ISFDA in this field, this method has an improvement of more than 8% in class average accuracy, and significantly improves the accuracy of the model in the tail category. For example, the accuracy of sktbrd (skateboard) has been improved by 20.77%.
[0071] In some embodiments, the method includes Figure 2 The steps shown below are combined Figure 3 An exemplary passive domain adaptation framework is shown to illustrate the method in detail.
[0072] S110: Add a new classifier to the network structure of the source domain model to obtain a target network structure.
[0073] This embodiment is used to migrate a pre-trained model in the source domain to the target domain. The source domain is an image dataset with rich data and complete labels, and the target domain is an image dataset with less data, incomplete labels or difficult to obtain, which is the field in which the migrated model is to work. In some embodiments, the source domain and the target domain can specifically be image datasets related to any application scenario in application scenarios such as autonomous driving, precision guidance, and medical imaging diagnosis.
[0074] For the sake of distinction, this article calls the model pre-trained in the source domain the source domain model, and the model obtained by migrating the source domain model to the target domain the target domain model.
[0075] The network structure of the source domain model includes a feature extraction network and a classifier. In some embodiments, the network structure of the source domain model uses ResNet101 as the backbone network. ResNet101 and the Bottle Neck layer (a neural network structure that compresses and amplifies information) constitute a feature extraction network. The classifier uses the features output by the feature extraction network as input data and outputs category data based on the input data.
[0076] The target network structure is the network structure used to train the target domain model, such as Figure 2As shown in the figure, the only difference between the target network structure and the network structure of the source domain model is that the target network structure has one more classifier. The target network structure includes two classifiers. For the convenience of distinction, this paper calls the classifier taken from the network structure of the source domain model the original classifier, and the classifier added to the network structure of the source domain model is called the debiased classifier (also called balanced classifier).
[0077] In some embodiments, the source domain model is a deep learning classification model pre-trained based on source domain sample data, and the target domain model is also a deep learning classification model. Both the source domain model and the target domain model are used to identify the target in the image and predict the category corresponding to the target. The source domain sample data includes multiple source domain samples and their corresponding annotation data. The source domain sample is specifically image data related to a specific application scenario, and the image data includes at least one target (such as an airplane, a car, etc.). The category distribution of the source domain sample data is unbalanced, that is, in the source domain sample data, there are multiple categories corresponding to the source domain samples, some categories correspond to a large number of source domain samples, and some categories correspond to a small number of source domain samples.
[0078] S120: Initializing the weight of the debiased classifier based on the weight of the original classifier, setting the weight of the original classifier to a non-updatable state, and setting the weight of the debiased classifier to an updateable state.
[0079] Before starting training, extract the weights from the original classifier and use them to initialize the corresponding layers of the debiased classifier. This initialization can be done by direct assignment or using the model loading function. The weights of the original classifier are set to a non-updatable state (frozen state) so that they are not updated during training. The weights of the debiased classifier are set to an updateable state (thawed state) so that their weights can be continuously updated as training progresses.
[0080] Furthermore, you need to set hyperparameters, such as setting the standard batch size to 32, the initial learning rate to 1e-3, and using SGD stochastic gradient descent and the learning rate attenuator η = η0·(1+10·t) -0.75 to optimize the network, where t varies linearly from 0 to 1 during training.
[0081] This embodiment reconciles the contradiction between passive domain adaptation and class imbalance research on whether to adjust the classifier or not by introducing a new classifier based on the original classifier. Specifically, by keeping the original classifier frozen, the feature distribution of the source domain and the target domain are implicitly aligned; the debiased classifier is involved in model training to update its weights and push the classification hyperplane of the classifier away from the minority class, so that the target domain model can better adapt to the target domain while reducing its bias towards the tail class.
[0082] S130: Obtain target domain sample data.
[0083] The target domain sample data is a pre-made training sample for model training. The target domain sample data includes multiple target domain samples and the pseudo label and initial adaptive weight corresponding to each target domain sample. There is a class imbalance in both the target domain and the source domain. For this reason, the class distribution of the target domain sample data and the source domain sample data used in this embodiment is unbalanced, so as to improve the performance and generalization ability of the target domain model in the target domain.
[0084] S140: Iteratively train the target network structure according to the target domain sample data and the preset objective function to obtain a trained target domain model.
[0085] During training, a batch of samples can be randomly sampled from the target domain samples included in the target domain sample data for training, and a pre-specified objective function can be calculated to obtain a target loss (or total loss), and then the network parameters of the target network structure can be updated using a gradient descent algorithm;
[0086] After each training, check whether the preset training completion conditions are met. For example, if the current training step number has reached the pre-specified training step number or the model has converged, it is determined that the training completion conditions are met, the training process is terminated, and the model parameters are saved to obtain a trained target domain model. If the training completion conditions are not met, continue with the next training.
[0087] The objective function is specifically constructed based on multiple loss functions, and the multiple loss functions include one or more of an information maximization loss function, a self-training loss function, a consistency loss function, and a classifier debiasing loss function.
[0088] In some embodiments, the objective function may be:
[0089]
[0090] represents the target loss, represents the information maximization loss, represents the self-training loss, represents the consistency loss, Represents the classifier debiasing loss.
[0091] This embodiment uses information maximization loss, self-training loss, consistency loss and classifier debiasing loss to jointly guide model training, which can enable the target domain model to achieve better performance.
[0092] In some embodiments, there are multiple categories of target domain samples in the target domain sample data; before obtaining the target domain sample data, the method further includes:
[0093] Determine the cluster center of each category through a pre-specified clustering algorithm, calculate the distance between each target domain sample and the cluster center of each category, and assign a corresponding pseudo label to each target domain sample based on the distance between each target domain sample and the cluster center of each category;
[0094] The uncertainty of the pseudo-label corresponding to each target domain sample is calculated, and the initial adaptive weight corresponding to each target domain sample is calculated according to the uncertainty of the pseudo-label corresponding to each target domain sample.
[0095] In this embodiment, each target domain sample is unlabeled data. In order to improve the performance of the target domain model, a corresponding pseudo label is assigned to each target domain sample in advance. The clustering center of each category in the target domain sample can be determined by a clustering algorithm such as K-Means, and then a corresponding pseudo label is assigned to each target domain sample according to the distance between each target domain sample and the clustering center of each category. The pseudo labels and adaptive weights corresponding to each target domain sample will participate in the calculation process of the objective function.
[0096] The initial adaptive weight corresponding to each target domain sample can be calculated based on the uncertainty of the pseudo label corresponding to each target domain sample. Uncertainty is usually used to measure the confidence level of the model in a certain prediction result. There are many ways to calculate uncertainty. For example, the uncertainty of the prediction probability distribution can be quantified by information entropy, confidence interval, etc. This embodiment does not limit the specific calculation method.
[0097] Furthermore, in some embodiments, before determining the cluster centers of each category by a pre-specified clustering algorithm, the method further includes:
[0098] Obtain a target domain unlabeled dataset; the target domain unlabeled dataset includes unlabeled data of multiple categories;
[0099] Construct corresponding weak data enhancement versions and strong data enhancement versions for each unlabeled data;
[0100] Each unlabeled data and its corresponding weak data enhancement version and strong data enhancement version are taken as target domain samples.
[0101] In this embodiment, the unlabeled data included in the target domain unlabeled data set is data that has been preprocessed in advance, such as scaling, cropping, etc. For example, the images in the VISDA-C (RSUT) data set (a large-scale domain adaptation data set from simulator to real environment) can be scaled to a specified size (such as 224×224) and used as unlabeled data.
[0102] In order to improve the generalization ability and robustness of the target domain model, this embodiment also performs data enhancement based on the target domain unlabeled data set, specifically constructing corresponding weak data enhancement versions and strong data enhancement versions for each unlabeled data, and using each unlabeled data and each enhanced version constructed as a target domain sample. The weak data enhancement version is the data obtained by performing processing such as cropping, translation, flipping, etc. on the original sample, and the strong data enhancement version is the data obtained by changing the color, contrast, brightness of the original sample, or blocking a part of it. The weak data enhancement version is similar to the original sample, while the strong data enhancement version is quite different from the original sample.
[0103] In some embodiments, the method further includes: calculating the information entropy of each target domain sample after each training; and updating the adaptive weight corresponding to each target domain sample according to the information entropy of each target domain sample.
[0104] In this embodiment, the adaptive weight corresponding to each target domain sample is recalculated based on the prediction result output by the target network structure in each training iteration, so that the contribution of each target domain sample to the model training can be dynamically controlled. Since the pseudo-label of the target domain sample with lower confidence may be incorrect, and the pseudo-label of the target domain sample with higher confidence is more likely to be correct, when updating the adaptive weight corresponding to each target domain sample, a larger weight coefficient can be added to the target domain sample with lower information entropy, and a smaller weight coefficient can be added to the target domain sample with higher information entropy, so that the noise interference caused by difficult samples (samples with low confidence) in the early stage of model training can be alleviated, and as the training proceeds, the model learns knowledge from easy-to-learn samples and gradually improves its prediction performance, and more and more difficult samples become easy-to-learn samples, so that the model is continuously trained in order from easy to difficult.
[0105] In some embodiments, the information maximization loss function is:
[0106]
[0107] in, represents the information maximization loss, represents the entropy minimization loss based on negative sample learning, Represents a smoothly decaying class diversity loss.
[0108] Among them, the entropy minimization loss based on negative sample learning is calculated by the following formula:
[0109]
[0110] in, represents the maximum square loss, represents the negative sample learning loss, and α represents the weight coefficient that controls the ratio of the maximum square loss to the negative sample learning loss.
[0111] The maximum square loss is calculated by the following formula:
[0112]
[0113] Among them, δ k (f t (x t )) represents the target domain sample x t The K-dimensional vector f output after passing through the target network structure t (x t ) The Kth dimension of the prediction result obtained after softmax processing;
[0114] The negative sample learning loss is calculated by the following formula:
[0115]
[0116] in, is the indicator function, when δ k (f t (x t ))<θ, and takes the value 1, and takes the value 0 when δk(ft(xt))≥θ; θ is the preset value;
[0117] This embodiment introduces the maximum square loss into the information maximization loss function, which can prevent the update of model parameters from being dominated by a small number of samples with excessively large gradients. On this basis, this embodiment also adds negative sample learning, which can remove as much uncertainty about the model's output as possible by increasing the amount of information obtained by the model. In addition, negative sample learning can enable the model to build knowledge from two aspects. Compared with relying only on positive samples, the introduction of negative samples can enable the model to obtain more information.
[0118] Furthermore, the smoothly decaying class diversity loss is calculated by the following formula:
[0119]
[0120] in, The Kth dimension represents the average prediction result of the entire target domain; the average prediction result is obtained by Calculated; ω1 represents the smooth attenuation coefficient, which is calculated by ω1=cos((arccose)·t), where t changes linearly from 0 to 1 during the training process, and e is a hyperparameter used to control the intensity of attenuation.
[0121] This embodiment introduces a smoothly decaying category diversity loss into the information maximization loss function to prevent the model from learning a degenerate solution, that is, to prevent the model from predicting all samples in the target domain as the same category, or a few categories. Furthermore, in the case of category imbalance, forcing the prediction of each category of the entire target domain sample to be 1 / K may interfere with model training. Therefore, this embodiment also introduces a smooth decay coefficient ω1, so that the contribution of category diversity loss to information maximization loss can be continuously reduced during the training process, which helps the model training to proceed in the right direction while preventing the model from learning a degenerate solution.
[0122] In some embodiments, the self-training loss function is:
[0123]
[0124] in, represents the self-training loss, ω2 represents the target domain sample x t The corresponding adaptive weights, Represents the target domain sample x t The corresponding pseudo labels.
[0125] In some embodiments, the consistency loss function is:
[0126]
[0127] in, represents consistency loss; H(p,q) represents cross entropy loss;
[0128] Represents the target network structure for the target domain sample x t The prediction result of the strongly data-enhanced version; p(y|α(x t )) represents the target network structure for the target domain sample x t The prediction result of the weak data enhancement version; γ is the preset threshold; is an indicator function, when max(p(y|a(x t )))≥γ, and when max(p(y|α(x t When )))<γ, the value is 0.
[0129] This embodiment introduces a consistency loss function in the objective function. Specifically, the loss function is constructed by comparing the consistency of the prediction results of the model for the weak data enhancement version and the strong data enhancement version of the same sample, which can improve the robustness of the model.
[0130] In some embodiments, the classifier debiasing loss function is:
[0131]
[0132] in, Represents the target network structure for the target domain sample x t The prediction results output by the strong data augmentation sample after passing through the debiased classifier.
[0133] This embodiment introduces a classifier debiasing loss function in the objective function, wherein the logit obtained after the weak data enhancement sample passes through the original classifier of the model is adjusted through logit adjustment, and the adjusted logit is used to guide the model, which can affect the decision boundary and prediction probability of the model and achieve the purpose of removing the model's bias for the tail class.
[0134] In some embodiments, the cross entropy loss is based on the target domain samples x t The corresponding pseudo soft labels are calculated. The pseudo soft labels contain the predicted probability distribution of the source domain model for each category of the target domain sample, that is, the confidence of the source domain model for each category. The pseudo soft label is not a single category label, but a probability value for each category. For example, in a multi-classification problem, the model may give a probability of 0.7 that a sample belongs to category A, 0.2 to category B, and 0.1 to category C. Such a set of probability values is a pseudo soft label. The pseudo soft label can reflect the uncertainty of the source domain model in the prediction result. Calculating the cross entropy loss based on the pseudo soft label can enable the model to learn a more generalized feature representation, thereby improving the generalization ability of the model.
[0135] In some embodiments, the adaptive weight corresponding to each target domain sample is calculated by the following formula:
[0136]
[0137] Among them, ω2 represents the target domain sample x t The corresponding adaptive weights.
[0138] It should be noted that, with respect to the various steps included in the model training method based on passive domain adaptation provided in any of the above embodiments, unless otherwise clearly stated in this document, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least part of these steps may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0139] Based on the same inventive concept, the present application also provides a model training device based on passive domain adaptation. In some embodiments, Figure 4 As shown, the model training device based on passive domain adaptation includes the following modules:
[0140] The target domain model network construction module 110 is used to add a classifier to the network structure of the source domain model to obtain a target network structure; the source domain model is a deep learning classification model pre-trained based on source domain sample data; the target network structure includes the original classifier from the network structure of the source domain model and the newly added debiased classifier;
[0141] A setting module 120, for initializing the weight of the debiased classifier based on the weight of the original classifier, setting the weight of the original classifier to a non-updatable state, and setting the weight of the debiased classifier to an updateable state;
[0142] The target domain sample acquisition module 130 is used to acquire target domain sample data; the target domain sample data includes multiple target domain samples and a pseudo label and an initial adaptive weight corresponding to each target domain sample; the category distribution of the target domain sample data and the source domain sample data is unbalanced;
[0143] The target domain model training module 140 is used to iteratively train the target network structure according to the target domain sample data and the preset objective function to obtain a trained target domain model; the objective function is constructed based on multiple loss functions; the multiple loss functions include one or more of the information maximization loss function, the self-training loss function, the consistency loss function and the classifier debiasing loss function.
[0144] In some embodiments, the apparatus further comprises:
[0145] A pseudo-label assignment module (not shown in the figure) is used to determine the cluster centers of each category through a pre-specified clustering algorithm, calculate the distance between each target domain sample and the cluster center of each category, and assign a corresponding pseudo-label to each target domain sample according to the distance between each target domain sample and the cluster center of each category;
[0146] The adaptive weight calculation module (not shown in the figure) is used to calculate the uncertainty of the pseudo label corresponding to each target domain sample, and calculate the initial adaptive weight corresponding to each target domain sample according to the uncertainty of the pseudo label corresponding to each target domain sample.
[0147] In some embodiments, before determining the cluster centers of each category by a pre-specified clustering algorithm, the method further includes a sample construction module (not shown in the figure). The sample construction module is used to:
[0148] Obtain a target domain unlabeled dataset; the target domain unlabeled dataset includes unlabeled data of multiple categories;
[0149] Construct corresponding weak data enhancement versions and strong data enhancement versions for each unlabeled data;
[0150] Each unlabeled data and its corresponding weak data enhancement version and strong data enhancement version are taken as target domain samples.
[0151] In some embodiments, the adaptive weight calculation module is further used to calculate the information entropy of each target domain sample after each training; and to update the adaptive weight corresponding to each target domain sample according to the information entropy of each target domain sample.
[0152] For the specific limitations of the model training device based on passive domain adaptation, please refer to the limitations of the model training method based on passive domain adaptation above, which will not be repeated here. Each module in the above-mentioned model training device based on passive domain adaptation can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0153] In some embodiments, the present application provides a computer device, whose internal structure diagram can be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store target domain sample data, target function and other data. The specific stored data can also refer to the definition in the above method embodiment. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a model training method based on passive domain adaptation is implemented.
[0154] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0155] This embodiment also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the model training method based on passive domain adaptation provided in any of the above embodiments can be implemented.
[0156] The present application also provides a computer-readable storage medium. In some embodiments, a computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, the steps of the model training method based on passive domain adaptation provided in any of the above embodiments are implemented.
[0157] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0158] Those skilled in the art can understand that all or part of the processes in the above method embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application 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. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink), DRAM (SLDRAM), memory bus (Rambus), direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0159] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0160] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A model training method based on passive domain adaptation, characterized in that: The method comprises: A new classifier is added to the network structure of the source domain model to obtain a target network structure; the source domain model is a deep learning classification model pre-trained based on source domain sample data; the target network structure includes the original classifier from the network structure of the source domain model and the newly added debiased classifier; Initializing the weight of the debiased classifier based on the weight of the original classifier, setting the weight of the original classifier to a non-updatable state, and setting the weight of the debiased classifier to an updatable state; Acquire target domain sample data; the target domain sample data includes a plurality of target domain samples and a pseudo label and an initial adaptive weight corresponding to each of the target domain samples; the category distribution of the target domain sample data and the source domain sample data is unbalanced; The target network structure is iteratively trained according to the target domain sample data and a preset objective function to obtain a trained target domain model; the objective function is constructed based on multiple loss functions; the multiple loss functions include one or more of an information maximization loss function, a self-training loss function, a consistency loss function, and a classifier debiasing loss function.
2. The method according to claim 1, characterized in that There are multiple categories of target domain samples in the target domain sample data; Before acquiring the target domain sample data, the method further includes: Determine the cluster centers of each category through a pre-specified clustering algorithm; Calculate the distance between each target domain sample and the cluster center of each category, and assign a corresponding pseudo label to each target domain sample based on the distance between each target domain sample and the cluster center of each category; The uncertainty of the pseudo-label corresponding to each target domain sample is calculated, and the initial adaptive weight corresponding to each target domain sample is calculated according to the uncertainty of the pseudo-label corresponding to each target domain sample.
3. The method according to claim 2, characterized in that Before determining the cluster centers of each category by a pre-specified clustering algorithm, the method further includes: Obtain a target domain unlabeled dataset; the target domain unlabeled dataset includes unlabeled data of multiple categories; Constructing a corresponding weak data enhancement version and a strong data enhancement version for each of the unlabeled data; Each of the unlabeled data and its corresponding weak data enhancement version and strong data enhancement version are used as target domain samples.
4. The method according to claim 1, characterized in that The method further comprises: After each training, calculating the information entropy of each target domain sample; The adaptive weight corresponding to each target domain sample is updated according to the information entropy of each target domain sample.
5. The method according to any one of claims 1 to 4, characterized in that The information maximization loss function is: in, represents the information maximization loss, represents the entropy minimization loss based on negative sample learning, represents a smoothly decaying class diversity loss; The entropy minimization loss based on negative sample learning is calculated by the following formula: in, represents the maximum square loss, represents the negative sample learning loss, and α represents the weight coefficient controlling the ratio of the maximum square loss to the negative sample learning loss; The maximum square loss is calculated by the following formula: Among them, δ k (f t (x t )) represents the target domain sample x t The K-dimensional vector f output after passing through the target network structure t (x t ) The Kth dimension of the prediction result obtained after softmax processing; The negative sample learning loss is calculated by the following formula: in, is the indicator function, when δ k (f t (x t ))<θ, and takes a value of 1, and takes a value of 0 when δk(ft(xt))≥θ; θ is a preset value; The smoothly decaying class diversity loss is calculated by the following formula: in, The Kth dimension represents the average prediction result of the entire target domain; the average prediction result is obtained by Calculated; ω1 represents the smooth attenuation coefficient, which is calculated by ω1=cos((arccose)·t), where t changes linearly from 0 to 1 during training, and e is a hyperparameter used to control the strength of attenuation; The self-training loss function is: in, represents the self-training loss, ω2 represents the target domain sample x t The corresponding adaptive weights, Represents the target domain sample x t The corresponding pseudo-label,; The consistency loss function is: in, represents consistency loss; H(p,q) represents cross entropy loss; Represents the target network structure for the target domain sample x t The prediction result of the strongly data-enhanced version; p(y|α(x t )) represents the target network structure for the target domain sample x t The prediction result of the weak data enhancement version; γ is the preset threshold; is an indicator function, when max(p(y|α(x t )))≥γ, and when max(p(y|α(x t )))<γ, the value is 0; The classifier debiasing loss function is: in, Represents the target network structure for the target domain sample x t The prediction results output by the strong data augmentation sample after passing through the debiased classifier.
6. The method according to claim 5, characterized in that The cross entropy loss is based on the target domain samples x t The corresponding pseudo soft label is calculated.
7. The method according to claim 5, characterized in that The adaptive weight corresponding to each target domain sample is calculated by the following formula: Among them, ω2 represents the target domain sample x t The corresponding adaptive weights.
8. A model training device based on passive domain adaptation, characterized in that: The device comprises: The target domain model network construction module is used to add a classifier to the network structure of the source domain model to obtain a target network structure; the source domain model is a deep learning classification model pre-trained based on source domain sample data; the target network structure includes the original classifier from the network structure of the source domain model and the newly added debiased classifier; A setting module, used for initializing the weight of the debiased classifier based on the weight of the original classifier, setting the weight of the original classifier to a non-updatable state, and setting the weight of the debiased classifier to an updateable state; A target domain sample acquisition module is used to acquire target domain sample data; the target domain sample data includes a plurality of target domain samples and a pseudo label and an initial adaptive weight corresponding to each of the target domain samples; the category distribution of the target domain sample data and the source domain sample data is unbalanced; The target domain model training module is used to iteratively train the target network structure according to the target domain sample data and a preset objective function to obtain a trained target domain model; the objective function is constructed based on multiple loss functions; the multiple loss functions include one or more of the information maximization loss function, the self-training loss function, the consistency loss function and the classifier debiasing loss function.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.