3.1. Model Overview
This paper is a model for performing adversarial domain adaptation. The architecture of the proposed model is shown in
Figure 2. First, for preprocessing the existing dataset and constructing the model, we pretrained a generative model with a convolutional autoencoder structure on the input data
which is from source domain. And the other input data is
which is from target domain. We then loaded and used the pretrained model. The inputs
and
are passed through the pretrained generative network to reconstruct the input image data and generate a theoretically identical image. However, in practice, they are not identical. For example, if you apply the generative network that is customized to the MNIST dataset to the SVHN dataset, which is an RGB image dataset, the same image cannot be generated. Thus, results may vary depending on the source domain. However, results may change when adjusting parameters. In this paper, the classification accuracy of the generative network was 98.5∼99.23%. Images were generated by the well-trained generative model. The image data
,
of the generated source domain and target domain were taken as input data and features of those images were extracted with the feature extractor. This prepared us to perform the adversarial domain adaptation (AdvDA) problem. Weights were shared for consistency in experiments [
29].
For the input layer, we used a convolutional autoencoder structure, and used three convolutional layers for the encoder and decoder parts, and encoded by increasing the number of channels from 1 channel to 8 channels, 16 channels, and 32 channels, and reconstructed by returning to 32 channels, 16 channels, 8 channels, and 1 channel. The amount of error in this process is considered as noise for the robustness of the model and data in this paper. After that, the rest of the learning process proceeds through the feature extractor.
It trains a label classifier with features extracted from the source domain to classify the class label of the source data. In the process, it calculates the label loss, or label classification loss, which shows how badly it classifies the label. Label classification loss uses cross-entropy loss as a general classification loss function. Therefore, this paper learns to maximize the performance of the label classifier by minimizing the label classification loss and learns a domain discriminator to determine the source domain or target domain using features. As this paper is a domain adaptation problem, it is a problem for the target domain to learn well without label information for the model learned for the source domain. Therefore, it can be said that this part is adversarial, in that the domain discriminator learns to distinguish the source domain and the target domain as well as possible, while learning to extract domain-invariant features that fool the domain discriminator into not distinguishing as well as possible with features extracted with the feature extractor. Therefore, if the label classifier has a classification loss, the domain discriminator uses the same general classification loss as the label classifier as a domain classification loss. A single device is required to classify the label of the source domain well despite a difference in distribution between the source domain and the target domain and to prevent the two domains (i.e., the source domain and the target domain) from being distinguished.
The device is the gradient reversal layer (GRL) [
2] proposed in the DANN paper. This GRL acts as an intermediary between the feature extractor and the domain discriminator. When learning, it still passes linearly when forward. However, when performing backpropagation, it reverses the direction of the gradient by reversing the sign of the gradient. The inverted gradient is inserted between the domain classifier and the feature extractor. This plays a role in training the feature extractor to minimize the domain information while minimizing the domain classification loss. This allows the feature extractor to extract features with minimal domain information. The hyperparameter alpha, which controls how much domain information to include, is not a trainable parameter. In this paper, it takes the form of bidirectional feature learning, in addition to mutually conservative learning, in the direction of minimizing similarity difference between features while preserving characteristics between domains by including very little domain information.
In addition to learning methods limited to a single domain, the model in this paper induces smooth learning for a series of domains with completely different characteristics such as their distribution. In addition to reducing the gap between domains, the data itself is subjected to a slight noise effect using a pretrained generative network. By reconstructing the input image data, we propose a method to improve the robustness of both the domains and data.
3.2. Loss Functions
This paper aims to reduce the gap between domains and improve the robustness of the model using a generative model with an autoencoder structure and an adversarial domain adaptation (BiFLP-AdvDA) approach based on bidirectional feature learning to extract features that can finally be learned regardless of the domain. This study also aims to perform domain adaptation to minimize the gap between domains so that characteristics of domains become similar. For these purposes, four loss functions and a total of five loss functions are used until total loss using all of them. Formulas and brief descriptions of the loss functions are presented below.
Label classification loss was used to perform a classification task using data from the source domain and to minimize the difference between the actual and predicted labels. The following is the formula for label classification loss:
where
y denotes actual classified class labels of the source domain, which can be binary or multi-class depending on the problem;
denotes predicted class labels of the source domain containing probabilities for each class;
i denotes an index variable representing classes, varying depending on the number of possible classes in a classification task;
denotes the value corresponding to class
i in the actual label vector, the value of
; and
i in the log function corresponds to class i in the predicted probability vector, representing the likelihood of belonging to that class.
Domain classification loss was used to train the domain discriminator to misclassify the domain as much as possible. This helps the feature extractor to extract features that the domain discriminator will use to prevent the domain discriminator from classifying as well as possible. As a loss function, unlike label classification loss, we used binary cross-entropy loss (BCE loss) because the task was to classify into one of two domains. The following is the formula for domain classification loss:
For the target domain,
where
indicates the source domain classification loss function;
denotes the actual classified source domain labels obtained using the domain discriminator;
denotes the predicted source domain labels;
i denotes the index variable for the elements in one batch of source data;
denotes the target domain classification loss function;
indicates a binary value of 0 or 1 and indicates whether the domain is the source or target;
denotes the predicted domain labels of the target domain; and i denotes the index variable for the elements in one batch of the target data.
Adversarial loss was used to train the domain discriminator to not discriminate between features extracted from the feature extractor. In this way, it learns to reduce the gap between domains. Here is the formula for adversarial loss:
For the target domain,
where
denotes the classification loss for the source domain;
denotes the source domain classification loss; alpha denotes a hyperparameter representing the weight or importance given to the source loss in the combination;
denotes the classification loss for the source domain, as already mentioned; and
denotes the target domain’s classification loss.
The adversarial loss function, represented by Equations (
4) and (
5), was calculated by utilizing Equations (
1) and (
2) or Equation (
3) as appropriate. First of all, Equation (
1) is a task to classify the label of the source domain as best as possible, as mentioned earlier, and the corresponding loss function is learned to be maximized; while Equations (
2) and (
3) are the main tasks to learn to distinguish whether the input data are from the source domain or the target domain as much as possible. Corresponding loss functions are learned to be minimized. In this respect, it is similar to the existing minmax loss. Thus, it is called adversarial loss. In addition, the alpha value of GRL, borrowed from the model proposed for the domain adaptation task, which is the subject of this paper, is multiplied by the domain classification loss to adjust how much to use characteristics of the domain. Contrastive loss is a loss function to measure similarity between two features [
30,
31], which is defined as the Euclidean distance between two features with the following formula:
where
f indicates the feature extraction function mapping the input data to feature embeddings;
and
denotes the original source data
and the original target data
reconstructed by the pretrained autoencoder;
indicates the Euclidean distance, obtained by measuring the distance of features between the source data
and the target data
using the feature embeddings generated by the function;
f and
n denote the size of one batch of the source and target domains and the number of data points within that batch;
i and
j denote the index variables of the source and target data;
denotes the ith data point of one batch of
;
denotes the
jth data point of one batch of
; the means of
D are different for each loss function. One of the
D’s, in Equations (
2) and (
3), indicates the domain discriminator and the other, in Equations (
6) and (
7), indicates the Euclidean distance;
y denotes a binary label that takes the value 0 or 1, 1 if the two features are similar and 0 if they are different, for example, in traditional research, the loss function is computed in such a way that if a pair of data enters as input a pair of data of the same class, the value of
y is 1, while if a pair of data enters as input a pair of data of a different class, the value of
y is 0; and
m denotes the margin value. This hyperparameter
m is not learnable. However, it can be tuned to an appropriate value through experimentation.
The total loss function is calculated by summing the loss functions of all components. After all, minimizing it is the goal of generalizing the model across domains and guiding it to extract similar features. Here is the formula for the total loss function.
In the learning process of the model proposed in this paper, the loss function is finally composed of adversarial loss and contrastive loss, which are arbitrarily configured for the model as in Equation (
8). By learning the loss function for the source domain and the target domain adversarially, the feature extractor extracts domain-invariant features that work well in both domains, i.e., features with similar characteristics to both domains. The contrastive loss is calculated according to the Euclidean distance between the two extracted features so that the similarity of the data points in the vector space increases. Eventually, the boundary between the two domains is blurred.