# Unsupervised Domain Adaptive Person Re-Identification via Intermediate Domains
## 3 Proposed Method
### Intermediate Domains  
#### 3.1.1 SPGAN Model  
The proposed method is based on SPGAN [9], which consists of Siamese network (SiaNet) and CycleGAN [25]. SPGAN can not only transfer the style of the image from source domain to target domain but also preserve its underlying identity information.  
CycleGAN includes two generators and discriminators between source domain \(\mathcal{S}\) and target domain \(\mathcal{T}\). \(\{G,D_{\mathcal{T}}\}\) transfer the images in \(\mathcal{S}\) into the style of \(\mathcal{T}\), whereas \(\{F,D_{\mathcal{S}}\}\) act in the inverse direction. The following cycle consistency loss is proposed to preserve the semantic content of an image after translating it to another style:  
\[\begin{split}\mathcal{L}_{\text{rec}}\left(G,F\right)=& \mathbb{E}_{x\sim p_{\text{data}(\mathcal{S})}}\|F(G(x))-x\|_{1}\\ &+\mathbb{E}_{y\sim p_{\text{data}(\mathcal{T})}}\|G(F(y))-y\|_{1 }\end{split} \tag{1}\]  
where \(p_{\text{data}(\mathcal{S})}\) and \(p_{\text{data}(\mathcal{T})}\) denote the sample distributions in the source and target domain, respectively.  
The loss function of cycleGAN can be written as:  
\[\begin{split}\mathcal{L}_{cyc}(G,F,D_{\mathcal{T}},D_{\mathcal{ S}})=&\mathcal{L}_{adv}(G,D_{\mathcal{T}})+\mathcal{L}_{adv}(F,D_{ \mathcal{S}})\\ &+a\mathcal{L}_{rec}(G,F)\end{split} \tag{2}\]  
\(\mathcal{L}_{adv}(G,D_{\mathcal{T}})\) and \(\mathcal{L}_{adv}(F,D_{\mathcal{S}})\) represent the adversarial loss for GAN model:  
\[\begin{split}\mathcal{L}_{adv}(G,D_{\mathcal{T}})=& \mathbb{E}_{y\sim p_{\text{data}(\mathcal{T})}}\left[\log D_{ \mathcal{T}}(y)\right]\\ &+\mathbb{E}_{x\sim p_{\text{data}(\mathcal{S})}}\left[\log(1-D_ {\mathcal{T}}(G(x))\right]\end{split} \tag{3}\]  
Based on cycleGAN, SPGAN introduced the inside-domain identity constraint [26] as an auxiliary for image translation. For each image \(x\) from domain \(\mathcal{S}\), the generator \(F\) should translated it into source domain.  
\[\begin{split}\mathcal{L}_{ide}(G,F)=&\mathbb{E}_{x \sim p_{\text{data}(\mathcal{T})}}\left\|F(x)-x\right\|_{1}\\ &+\mathbb{E}_{y\sim p_{\text{data}(\mathcal{T})}}\left\|G(y)-y \right\|_{1}\end{split} \tag{4}\]  
The SiaNet \(M_{e}\) was introduced to preserve the information of a pedestrian, and was trained by similarity-preserving loss [27] as follows:  
\[\begin{split}\mathcal{L}_{\text{con}}(i,x_{1},x_{2})=(1-i)\{ \max(0,m-d)\}^{2}+id^{2}\end{split} \tag{5}\]  
where \(x_{1}\) and \(x_{2}\) are two input vectors and \(d\) denotes the Euclidean distance between the normalized embeddings of the two inputs. \(i=1\) if \(x_{1}\) and \(x_{2}\) belong to the same pedestrian but different domains, whereas \(i=0\) if \(x_{1}\) and \(x_{2}\) belong to different pedestrians.  
The overall loss function of SPGAN is as follows:  
\[\begin{split}\mathcal{L}_{\text{sp}}(G,F,D_{\mathcal{T}},D_{ \mathcal{S}},M)=\mathcal{L}_{cyc}(G,F,D_{\mathcal{T}},D_{\mathcal{S}})\\ &\quad+\beta\mathcal{L}_{ide}(G,F)+\gamma\mathcal{L}_{\text{con} }(G,F,M_{e})\end{split} \tag{6}\]  
where the parameter \(\beta\) and \(\gamma\) control the importance of identity constraint and similarity-preserving loss. We would like to refer the readers to the SPGAN [9] for more details about these loss functions.