# CLEANIR: Controllable Attribute-Preserving Natural Identity Remover
## 3 Proposed Method
### Training Process  
An overview of the training process is shown in Figure 1(a). The encoder network \(E\) maps a facial image \(\mathcal{I}\) to \(z\) which consists of identity-related vector \(z^{i}\) and attribute-related vector \(z^{a}\). Then, the decoder network \(D\) generates a reconstruction image \(\mathcal{I}^{r}\) from \(z\). As is common in encoder-decoder architectures based on VAE, we also use binary cross entropy (BCE) loss to measure reconstruction error as well as Kullback-Leibler (KL) loss for regularization. Since in an image, pixel intensity values follow a conditional probability distribution, we assume that the values can be interpreted as probabilities for pixels being on/off after the values are scaled to [0, 1]. Therefore, the BCE loss can be adopted to our formulation. The BCE loss function results in the minimum loss when the value of a pixel on the input image \(\mathcal{I}_{j}(x,y)\) and the value of the corresponding pixel on the reconstructed image \(\mathcal{I}_{j}^{r}(x,y)\) are the same. We define the BCE loss \(\mathcal{L}_{r}\) and the KL loss \(\mathcal{L}_{kl}\) as follows,  
\[\mathcal{L}_{r}=\sum_{j=1}^{N}\left(-\sum_{x=1}^{W}\sum_{y=1}^{H}\mathcal{I}_{ j}(x,y)log(\mathcal{I}_{j}^{r}(x,y))\right) \tag{1}\]  
where \(N\) is the number of samples, \(W\) and \(H\) are width and height of the image, respectively.  
\begin{table}
\begin{tabular}{c c c c} \hline \hline  
Figure 3: Architectures of blocks of the encoder and the decoder.  
\[\mathcal{L}_{kl}=\sum_{j=1}^{N}KL(q(z|\mathcal{I}_{j})\|\mathcal{N}(0,I)) \tag{2}\]  
where \(q\) is the encoder network.  
Our key idea in this work is to design the latent feature vector resulting from the encoder to have disentangled into identity-related part and the rest facial attribute-related part, enabling effective identity modification by solely manipulating the identity-related part from the latent vector. To train the network to result such disentanglement, we present an embedding loss using an external facial embedding extractor \(F\). Since, we employ the \(F\) which is pre-trained for face recognition and verification, we assume that it is well trained to provide plenty distinctive features for facial identity. Therefore, by transforming a point on the identity space defined by \(F\), we expect that identities of given facial images can be transformed with ease by producing new facial images. In this work, we use a Keras implementation [50] of FaceNet [51] as the face embedding extractor \(F\). The network architecture is based on the Inception-Resnet-v1 [52] and the model was trained on VGGFace2 dataset [53] using a triplet loss.  
To make \(z^{i}\) resulted from the proposed network get closer to the output of \(F\), \(z^{f}\), we design the embedding loss function using cosine distance as follows:  
\[\mathcal{L}_{e}=\sum_{j=1}^{N}\left(1-\frac{z_{j}^{f}\cdot z_{j}^{i}}{\|z_{j}^ {f}\|_{2}\|z_{j}^{i}\|_{2}}\right). \tag{3}\]  
For a sample \(j\), the cosine distance between \(z_{j}^{f}\) and \(z_{j}^{i}\) ranges in [0, 2], and the loss is the sum of the distances of \(N\) samples in a batch.  
Finally, our training loss is defined as the sum of the loss functions with control parameters \(\lambda_{r}\), \(\lambda_{kl}\) and \(\lambda_{e}\):  
\[\mathcal{L}=\lambda_{r}\mathcal{L}_{r}+\lambda_{kl}\mathcal{L}_{kl}+\lambda_ {e}\mathcal{L}_{e}, \tag{4}\]  
where by the embedding loss \(\mathcal{L}_{e}\), the latent space related to facial identities is trained while non-identity latent space is also be learned due to the reconstruction loss \(\mathcal{L}_{r}\) because it demands the rest information to reconstruct the input image properly.