Next Article in Journal
PSRGAN: Perception-Design-Oriented Image Super Resolution Generative Adversarial Network
Previous Article in Journal
Joint Sub-Band and Transmission Rate Selection for Anti-Jamming Non-Contiguous Orthogonal Frequency Division Multiplexing System: An Upper Confidence Bound Based Reinforcement Learning Approach
Previous Article in Special Issue
Tikhonov-Tuned Sliding Neural Network Decoupling Control for an Inverted Pendulum
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

S2AC: Self-Supervised Attention Correlation Alignment Based on Mahalanobis Distance for Image Recognition

1
Blockchain Laboratory of Agricultural Vegetables, Weifang University of Science and Technology, Weifang 262700, China
2
Department of Computer Engineering, Dongseo University, 47 Jurye-ro, Sasang-gu, Busan 47011, Republic of Korea
*
Author to whom correspondence should be addressed.
Electronics 2023, 12(21), 4419; https://doi.org/10.3390/electronics12214419
Submission received: 9 September 2023 / Revised: 16 October 2023 / Accepted: 21 October 2023 / Published: 26 October 2023
(This article belongs to the Special Issue Artificial Intelligence for Robotics)

Abstract

:
Susceptibility to domain changes for image classification hinders the application and development of deep neural networks. Domain adaptation (DA) makes use of domain-invariant characteristics to improve the performance of a model trained on labeled data from one domain (source domain) on an unlabeled domain (target) with a different data distribution. But existing DA methods simply use pretrained models (e.g., AlexNet, ResNet) for feature extraction, which are convolutional models that are trapped in localized features and fail to acquire long-distance dependencies. Furthermore, many approaches depend too much on pseudo-labels, which can impair adaptation efficiency and lead to unstable and inconsistent results. In this research, we present S2AC, a novel approach for unsupervised deep domain adaptation, that makes use of a stacked attention architecture as a feature map extractor. Our method can fuse domain discrepancy with minimizing a linear transformation of the second statistics (covariances) extended by the p-norm, while simultaneously designing pretext tasks on heuristics to improve the generality of the learning representation. In addition, we have developed a new trainable relative position embedding that not only reduces the model parameters but also enhances model accuracy and expedites the training process. To illustrate our method’s efficacy and controllability, we designed extensive experiments based on the Office31, Office_Caltech_10, and OfficeHome datasets. To the best of our knowledge, the proposed method is the first attempt at incorporating attention-based networks and self-supervised learning for image domain adaptation, and has shown promising results.

1. Introduction

Neural networks have transformed the area of machine learning, enabling the development of powerful models capable of learning complicated patterns and making accurate predictions. However, one of the major challenges in employing neural networks is their sensitivity to distribution shift of the data on which they are trained. Figure 1 shows that the data used to train a model may not be indicative of the data encountered by the model in the real-world. Domain adaptation seeks to address this issue by adapting the model to the target domain, allowing it to generalize more effectively and generate more accurate predictions.
Domain adaptation (DA) is a sub-field of transfer learning that aims to bridge the source and target domains by deriving domain-invariant features from labeled data in the source domain and unlabeled data in the target domain. There has been a surge of interest in employing neural networks for DA in recent years. Many novel algorithms, ranging from simple techniques to more complicated ones, have been presented. These approaches have yielded promising results in a variety of applications, such as computer vision, natural language processing, and speech recognition.
Basically, recent advances in DA are divided mainly into two different types of DA methods: shallow methods and deep methods. The shallow method can be applied to homogeneous and heterogeneous visual tasks, where visual features are extracted from the images. According to [1], features generated by deep models can be repurposed to new tasks and outperform the shallow DA methods even without any adaptation. Inspired by this phenomenon, a commonly accepted paradigm considers the deep model to extract vectorial features as representations for the input image, which can then be used within the shallow DA methods to mitigate the domain discrepancy.
In this work, we present an End2End deep domain adaptation model S2AC, which stands for self-supervised attention CORAL based on Mahalanobis distance. There are two main ideas proposed to improve the previous methods.
First, in our model, the attention architecture relies entirely on attention mechanisms. We stack self-attention blocks and linear layers to draw global dependencies, and insert position encoding between them.
Second, the model leverages recent advances in self-supervised learning to learn representations that can be used for solving other downstream tasks of interest, but requires no label data.
The experimental results illustrate that our method can achieve state-of-the-art performance comparable with previously carefully tuned baselines.
The rest of this paper is organized as follows: Section 3 surveys the theoretical background related to our model; Section 4 describes the proposed S2AC model and provides a theoretical exposition; Section 5 shows experimental results; Section 6 presents the conclusions.

2. Related Work

Shallow DA Methods: Intensive efforts have been made in domain adaptation. Borgwardt et al. [2] introduce the maximum mean discrepancy (MMD) for structured biological data to estimate the differences in distribution between two molecular graph datasets. H. Shimodaira [3] discusses that the inference based on the maximum likelihood estimate (MLE) can be improved by weighting the covariate in the log-likelihood function. In order to adapt the existing classifiers across various video domains, Yang et al. [4] propose adaptive support vector machines (A-SVMs), which adapt the original and the adapted classifier through minimizing an SVM-like objective function.
Deep DA Methods: Deep learning’s advancement has heralded a new era for domain adaptation technology. DDC [5], an acronym for deep domain confusion, discovers the domain confusion metric, which can be utilized to estimate the dimensionality and ideal position of the domain adaptation layer; therefore, a domain confusion loss is introduced to reduce discrepancy between the source and target domains. Conditional domain adversarial networks (CDANs) [6] enhance the classic adversarial domain adaptation by including a conditional branch that takes class label information into account during training. The conditional branch directs the domain classifier in learning domain-invariant characteristics unique to each class. They have been found to be useful in a variety of applications, including sentiment analysis and object identification. In [7], they focus on reconciling the centroid-hypothesis conflict between two loss functions within source-free domain adaptation: the cross-entropy loss inclines to the probability implied by pseudo-labels, but nevertheless, the entropy minimization loss is prone to the class implied by hypothesis. Song et al. [8] introduce stable diffusion and score distillation sampling into a Style-GAN2 to guide the generator towards a target domain under the text prompt. Instead of using the text prompt, d-SNE [9] learns domain-agnostic latent space by using the stochastic neighborhood embedding techniques and a modified Hausdorffian distance. To learn adaptive classifiers, the residual transfer network (RTN) [10] plugs a residual block into CNN architectures to bridge tightly the source classifier and target classifier. To enable feature adaptation, they embed the fused features of multiple layers into Hilbert spaces to match distributions.
Attention Mechanisms: Attention mechanisms, especially self-attention (also called intra-attention), have become an integral part in transformer-related model, and present impressive improvements in various tasks [11,12,13,14,15]. Attention mechanisms are usually used to reweight the features of fully connected or convolutional layers. In [15], they show that inserting an attention layer into AlexNet (a convolutional neural network) used as the backbone network of deep CORAL achieves improved performance. Vaswani et al. [11] introduce a transformer based entirely on attention mechanisms to compute representations of its input on the WMT 2014 English-to-German translation tasks. The attention vectors are invariant during the training process in terms of sequence ordering, otherwise addition of position information can be considered [16]. GANs is a great tool in image-to-image transduction [17,18] and text-to-image translation tasks. Zhang et al. [13] employ an intra-attention module to implement long-range interaction across image regions.
Self-Supervised Model: Recent work shows that self-supervised learning [19] methods can significantly improve the accuracy on image classification tasks for most deep learning cases. Models trained on predefined surrogate tasks learn useful image semantics using only unsupervised data that can be used for solving other downstream tasks of interest. S4L [20] (self-supervised semi-supervised learning), proposed by Zhai et al., reports two techniques: S4L-Rotation rotates input images into four degrees 0 , 90 , 180 , 270 and predicts the rotation degree for each of them, and S4L-exemplar learns a visual invariant representation to image transformations, such as HSV-space color randomization, random mirroring, etc. A key issue for GAN training instability is catastrophic forgetting, which can be countered through introducing temporal memory to the training process. Noroozi and Favaro [21] propose that combining adversarial and self-supervised learning relieves the impact of discriminator forgetting.

3. Theoretical Background

3.1. Mahalanobis Distance-Based CORAL Loss ( L M D C O R A L )

Mahalanobis distance (MD) is a measure that can be seen as a modification of Euclidean distance, with the problem of inconsistent and correlated dimensional scales corrected.
Given two vectors X and Y , the squared MD D M 2 is:
D M 2 = x 1 y 1 λ 1 2 + x 2 y 2 λ 2 2 + + x n y n λ n 2 = x 1 y 1 , x 2 y 2 , , x n y n λ 1 λ 2 λ n x 1 y 1 x 2 y 2 x n y n = X Y Σ 1 X Y
where Σ 1 stands for the inverse of the covariance matrix between X and Y . Correlation alignment (CORAL) [22] proves that aligning second-order statistics (covariances) across domains facilitates learning domain-invariant features that are less affected by domain shift. P-ADC [15] attempted to extend CORAL loss with the idea of p-norm to balance the offset caused by the classification loss, but this led to dilemmas of accuracy and computation time.
CORAL loss L = min ω L C l a s s D S ; ω + α L C O R A L
P - norm loss L = min ω L C l a s s D S ; ω + p λ p L p
The Mahalanobis distance-based loss function (2-norm) is:
L M D C O R A L 2 n o r m = 1 4 d 2 C D S C D T i Σ 1 C D S C D T i
According to [15], as p increases, p-norm loss consumes a large amount of computational resources, leading to a drastic decrease in computing speed. We designed a linear transform to alleviate the conflict between accuracy and computational complexity, and to compensate for the loss of accuracy due to the neglect of higher-order terms.
L M D C O R A L = β 0 + β 1 L M D C O R A L 1 n o r m + β 2 L M D C O R A L 2 n o r m + β 3 L M D C O R A L 3 n o r m where β 0 = 1 + C D S C D T i β 1 = C D S C D T i β 2 = C D S + C D T i 2 n β 3 = 1 3

3.2. Self-Attention

Attention almost entirely replaces recurrence by allowing for a focus on important regions and modeling long-distance dependencies within input or output images. In practice, the queries, keys, and values, packed together into matrices Q, K, and V, are computed as linearly transformed input images x with parameter matrices W Q R C 8 × C , W K R C × C 8 , W V R C 8 × C , respectively. The self-attention function is:
S e l f A t t e n t i o n Q , K , V = s o f t m a x Q K d k V = s o f t m a x W Q x W K x d k W V x
where the input images x = x 1 , x 2 , , x C , x i R W × H are converted to two matrices to compute the attention after being normalized by a softmax function. d k denotes the variance of Q K . Figure 2 shows an example of a 64-channel self-attention block.

3.3. Positional Embedding

Self-attention raises the permutation equivalence without positional information, which limits the expressiveness of the model for visual tasks [23]. Positional embeddings refer to injecting some positional information of the tokens into the features according to different rules. There are two different strategies based on embedded location information. The attention with absolute positional embeddings, which utilizes the absolute position of pixels in an image, is called absolute attention, such as sinusoidal embedding [11], which uses sine and cosine functions to encode each dimension to form a geometric progression whose wavelength is from 2 π to 10 , 000 · 2 π . The attention based on relative positional embeddings, called relative attention, which calculates the relative distance to each location x , y N i , j to receive two offsets for the horizontal and vertical coordinate axes, respectively, i.e., x i , y j , results in improved performance [23]. The relative attention function is:
S e l f A t t e n t i o n r e l a t i v e ( Q , K , V ) = s o f t m a x Q K + Q r x i , r y j d k V

4. Methods

In this section, we present our S2AC approach for unsupervised domain adaptation (UDA) problem. Let a model q ω y | x trained on a labeled source dataset D s composed of source images x s and corresponding labels y s , D s = x s , y s | x s R H × W × C , y s 0 , 1 H × W × K , where W , H , C are the width, height, and channel of the source domain images, respectively; K denotes the number of classes, to be tested over multiple unlabeled target datasets composed of target domain images, D T 1 , D T 2 , , D T n , where D T i = x j T j = 1 N T i is the i t h target dataset and N T i denotes the scale of the target domain D T i .
Our method assumes that q ω y | x is trained in an unsupervised manner; meanwhile, it utilizes only the pretrained model q ω y | x , which works well in the source domain, and an unlabeled target dataset D T i .
Our framework mainly comprises the following three components (see Figure 3):
  • Attention-based backbone network module;
  • Self-supervised learning module;
  • Relative positional embedding.

4.1. Attention-Based Backbone Network Module

An attention-based backbone network module maps features to the space where joint training with the classification loss, the Mahalanobis distance-based CORAL loss, and the self-supervised loss are applied. We consider the total loss function in this study to have the following form:
L = min ω L C l a s s D S ; ω + α L M D C O R A L D S , D T i ; ω + β L s e l f D S ; ω
where L C l a s s is a standard cross-entropy loss of all labeled data in the source domain. L M D C O R A L stands for a linear transformation of the second statistics (covariances) extended by the p-norm to align the distributions of the source and target features. L s e l f is the self-supervised loss that encourages the model to learn useful information. The corresponding self-supervised task is to predict the index of the chosen permutation in this paper.
The backbone network is composed of a stack of N = 5 identical layers, followed by layer position encoding and two linear layers. Each layer has two sub-layers. The first is a self-attention mechanism and the second is max-pooling layer. We employ a residual connection inside the self-attention mechanism. That is, the output of each layer is H i = M a x ( R e L U ( x i 1 + S e l f A t t e n t i o n ( Q , K , V ) ) ) (see Figure 4), where M a x ( · ) is the function implemented by the max-pooling layer itself. To leverage these residual connections, the dimensions of input and output must be equal for all self-attention modules; thus, we set k e r n e l _ s i z e = 1 , s t r i d e = 1 , p a d d i n g = 0 for query, key, and value matrices in convolution-based attention.

4.2. Self-Supervised Learning Module

A self-supervised auxiliary task (called Random Context Prediction) module that transforms both given source and target data samples along with two prominent self-supervised techniques was adopted in our framework: context prediction + random rotation. Following [19,21], context prediction, as a “pretext”, forces the model to understand scenes and objects. The main idea is to learn general-purpose representation by exploiting the relative spatial location as labels that come for “free” within images. Doersch et al. [19]’s sample randomly pairs of patches in a three-by-thre grid. In their approach, one tile is the pivot kept in middle of a three-by-three grid; the other can be any of the eight remaining available locations for each pair. In contrast, ref. [21] observes all nine tiles through associating with the Jigsaw puzzle reassembly problem. A set of jigsaw puzzle permutations is defined, as well as the corresponding index for each item. To learn image representation, the Jigsaw puzzle solver shuffles the input tiles base on the set of permutations to predict the relevant index. However, since the number of possible permutations of nine tiles, which is 9 ! , is too numerous to be applied directly, a subset must be established, which is also time-consuming (see Section 5). In this study, we combine two strategies to create a novel, harder, and more efficient pretext task. Following [21], we generate the subset using “random” sampling rather than Hamming distance. To achieve end-to-end processing, it is also feasible to omit subset creation and just perform random selection in the original matrix. We crop a region from an image at random and divide it into nine patches, which are rearranged according to a randomly selected permutation. At the same time, each patch rotates at a “random” degree, which is generally picked from 0 , 90 , 180 , 270 (see Figure 5).
The self-supervised loss is:
L s e l f x , m ; ω , μ = 1 N M N D S D T i m M x D S D T i L C E p f ω x m ; μ , g m = 1 N M N D S D T i m M x D S D T i g m ln p f ω x m ; μ
where M stands for the predefined permutation set. x r is the input x reordered via a randomly chosen permutation from m and rotated via a randomly chosen degree from 0 , 90 , 180 , 270 . g · is the mapping of the jigsaw puzzle permutations to 1 , 2 , , 9 ! , e.g., 6 , 3 , 7 , 2 , 9 , 1 , 4 , 8 , 5 53 ; N denotes the number of candidates. D T i is the target domain. f ω · illustrates the model with parameters ω . p · , μ denotes the joint probability as p i , j x ; μ = e μ i , j x k , l e μ k , l x .

4.3. Relative Positional Embedding

It has been proven in [11,23] that employing positional embeddings results in more efficient and accurate models. However, the definition of early relative position embeddings only takes into account relative distance, i.e., row offset and column offset, which is irrelevant to the picture content. Unlike earlier literature, our strategy attaches the relative position to the model, converting it into a trainable type that can be tuned during parameter optimization. Using x i , y j as the base point, the relative distance of and other point x j , y j in the image to x i , y j is x d , y d (see Figure 6). The relative distance x d , y d is associated with embeddings r x d , r y d .
x i = σ p 1 w 2 w 1 + w 1 , 0 w 1 < w 2 W
y i = σ p 2 h 2 h 1 + h 1 , 0 h 1 < h 2 H
x d = x j x i
y d = y j y i
where x i , y i stand for the horizontal and vertical coordinates of the base point. x j , y j are the horizontal and vertical coordinates of any point on feature map. p 1 , p 2 represent trainable parameters that are optimized during model training. σ x = 1 1 + e x , is the sigmoid function. For example, given a 5 × 5 feature map implying W = H = 5 and also x i = 2 , y i = 3 after backpropagation computed from Equations (10) and (11), the positional embedding matix is: ( 0 , 0 ) ( 0 , 1 ) ( 0 , 2 ) ( 0 , 3 ) ( 0 , 4 ) ( 1 , 0 ) ( 1 , 1 ) ( 1 , 2 ) ( 1 , 3 ) ( 1 , 4 ) ( 2 , 0 ) ( 2 , 1 ) ( 2 , 2 ) ( 2 , 3 ) ( 2 , 4 ) ( 3 , 0 ) ( 3 , 1 ) ( 3 , 2 ) ( 3 , 3 ) ( 3 , 4 ) ( 4 , 0 ) ( 4 , 1 ) ( 4 , 2 ) ( 4 , 3 ) ( 4 , 4 ) h 1 = w 1 = 2 , h 2 = w 2 = 3 x i = 2 , y i = 3 ( 2 , 3 ) ( 2 , 2 ) ( 2 , 1 ) ( 2 , 0 ) ( 2 , 1 ) ( 1 , 3 ) ( 1 , 2 ) ( 1 , 1 ) ( 1 , 0 ) ( 1 , 1 ) ( 0 , 3 ) ( 0 , 2 ) ( 0 , 1 ) ( 0 , 0 ) ( 0 , 1 ) ( 1 , 3 ) ( 1 , 2 ) ( 1 , 1 ) ( 1 , 0 ) ( 1 , 1 ) ( 2 , 3 ) ( 2 , 2 ) ( 2 , 1 ) ( 2 , 0 ) ( 2 , 1 ) .

5. Experimental Results

5.1. Setup

In this study, we perform experiments on a computer that has an Intel(R) Xeon(R) Silver 4210R CPU, 64-bit 2.4GHz (two processors), and an NVIDIA Tesla T4 GPU. We evaluate our model on three image datasets: Office31 [24], Office_Caltech_10 [1], OfficeHome [25].
Office31 is a classic collection of images of objects from 31 distinct categories commonly encountered in office environments, including headphones, bottles, speakers, etc. It has 4652 images in total, with an average of 150 images per category. Three domains in the dataset are Amazon (A), DSLR (D), and Webcam (W).
Office_Caltech_10 is divided into two parts: the office part and the Caltech part. The office part contains images of office scenes, while the Caltech part contains images of Caltech scenes. It contains ten overlapping categories shared by four domains: Amazon (A), Caltech (C), DSLR (D), and Webcam (W).
OfficeHome contains images from four different workplace and home contexts. It includes images of objects from four different domains: Art (A), Clipart (C), Product (P), and Real-World (R). The dataset includes 15,588 images from 65 different categories, with a total of 4652 images from each domain.
Our model takes images of 224 × 224 pixels as input, and the weight decay and momentum are set to 5 × 10 4 and 0.9 , respectively; the initial learning rate is 1 × 10 3 as well. Because of GPU memory limitations, both our train_batch size and test_batch size are set to 8.

5.2. Selection of Criteria for Generating Permutation Subset

The original 9 ! -item permutation set in [21] is too large to be directly used in the computation; thus, the jigsaw puzzle solver must employ an external process, which is a non-end-to-end process, to calculate a subset of the permutations by hamming distance. We suggest using uniform random sampling to create the permutation subset in real time, which will increase the model’s efficacy.
We designed this experiment to show the time difference between executing three criteria, i.e., Mean Hamming distance, Max Hamming distance, and Random sampling, to generate the set of permutations. We discover that as the number of permutations increases, computing the Hamming distance has a substantial impact on running time when compared with random sampling, while the improvement in test accuracy is not significant. The runs are shown in Table 1. Based on the experiment results, we conclude that the use of random sampling can significantly reduce the running time without significantly affecting the accuracy.
Figure 7 displays us three graphs created from shift D W to help us analyze S2AC. In Figure 7a, we show the classification loss, the Mahalanobis distance-based CORAL loss, the self-supervised learning loss, and the total loss for the training phrase. The classification loss is initially significantly bigger than both the Mahalanobis distance-based CORAL loss and the self-supervised learning loss, but as iterations progress, the classification loss becomes minimal at around e p o c h s = 50 and progressively stabilizes and converges. The Mahalanobis distance-based CORAL loss exhibits a notable growth between iteration cycles 20 and 40, but beyond 50, it steadily declines and converges. In Figure 7b, we visualize the average loss for the test phrase in the source and target domains. The plot shows that the average loss is generally on the decline in both the source and target domains. The fluctuation of the training (source) and test (target) accuracy is shown in Figure 7c. Figure 7d shows the performance of Frobenius distance, Mahalanobis distance, earth mover’s distance (EMD), Chebyshev distance, and cosine distance matrices. The EMD fluctuations are excessively large, and the Frobenius distance-based loss function is weaker than our method in this scenario, while the Chebyshev distance-based loss and the cosine distance-based loss continue to rise in the latter phases, causing the total loss to be poorly converged (see Figure 7e–g).

5.3. Ablation Studies

We designed an ablation analysis of the influence of the attention-based backbone network, the self-supervised learning module, and positional embedding. Figure 8 shows the classification accuracy curves. For convenience, ‘-S’, and ‘-T’ denote training and test accuracy, respectively. And incorporation of only the AlexNet [26], instead of the attention-based backbone network, pretrained on ImageNet [27], is called S2AC-AlexNet-S/T pretrained. The corresponding settings are shown in Table 2. The table shows that if AlexNet was replaced by the proposed attention-based backbone network, the test accuracy would increase by about 3% points, mainly benefiting from learning long-range dependencies, which is a main challenge for convolutional neural networks. Furthermore, if the extractor is pretrained, it will converge quicker in both the training and testing phases. But nevertheless, the final accuracy in the training phase is 0.3% points lower for S2AC-AlexNet-S pretrained than S2AC-AlexNet-S, and the test accuracy is about 1.5% points lower for S2AC-AlexNet-S pretrained than S2AC-AlexNet-S. This demonstrates that pre-training has no significant effects on the model’s identification accuracy, but only on its convergence speed. The pre-training procedure cannot be used for S2AC since the brand new backbone network for the weights pre-trained on ImageNet does not exist.
When we compare test accuracy alone, S2AC-AlexNet-S pretrained fluctuates the most after convergence, while S2AC is more stable than S2AC-AlexNet-S. Nevertheless, S2AC has the highest test accuracy when compared with S2AC-AlexNet-S.
The validity of positional embedding has been demonstrated [23], and the purpose of this experiment is to see if positional embedding is more effective for the domain adaptation problem when employed in the source and target domains individually, or in both domains. For convenience, not performing the positional embedding operation in both source and target domains is called S2AC-∼S&∼T; adding location information in the source domain but not in the target domain is called S2AC-S&∼T; and vice versa is referred to as S2AC-∼S&T.
Figure 9 illustrates that positional embedding brings a significant rise of the accuracy, consequently resulting in an increase in F1 score from 73.33% to 85.74% (see Table 3). This highlights the effectiveness of location information in domain adaptation tasks heavy with the ability to present a more detailed representation of this information. Nevertheless, adding positional information to each domain does not improve operational outcomes compared with no location information. In fact, superior recognition accuracy requires only positional embedding in the target domain.
Last but not least, we attempt to tweak the self-supervised learning module in order to compare and analyze its influence on the model’s performance. Similarly, we set up the self-supervised learning module in the source and target domains, respectively, and compare the test accuracy. As for the legends of tables and figures, S2AC-S&T represents the execution of self-supervised learning in both the source and target domains; S2AC-S&!T denotes performing only the self-supervised module in the source domain; and S2AC-!S&T is the exact opposite, executed only in the target domain.
As observed in Figure 10, the self-supervised learning module has made a noteworthy contribution to the enhancement of the model’s test accuracy. In terms of convergence speed and stability of the algorithm, the two models, S2AC-S&T and S2AC-!S, perform the best, with S2AC-S&T exhibiting a faster convergence rate than S2AC-!S. Although S2AC-!S initially displayed the highest test accuracy, S2AC-S&T tends to outperform the previous one towards the end of the iteration. The trend is further evidenced by the F1 scores, where S2AC-S&T’s final score of 83.21% is about 5 points higher than S2AC-!S&T’s score of 78.67%; see Table 4.

5.4. The Network Visualization and Impacts of Training Dataset Size

Although understanding the mechanism of deep neural networks can be arduous, certain visual clues reveal that S2AC is capable of fusing two domains to achieve domain adaptation. In order to guarantee fair comparison, we trained both models for 160 epochs. Figure 11 shows feature maps extracted by the model. One can see that the model learned the contour information of the object compared with AlexNet during the training phase (see Figure 11a), while also exhibiting competitive feature extraction capacity during the test phase (see Figure 11b). The first figure of Figure 11a) shows that two regions are activated corresponding to the top and bottom of the object, respectively, in the left, while only the region corresponding to the bottom of the object in the right (extracted by AlexNet). For the test phase, the second figure of Figure 11b demonstrates that S2AC (left) activates the majority of the light-colored areas, and the dark-colored region activated weakly can basically distinguish the shape of the object, whereas the right (AlexNet) cannot represent the outline of the object due to the lack of activated regions.
We also investigated the influence of dataset size on domain adaptation. Five training datasets of varying sizes were created and used for evaluation. In addition to the whole dataset, 100, 200, 300, and 400 images were randomly chosen from the source domain to create a new dataset. The corresponding F1 score curves are shown in Figure 12b. From the figure, we conclude that the model’s performance improves as the size of the training set increases. The F1 curve shows a trend of fast forward and slow backward, indicating that the number of images is less than 350 and the F1 score grows rapidly as the number increases. As the dataset size, 350, increases, the performance improvement slows down and tends to saturate. Table 5 depicts F1, recall, precision score, and the micro AP. The corresponding P-R curves are shown in Figure 12a.

5.5. Discussion

In this experiment, we chose one of the domains at random as the source domain for training and another as the target domain. The labels of the source domain are inherently known, while the labels of all target domains remain unknown. To compare the effectiveness of our method, in addition to a variant of S2AC with AlexNet, we evaluated popular algorithms, such as deep domain confusion (DDC), conditional domain adversarial networks (CDANs), etc., on the Office31, Office_Caltech_10, and OfficeHome datasets.
As seen in Table 6, our method (S2AC) obtained higher average performance than the other baseline approaches on the Office31 dataset. S2AC had the greatest running accuracy in four out of the six shifts. CDAN(+E) received the highest scores in the other two shifts.
In Table 7, we evaluated our method on Office_Caltech_10 compared with other baseline algorithms. The Office_Caltech_10 dataset contains four domains: Caltech, DLSR, Amazon, and Webcam. Three of them, i.e., DLSR, Amazon, and Webcam, are from the Office31 Dataset. To avoid duplication of effort, Table 7 simply compares the shifts of Caltech with the other three domains (DLSR, Amazon, and Webcam); hence, Table 7 only includes six shifts ( A C , D C , etc.). In three out of the six shifts, our algorithm performs best, and the gap between S2AC and the best baseline method in the other three shifts is extremely small (⩽2 approximately), which illustrates its effectiveness on this dataset.
The results on OfficeHome are reported in Table 8, in most transfer tasks, the S2AC-model beats other baseline methods, demonstrating high performance and potential for improvement. One can see that OfficeHome contains more categories and a larger volume than the other two datasets, which are visually more distinct from each other, and hence are more difficult to classify because of their substantially lower classification accuracy within the domain [28]. Since the prior work’s feature extraction is distance-agnostic, the extracted features are unsuitable for classification in the presence of a large number of categories.
In the tables, AttNet-5 represents a five-layer stack, and it is interesting to note that although the number of layers in the stack is less than ResNet-34, AlexNet, S2AC outperforms them in most cases. Since the number of layers of AttNet-5 is significantly smaller than ResNet-34, AlexNet, its convergence is faster and it is easier to train. In addition, considering the hardware environment, we did not include ResNet-50, ResNet-101 in the Table 6, Table 7 and Table 8; researchers who are able to do so might use it as a starting point for their study.
Table 6. Performance comparison for all six domain shifts on Office31. A: Amazon, D: DLSR, W: Webcam.
Table 6. Performance comparison for all six domain shifts on Office31. A: Amazon, D: DLSR, W: Webcam.
MethodBackboneAWADWAWDDADW
No AdaptationAlexNet [29]35.3 ± 0.522.3 ± 1.230.2 ± 0.537.4 ± 1.621.2 ± 0.639.5 ± 0.3
ResNet-34 [30]37.6 ± 0.725.5 ± 0.632.8 ± 0.439.4 ± 0.424.3 ± 0.939.3 ± 0.5
DDC [5]Deep CNN [5]43.3 ± 0.830.2 ± 1.435.6 ± 0.745.6 ± 1.325.3 ± 0.565.4 ± 0.4
CDAN [6]AlexNet [29]41.4 ± 1.936.2 ± 1.635.1 ± 1.575.2 ± 0.638.4 ± 1.565.6 ± 1.6
ResNet-34 [30]44.7 ± 0.437.4 ± 0.638.1 ± 0.776.7 ± 0.940.6 ± 1.666.3 ± 0.8
CDAN+E [6]AlexNet [29]45.5 ± 0.637.4 ± 1.638.2 ± 0.672.4 ± 1.535.7 ± 0.4368.4 ± 1.5
ResNet-34 [30]47.3 ± 0.540.5 ± 0.639.7 ± 1.674.7 ± 0.740.1 ± 1.171.5 ± 0.7
Deep CORAL [31]AlexNet [29]50.5 ± 0.738.1 ± 1.537.9 ± 0.671.4 ± 0.638.6 ± 0.860.2 ± 0.7
P-ADC [15]AlexNet [29] with an attention layer51.4 ± 0.940.3 ± 0.739.5 ± 0.673.9 ± 0.540.1 ± 0.763.8 ± 0.5
S2AC-AlexNetAlexNet [29]56.8 ± 0.744.0 ± 1.239.8 ± 0.974.7 ± 1.740.9 ± 1.163.6 ± 0.7
S2ACAttNet-556.8 ± 1.145.6 ± 1.440.2 ± 0.575.9 ± 0.741.5 ± 0.661.6 ± 1.6
Table 7. Performance comparison for six domain shifts on Office_Caltech_10. C: Caltech, D: DLSR, A: Amazon, W: Webcam.
Table 7. Performance comparison for six domain shifts on Office_Caltech_10. C: Caltech, D: DLSR, A: Amazon, W: Webcam.
MethodBackbone A C D C W C C A C D C W
No AdaptationAlexNet [29]42.0 ± 0.426.5 ± 1.535.0 ± 0.945.3 ± 0.950.5 ± 0.549.2 ± 0.6
ResNet-34 [30]45.8 ± 0.731.4 ± 0.646.2 ± 0.347.5 ± 0.446.5 ± 0.651.3 ± 1.1
DDC [5]Deep CNN [5]64.4 ± 0.854.4 ± 0.968.4 ± 1.274.5 ± 1.452.4 ± 0.464.8 ± 0.7
CDAN [6]AlexNet [29]62.5 ± 0.960.2 ± 1.971.4 ± 1.973.6 ± 0.653.4 ± 0.564.3 ± 1.7
ResNet-34 [30]65.2 ± 0.463.3 ± 0.469.6 ± 0.974.3 ± 1.358.4 ± 0.668.4 ± 0.6
CDAN+E [6]AlexNet [29]64.9 ± 1.563.4 ± 1.171.3 ± 0.275.6 ± 0.860.4 ± 0.970.5 ± 1.2
ResNet-34 [30]67.2 ± 0.567.8 ± 0.773.2 ± 0.780.0 ± 1.263.6 ± 0.569.1 ± 0.8
Deep CORAL [31]AlexNet [29]74.8 ± 0.966.6 ± 0.667.4 ± 0.381.9 ± 0.760.2 ± 0.970.5 ± 1.3
P-ADC [15]AlexNet [29] with an attention layer76.5 ± 0.268.5 ± 0.170.7 ± 0.784.6 ± 0.163.8 ± 0.372.4 ± 0.2
S2AC-AlexNetAlexNet [29]72.5 ± 0.161.5 ± 0.169.6 ± 0.385.2 ± 0.255.7 ± 0.374.4 ± 0.2
S2ACAttNet-579.3 ± 0.467.4 ± 0.271.1 ± 0.283.9 ± 0.369.8 ± 0.375.7 ± 0.5
Table 8. Performance comparison for 12 domain shifts on OfficeHome. A: Art, C: Clipart, P: Product, R: Real-World.
Table 8. Performance comparison for 12 domain shifts on OfficeHome. A: Art, C: Clipart, P: Product, R: Real-World.
MethodBackbone A C A P A R C A C P C R P A P C P R R A R C R P
No AdaptationAlexNet [29]35.6 ± 0.333.6 ± 1.340.0 ± 0.427.5 ± 0.533.1 ± 0.329.6 ± 0.237.4 ± 0.832.7 ± 1.028.4 ± 0.630.3 ± 0.741.5 ± 0.337.3 ± 0.4
ResNet-34 [30]34.9 ± 0.538.4 ± 0.645.7 ± 0.438.0 ± 1.035.8 ± 0.532.7 ± 0.639.1 ± 1.339.1 ± 0.534.6 ± 1.134.8 ± 0.749.6 ± 0.241.5 ± 0.9
DDC [5]Deep CNN [5]41.0 ± 1.454.5 ± 0.663.4 ± 0.653.4 ± 0.666.9 ± 0.445.8 ± 1.049.5 ± 0.555.9 ± 0.739.4 ± 0.348.1 ± 1.671.5 ± 0.866.4 ± 0.6
CDAN [6]AlexNet [29]51.9 ± 1.753.7 ± 0.965.1 ± 2.171.4 ± 1.163.3 ± 0.651.4 ± 1.751.8 ± 0.758.5 ± 1.447.8 ± 0.449.7 ± 2.173.1 ± 0.767.1 ± 0.1
ResNet-34 [30]52.4 ± 0.555.3 ± 0.365.7 ± 1.069.3 ± 0.664.1 ± 0.957.2 ± 0.654.9 ± 0.759.1 ± 0.949.2 ± 0.850.1 ± 1.475.6 ± 0.968.5 ± 0.7
CDAN+E [6]AlexNet [29]55.3 ± 0.660.4 ± 1.567.1 ± 1.675.3 ± 1.065.2 ± 0.855.7 ± 1.161.7 ± 0.761.4 ± 2.049.9 ± 0.951.5 ± 0.775.8 ± 0.869.5 ± 0.7
ResNet-34 [30]60.2 ± 0.658.1 ± 0.966.9 ± 0.776.1 ± 0.666.9 ± 0.659.5 ± 0.663.1 ± 0.662.7 ± 0.950.6 ± 0.653.5 ± 0.674.0 ± 0.669.9 ± 0.7
Deep CORAL [31]AlexNet [29]54.6 ± 0.862.4 ± 1.367.1 ± 0.576.7 ± 0.567.5 ± 0.360.6 ± 0.760.5 ± 0.862.6 ± 0.645.7 ± 0.554.4 ± 1.473.1 ± 0.569.6 ± 0.5
P-ADC [15]AlexNet [29] with an attention layer55.2 ± 0.562.1 ± 0.865.6 ± 1.275.0 ± 0.868.1 ± 0.261.1 ± 0.462.7 ± 1.461.9 ± 0.747.1 ± 0.456.1 ± 0.972.2 ± 1.370.2 ± 0.9
S2AC-AlexNetAlexNet [29]56.3 ± 1.761.3 ± 0.768.1 ± 0.576.7 ± 0.668.0 ± 0.965.3 ± 0.561.3 ± 1.162.6 ± 0.350.2 ± 0.656.5 ± 0.373.7 ± 0.770.3 ± 1.3
S2ACAttNet-556.9 ± 0.862.6 ± 0.668.1 ± 0.677.6 ± 1.068.5 ± 0.664.5 ± 0.762.1 ± 0.463.6 ± 1.153.2 ± 0.557.6 ± 0.676.4 ± 1.271.8 ± 0.9

5.6. Computational Complexity

We calculated the average training time over all the cross-domain scenarios on the Office31 dataset to compare the time complexity of our approach to other baseline algorithms, as shown in Table 9. When comparing to other algorithms, Deep CORAL has the lowest computational complexity. Overall, the adversarial-based approach is more computationally difficult than the distance-based approach. Both S2AC and P-ADC are located in the 12-s average computing time echelon, just behind Deep CORAL.

6. Conclusions and Future Work

Our study suggests a self-supervised attention CORAL based on a Mahalanobis distance approach for domain adaptation, based on the attention mechanism. This technique might eliminate certain influences from data insufficiency, enhance local extraction reliance, and increase the test accuracy of base algorithms, such as deep CORAL. Several ideas are applied to attain these improvements. To begin with, the attention architecture facilitates attribute extraction, which aids in the learning to long-distance dependencies and allows for enhanced attribute reuse. The second is that the incorporation of self-supervised learning enables S2AC to acquire high-quality representations even with limited labeled data, which can be utilized to learn new tasks that lack sufficient data. Integating these modules, S2AC constructs an adaptation model that is completely independent of pretrained models for feature extraction, with a global receptive field and that are pseudo-label-free.
Numerous experimental results show that it is effective and exceeds other compared algorithms in terms of test accuracy and time efficiency.
We hope that our work stimulates researchers in other fields to consider using this approach to broaden their research horizons, as well as domain adaptation researchers to be inspired by the great number of innovative methods that have lately been proposed.
In the future, category information will be considered to improve the domain alignment performance, particularly the utilization of object and background information in the same category in different domains. Moreover, in the absence of knowledge about the target domain, information about multiple source domains will be studied and generalized to unseen domains in diverse environments.

Author Contributions

Conceptualization, Z.-Y.W. and C.-P.Z.; methodology, Z.-Y.W.; software, Z.-Y.W. and C.-P.Z.; validation, D.-K.K.; formal analysis, Z.-Y.W. and D.-K.K.; investigation, Z.-Y.W. and C.-P.Z.; resources, D.-K.K.; data curation, C.-P.Z.; writing—original draft preparation, Z.-Y.W. and C.-P.Z.; writing—review and editing, D.-K.K.; visualization, Z.-Y.W. and C.-P.Z.; supervision, D.-K.K.; project administration, D.-K.K.; funding acquisition, Z.-Y.W. and D.-K.K. All authors have read and agreed to the published version of the manuscript.

Funding

This research was supported by the Basic Science Research Program through the National Research Foundation of Korea (NRF) funded by the Ministry of Science and ICT (NRF-2022R1A2C2012243). First author was supported in part by Weifang University of Science and Technology Doctoral Fund Project under grant (2021KJBS14).

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Publicly available datasets were analyzed in this study. These data can be found here (accessed on 9 September 2023): [https://faculty.cc.gatech.edu/~judy/domainadapt/] and [https://www.hemanthdv.org/officeHomeDataset.html].

Acknowledgments

The authors wish to thank members of the Dongseo University Machine Learning/Deep Learning Research Lab., and anonymous referees for their helpful comments on earlier drafts of this paper.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Csurka, G. A comprehensive survey on domain adaptation for visual applications. In Domain Adaptation in Computer Vision Applications; Springer: Cham, Switzerland, 2017; pp. 1–35. [Google Scholar]
  2. Borgwardt, K.M.; Gretton, A.; Rasch, M.J.; Kriegel, H.P.; Schölkopf, B.; Smola, A.J. Integrating structured biological data by kernel maximum mean discrepancy. Bioinformatics 2006, 22, e49–e57. [Google Scholar] [CrossRef] [PubMed]
  3. Shimodaira, H. Improving predictive inference under covariate shift by weighting the log-likelihood function. J. Stat. Plan. Inference 2000, 90, 227–244. [Google Scholar] [CrossRef]
  4. Yang, J.; Yan, R.; Hauptmann, A.G. Cross-domain video concept detection using adaptive svms. In Proceedings of the 15th ACM international conference on Multimedia, Augsburg, Germany, 24–29 September 2007; pp. 188–197. [Google Scholar]
  5. Tzeng, E.; Hoffman, J.; Zhang, N.; Saenko, K.; Darrell, T. Deep domain confusion: Maximizing for domain invariance. arXiv 2014, arXiv:1412.3474. [Google Scholar]
  6. Long, M.; Cao, Z.; Wang, J.; Jordan, M.I. Conditional adversarial domain adaptation. Adv. Neural Inf. Process. Syst. 2018, 31, 1640–1650. [Google Scholar]
  7. Diamant, I.; Jennings, R.H.; Dror, O.; Habi, H.V.; Netzer, A. Reconciling a Centroid-Hypothesis Conflict in Source-Free Domain Adaptation. arXiv 2022, arXiv:2212.03795. [Google Scholar]
  8. Song, K.; Han, L.; Liu, B.; Metaxas, D.; Elgammal, A. Diffusion Guided Domain Adaptation of Image Generators. arXiv 2022, arXiv:2212.04473. [Google Scholar]
  9. Xu, X.; Zhou, X.; Venkatesan, R.; Swaminathan, G.; Majumder, O. d-sne: Domain adaptation using stochastic neighborhood embedding. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, Long Beach, CA, USA, 16–20 June 2019; pp. 2497–2506. [Google Scholar]
  10. Long, M.; Zhu, H.; Wang, J.; Jordan, M.I. Unsupervised domain adaptation with residual transfer networks. Adv. Neural Inf. Process. Syst. 2016, 29, 136–144. [Google Scholar]
  11. Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A.N.; Kaiser, Ł.; Polosukhin, I. Attention is all you need. Adv. Neural Inf. Process. Syst. 2017, 30, 5998–6008. [Google Scholar]
  12. Pedro, R.; Oliveira, A.L. Assessing the impact of attention and self-attention mechanisms on the classification of skin lesions. In Proceedings of the 2022 International Joint Conference on Neural Networks (IJCNN), Padua, Italy, 18–23 July 2022; IEEE: Piscataway, NJ, USA, 2022; pp. 1–8. [Google Scholar]
  13. Zhang, H.; Goodfellow, I.; Metaxas, D.; Odena, A. Self-attention generative adversarial networks. In Proceedings of the International Conference on Machine Learning, Long Beach, CA, USA, 9–15 June 2019; pp. 7354–7363. [Google Scholar]
  14. Trockman, A.; Kolter, J.Z. Patches are all you need? arXiv 2022, arXiv:2201.09792. [Google Scholar]
  15. Wang, Z.Y.; Kang, D.K. P-norm attention deep coral: Extending correlation alignment using attention and the p-norm loss function. Appl. Sci. 2021, 11, 5267. [Google Scholar] [CrossRef]
  16. Shaw, P.; Uszkoreit, J.; Vaswani, A. Self-attention with relative position representations. arXiv 2018, arXiv:1803.02155. [Google Scholar]
  17. Zhu, J.Y.; Park, T.; Isola, P.; Efros, A.A. Unpaired image-to-image translation using cycle-consistent adversarial networks. In Proceedings of the IEEE International Conference on Computer Vision, Venice, Italy, 22–29 October 2017; pp. 2223–2232. [Google Scholar]
  18. Park, T.; Liu, M.Y.; Wang, T.C.; Zhu, J.Y. Semantic image synthesis with spatially-adaptive normalization. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, Long Beach, CA, USA, 15–20 June 2019; pp. 2337–2346. [Google Scholar]
  19. Doersch, C.; Gupta, A.; Efros, A.A. Unsupervised visual representation learning by context prediction. In Proceedings of the IEEE International Conference on Computer Vision, Santiago, Chile, 7–13 December 2015; pp. 1422–1430. [Google Scholar]
  20. Zhai, X.; Oliver, A.; Kolesnikov, A.; Beyer, L. S4l: Self-supervised semi-supervised learning. In Proceedings of the IEEE/CVF International Conference on Computer Vision, Seoul, Republic of Korea, 27 October–2 November 2019; pp. 1476–1485. [Google Scholar]
  21. Noroozi, M.; Favaro, P. Unsupervised learning of visual representations by solving jigsaw puzzles. In Proceedings of the European Conference on Computer Vision, Amsterdam, The Netherlands, 11–14 October 2016; Springer: Berlin/Heidelberg, Germany, 2016; pp. 69–84. [Google Scholar]
  22. Sun, B.; Feng, J.; Saenko, K. Return of frustratingly easy domain adaptation. In Proceedings of the AAAI Conference on Artificial Intelligence, Phoenix, AZ, USA, 12–17 February 2016; Volume 30. [Google Scholar]
  23. Ramachandran, P.; Parmar, N.; Vaswani, A.; Bello, I.; Levskaya, A.; Shlens, J. Stand-Alone Self-Attention in Vision Models. arXiv 2019, arXiv:1906.05909. [Google Scholar]
  24. Saenko, K.; Kulis, B.; Fritz, M.; Darrell, T. Adapting visual category models to new domains. In Proceedings of the Computer Vision–ECCV 2010: 11th European Conference on Computer Vision, Heraklion, Crete, Greece, 5–11 September 2010; Proceedings, Part IV 11. Springer: Berlin/Heidelberg, Germany, 2010; pp. 213–226. [Google Scholar]
  25. Venkateswara, H.; Eusebio, J.; Chakraborty, S.; Panchanathan, S. Deep hashing network for unsupervised domain adaptation. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Honolulu, HI, USA, 21–26 July 2017; pp. 5018–5027. [Google Scholar]
  26. Krizhevsky, A.; Sutskever, I.; Hinton, G.E. ImageNet Classification with Deep Convolutional Neural Networks. In Advances in Neural Information Processing Systems; Pereira, F., Burges, C., Bottou, L., Weinberger, K., Eds.; Curran Associates, Inc.: Red Hook, NY, USA, 2012; Volume 25. [Google Scholar]
  27. Deng, J.; Dong, W.; Socher, R.; Li, L.J.; Li, K.; Fei-Fei, L. Imagenet: A large-scale hierarchical image database. In Proceedings of the 2009 IEEE Conference on Computer Vision and Pattern Recognition, Miami, FL, USA, 20–25 June 2009; IEEE: Piscataway, NJ, USA, 2009; pp. 248–255. [Google Scholar]
  28. Tzeng, E.; Hoffman, J.; Darrell, T.; Saenko, K. Simultaneous deep transfer across domains and tasks. In Proceedings of the IEEE International Conference on Computer Vision, Santiago, Chile, 7–13 December 2015; pp. 4068–4076. [Google Scholar]
  29. Krizhevsky, A.; Sutskever, I.; Hinton, G.E. Imagenet classification with deep convolutional neural networks. Commun. ACM 2017, 60, 84–90. [Google Scholar] [CrossRef]
  30. He, K.; Zhang, X.; Ren, S.; Sun, J. Deep residual learning for image recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Las Vegas, NV, USA, 26 June–1 July 2016; pp. 770–778. [Google Scholar]
  31. Sun, B.; Saenko, K. Deep coral: Correlation alignment for deep domain adaptation. In Proceedings of the Computer Vision–ECCV 2016 Workshops, Amsterdam, The Netherlands, 8–10, 15–16 October 2016; Proceedings, Part III 14. Springer: Berlin/Heidelberg, Germany, 2016; pp. 443–450. [Google Scholar]
  32. Ganin, Y.; Ustinova, E.; Ajakan, H.; Germain, P.; Larochelle, H.; Laviolette, F.; Marchand, M.; Lempitsky, V. Domain-adversarial training of neural networks. J. Mach. Learn. Res. 2016, 17, 2030–2096. [Google Scholar]
Figure 1. Added Training data differ significantly from the data in the real-world scenario. Source domain (upper) is pre-processed studio images that are very different from the real-world scenario (lower), which is called domain shift.
Figure 1. Added Training data differ significantly from the data in the real-world scenario. Source domain (upper) is pre-processed studio images that are very different from the real-world scenario (lower), which is called domain shift.
Electronics 12 04419 g001
Figure 2. Illustration of a 64-channel self-attention block. Given the original image (1st column, three channels), we compute the input x, which is 64 feature maps (2nd column) by convolutional layer with parameters i n _ c h a n n e l s = 3 , o u t _ c h a n n e l s = 64 . Out attention is just a dot-product between queries and keys, i.e., Q K d k , scaled by its standard deviation.
Figure 2. Illustration of a 64-channel self-attention block. Given the original image (1st column, three channels), we compute the input x, which is 64 feature maps (2nd column) by convolutional layer with parameters i n _ c h a n n e l s = 3 , o u t _ c h a n n e l s = 64 . Out attention is just a dot-product between queries and keys, i.e., Q K d k , scaled by its standard deviation.
Electronics 12 04419 g002
Figure 3. An overview of the proposed model.
Figure 3. An overview of the proposed model.
Electronics 12 04419 g003
Figure 4. An overview of feature extraction module. H i is the operation Attention-ReLU-MaxPool2d. ⨁ denotes the summation of the corresponding elements. ⨂ indicates the dot product operation.
Figure 4. An overview of feature extraction module. H i is the operation Attention-ReLU-MaxPool2d. ⨁ denotes the summation of the corresponding elements. ⨂ indicates the dot product operation.
Electronics 12 04419 g004
Figure 5. The algorithm is given nine rearranged and rotated tiles, and then predicts the index in the predefined permutation set.
Figure 5. The algorithm is given nine rearranged and rotated tiles, and then predicts the index in the predefined permutation set.
Electronics 12 04419 g005
Figure 6. Positional embedding. The middle rectangle indicates the range of x i , y i , i.e., w 1 x i w 2 , h 1 y i h 2 . The outer rectangle is the feature map, which is also the range of x j , y j , the width and height are W and H, respectively. · represents the pixel coordinate, the origin is O, and · is the relative position with respect to O’.
Figure 6. Positional embedding. The middle rectangle indicates the range of x i , y i , i.e., w 1 x i w 2 , h 1 y i h 2 . The outer rectangle is the feature map, which is also the range of x j , y j , the width and height are W and H, respectively. · represents the pixel coordinate, the origin is O, and · is the relative position with respect to O’.
Electronics 12 04419 g006
Figure 7. Detailed analysis of shift D W for training S2AC. (a) The curves of the loss function (our method). (b) Testing the average loss of S2AC in the source and target domains. (c) Training and test accuracies of S2AC. As the number of iterations grows, we can observe that the S2AC’s training and test accuracy improve dramatically. (d) Comparison of difference distance matrices in this scenario. (e) The curves of the loss function under EMD. (f) The curves of the loss function under Chebyshev distance. (g) The curve of the loss function under cosine distance.
Figure 7. Detailed analysis of shift D W for training S2AC. (a) The curves of the loss function (our method). (b) Testing the average loss of S2AC in the source and target domains. (c) Training and test accuracies of S2AC. As the number of iterations grows, we can observe that the S2AC’s training and test accuracy improve dramatically. (d) Comparison of difference distance matrices in this scenario. (e) The curves of the loss function under EMD. (f) The curves of the loss function under Chebyshev distance. (g) The curve of the loss function under cosine distance.
Electronics 12 04419 g007
Figure 8. Prediction accuracy curves of S2AC substituting the attention-based backbone network with AlexNet for ablation study based on Office31 dataset ( D W ). Due to the considerable volatility, the data have been smoothed by w i n d o w = 3 .
Figure 8. Prediction accuracy curves of S2AC substituting the attention-based backbone network with AlexNet for ablation study based on Office31 dataset ( D W ). Due to the considerable volatility, the data have been smoothed by w i n d o w = 3 .
Electronics 12 04419 g008
Figure 9. Prediction accuracy curves of positional embedding for S2AC ablation study based on Office31 dataset ( D W ). Due of the considerable volatility, the data have been smoothed by w i n d o w = 3 .
Figure 9. Prediction accuracy curves of positional embedding for S2AC ablation study based on Office31 dataset ( D W ). Due of the considerable volatility, the data have been smoothed by w i n d o w = 3 .
Electronics 12 04419 g009
Figure 10. Prediction accuracy curves of the self-supervised learning module for S2AC ablation study based on Office31 dataset ( D W ). Due to the considerable volatility, the data have been smoothed by w i n d o w = 3 .
Figure 10. Prediction accuracy curves of the self-supervised learning module for S2AC ablation study based on Office31 dataset ( D W ). Due to the considerable volatility, the data have been smoothed by w i n d o w = 3 .
Electronics 12 04419 g010
Figure 11. Comparison of the source and target domain feature maps (sum of 256 channels) extracted by S2AC (left) and AlexNet (right) based on Office31. Yellow represents high values, whereas dark blue represents low levels.
Figure 11. Comparison of the source and target domain feature maps (sum of 256 channels) extracted by S2AC (left) and AlexNet (right) based on Office31. Yellow represents high values, whereas dark blue represents low levels.
Electronics 12 04419 g011
Figure 12. (a) P-R curves and (b) the F1 scores of the models trained with various dataset sizes.
Figure 12. (a) P-R curves and (b) the F1 scores of the models trained with various dataset sizes.
Electronics 12 04419 g012
Table 1. The running time and test accuracy analysis on three criteria: mean Hamming distance, max Hamming distance, and random sampling, to generate the permutation set. # means “the number of”. Σ is “the sum of”. M e a n stands of the mean Hamming distance. M a x indicates the max Hamming distance. R a n d o m is the random sampling.
Table 1. The running time and test accuracy analysis on three criteria: mean Hamming distance, max Hamming distance, and random sampling, to generate the permutation set. # means “the number of”. Σ is “the sum of”. M e a n stands of the mean Hamming distance. M a x indicates the max Hamming distance. R a n d o m is the random sampling.
# PermutationsMean Hamming Distance Max Hamming Distance Random Sampling
Σ  MeanRunning Time (s)Test Accuracy (%)  Σ  MaxRunning Time (s)Test Accuracy (%) Running Time (s)Test Accuracy (%)
65.3330.41145.6 6.0000.36645.4 0.05645.5
76.2220.58345.4 7.0000.48245.6 0.07145.6
1513.3331.74045.8 14.4001.44945.7 0.16545.6
2522.2223.79446.1 23.5253.34946.1 0.19545.8
3532.1116.89547.4 32.5716.03446.6 0.28246.5
5548.88915.41248.9 50.52714.28947.2 0.40947.6
7364.88926.86349.32 66.65124.13748.8 0.59748.6
8575.55635.06949.9 77.38132.53649.4 0.68848.9
10088.88947.60250.1 90.79142.93949.5 0.71849.4
Table 2. Ablation study of the attention-based backbone network ( D W ).
Table 2. Ablation study of the attention-based backbone network ( D W ).
MethodsAttention-Based Backbone NetworkAlexNetPretrainedAccuracy(%)
S2AC 66.5 ± 0.6
S2AC-AlexNet 63.6 ± 0.7
S2AC-AlexNet pretrained 61.3 ± 0.5
Table 3. Ablation study of positional embeddings. "✓" denotes the execution of self-supervised learning in the corresponding domain. ( D W ).
Table 3. Ablation study of positional embeddings. "✓" denotes the execution of self-supervised learning in the corresponding domain. ( D W ).
MethodsSource DomainTarget DomainAccuracy(%)F1(%)
S2AC-S&T43.2 ± 0.765.00
S2AC-∼S&∼T 45.5 ± 0.973.33
S2AC-S&∼T 53.4 ± 1.684.23
S2AC-∼S&T 61.6 ± 1.785.74
Table 4. Ablation study of the self-supervised learning module. ( D W ).
Table 4. Ablation study of the self-supervised learning module. ( D W ).
MethodsF1(%)
S2AC-S& !T68.57
S2AC-S&T83.21
S2AC-!S&T78.67
S2AC-!S& !T54.33
Table 5. The test performance with different size of datasets on Office31 ( D W ).
Table 5. The test performance with different size of datasets on Office31 ( D W ).
Dataset SizeRecall (%)Precision (%)F1 (%)AP (%)
10044.3146.1343.5640.64
20051.8552.6551.5349.89
30062.4265.5363.0464.61
40075.3876.9376.6577.92
50081.7480.1981.9183.72
Table 9. The average training time of each approach on the Office31 dataset with epoch = 1, batch_size = 128 (Seconds).
Table 9. The average training time of each approach on the Office31 dataset with epoch = 1, batch_size = 128 (Seconds).
MethodDDC [5]Deep CORAL [31]DANN [32]CDAN [6]CDAN + E [6]P-ADC [15]S2AC
Computational Time34.811.917.618.0118.0612.312.7
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Wang, Z.-Y.; Kang, D.-K.; Zhang, C.-P. S2AC: Self-Supervised Attention Correlation Alignment Based on Mahalanobis Distance for Image Recognition. Electronics 2023, 12, 4419. https://doi.org/10.3390/electronics12214419

AMA Style

Wang Z-Y, Kang D-K, Zhang C-P. S2AC: Self-Supervised Attention Correlation Alignment Based on Mahalanobis Distance for Image Recognition. Electronics. 2023; 12(21):4419. https://doi.org/10.3390/electronics12214419

Chicago/Turabian Style

Wang, Zhi-Yong, Dae-Ki Kang, and Cui-Ping Zhang. 2023. "S2AC: Self-Supervised Attention Correlation Alignment Based on Mahalanobis Distance for Image Recognition" Electronics 12, no. 21: 4419. https://doi.org/10.3390/electronics12214419

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop