DNA-GAN: L EARNING D ISENTANGLED R EPRESENTATIONS FROM M ULTI -A TTRIBUTE I MAGES
Anonymous authors
Paper under double-blind review
A BSTRACT
Disentangling factors of variation has always been a challenging problem in representation learning.
Existing algorithms suffer from many limitations, such as unpredictable disentangling factors, bad quality of generated images from encodings, lack of identity information, etc.
In this paper, we proposed a supervised algorithm called DNA-GAN trying to disentangle different attributes of images.
The latent representations of images are DNA-like, in which each individual piece represents an independent factor of variation.
By annihilating the recessive piece and swapping a certain piece of two latent representations, we obtain another two different representations which could be decoded into images.
In order to obtain realistic images and also disentangled representations, we introduced the discriminator for adversarial training.
Experiments on Multi-PIE and CelebA datasets demonstrate the effectiveness of our method and the advantage of overcoming limitations existing in other methods.
I NTRODUCTION
The success of machine learning algorithms depends on data representation, because different representations can entangle different explanatory factors of variation behind the data.
Although prior knowledge can help us design representations, the vast demand of AI algorithms in various domains cannot be met, since feature engineering is labor-intensive and needs domain expert knowledge.
Therefore, algorithms that can automatically learn good representations of data will deﬁnitely make it easier for people to extract useful information when building classiﬁers or predictors.
Of all criteria of learning good representations as discussed in Bengio et al.
(2013), disentangling factors of variation is an important one that helps separate various explanatory factors.
For example, given a human-face image, we can obtain various information about the person, including gender, hair style, facial expression, with/without eyeglasses and so on.
All of these information are entangled in a single image, which renders the difﬁculty of training a single classiﬁer to handle different facial attributes.
If we could obtain a disentangled representation of the face image, we may build up only one classiﬁer for multiple attributes.
In this paper, we proposed a supervised method called DNA-GAN to obtain disentangled representations.
DNA-GAN is a bio-inspired algorithm, which is based on the assumption that the certain visual attribute in an image is controlled by a certain piece of encodings in its latent representations.
An encoder is used to encode an image to the attribute-relevant part and the attribute-irrelevant part, where different pieces in attribute-relevant part encode information of different attributes, and attribute-irrelevant part encodes the other information.
For example, given a facial image, we are trying to obtain a latent representation that each individual part controls different attributes, such as hairstyles, genders, expressions and so on.
Though annihilating recessive pieces and swapping attributes, we can obtain novel crossbreeds that can be decoded into new images.
By the adversarial discriminator loss and the reconstruction loss, DNA-GAN can reconstruct the input images and generate new images with new attributes.
Each attribute is disentangled from others gradually though iterative training,.
Finally, we are able to obtain disentangled representations in the latent representations.
The summary of contributions of our work is as follows:
Proposed DNA-GAN, which is able to disentangle multiple attributes as demonstrated by the experiments of interpolating multiple attributes on Multi-PIE (Gross et al., 2010) and CelebA (Liu et al., 2015) datasets.
Introduced the annihilating operation that prevents from trivial solutions: the attributerelevant part encodes information of the whole images instead of the attribute.
Employed iterative training to address the problem of unbalanced multi-attribute image data, which was theoretically proved to be more efﬁcient than random image pairs.
R ELATED W ORK
Traditional representation learning algorithms focused on (1) probabilistic graphical models, characterized by Restricted Boltzmann Machine (RBM) (Smolensky, 1986), Autoencoder (AE) and their variants; (2) manifold learning and geometrical approaches, such as Principal Components Analysis (PCA) (Pearson, 1901),
Locally Linear
Embedding (LLE) (Roweis & Saul, 2000), Local Coordinate
Coding (LCC) (Yu et al., 2009), etc.
However, recent research has actively focused on developing deep probabilistic models that learn to represent the distribution of data.
Kingma & Welling (2013) employed an explicit model distribution and used variational inference to learn its parameters.
As
Goodfellow et al.
(2014) invented the generative adversarial networks (GAN), many implicit models were developed.
In the semi-supervised setting, Siddharth et al.
(2016) learnt a disentangled representations by using an auxiliary variable.
Bouchacourt et al.
(2017) proposed the ML-VAE that could learn disentangled representations from a set of grouped observations.
In the unsupervised setting, InfoGAN (Chen et al., 2016) tries to maximize mutual information between a small subset of latent variables and observations by introducing an auxiliary network to approximate the posterior.
However, it relies much on the a-priori choice of distributions and suffers from unstable training.
Another popular unsupervised method β -VAE (Higgins et al., 2016), adapted from VAE, lays great stress on the KL distance between the approximate posterior and the prior.
However, unsupervised approaches do not anchor a speciﬁc meaning into the disentanglement.
More closely with our method, supervised methods take the advantage of labeled data and try to disentangle the factors as expected.
DC-IGN (Kulkarni et al., 2015) asks the active attribute to explain certain factor of variation by feeding the other attributes by the average in a mini-batch.
TD-GAN (Wang et al., 2017) uses a tag mapping net to boost the quality of disentangled representations, which are consistent with the representations extracted from images through the disentangling network.
Besides, the quality of generated image are improved by implementing the adversarial training strategy.
However, the identity information should be labeled so as to preserve the id information when swapping attributes, which renders the limitation of applying it into many other datasets without id labels.
IcGAN (Perarnau et al., 2016) is a multi-stage training algorithm that ﬁrst takes the advantage of cGAN (Mirza & Osindero, 2014) to learn a map from latent representations and conditional information to real images, and then learn its inverse map from images to the latent representations and conditions in a supervised manner.
The overall effect depends on each training stage, which is hard to obtain satisfying images.
Unlike these models, our model requires neither explicit id information in labels nor multi-stage training.
Many works studied the image-to-image translation between unpaired image data using GAN-based architectures, see Isola et al.
(2016), Taigman et al.
(2016), Zhu et al.
(2017), Liu et al.
(2017) and
Zhou et al.
Interestingly, these models require a form of 0/1 weak supervision that is similar to our setting.
However, they are circumscribed in two image domains which are opposite to each other with respect to a single attribute.
Our model differs from theirs as we generalize to the case of multi-attribute image data.
Speciﬁcally, we employ the strategy of iterative training to overcome the difﬁculty of training on unbalanced multi-attribute image datasets.
DNA-GAN A PPROACH
In this section, we formally outline our method.
A set X of multi-labeled images and a set of labels Y are considered in our setting.
Let { ( X 1 , Y 1 ) , . . .
, ( X m , Y m ) } denote the whole training dataset, where X i ∈
X is the i -th image with its label Y i ∈ Y .
m denotes the number of samples in set X and n denotes the number of attributes respectively.
The label Y i
=
( y i 1 , . . .
, y in ) is a n -dimensional vector where each element represents whether X i has certain attribute or not.
For example, in the case of labels with three candidates [Bangs, Eyeglasses, Smiling], the facial image
X i whose label is Y i =
(1 , 0 , 1) should depict a smiling face with bangs and no eyeglasses.
3. M ODEL
As shown in Figure 1, DNA-GAN is mainly composed of three parts: an encoder ( Enc ), a decoder ( Dec ) and a discriminator ( D ).
The encoder maps the real-world images A and B into latent disentangled representations
[Equation]
where [ a 1 , . .
. , a i , . .
. , a n ] is called the attribute-relevant part, and z a is called the attribute-irrelevant part.
a i is supposed to be a DNA piece that controls y i , the i -th attribute in the label, and z a is for keeping other silent factors which do not appear in the attribute list as well as image identity information.
The same thing applies for Enc( B ) .
E n c od e r ...
D ec od e r
[Figure]
We focus on one attribute each time in our framework.
Let’s say we are at i -th attribute.
The labels of A and B are required to be different.
In our convention, A is always for the dominant pattern, while B is for the recessive pattern.
In another word, labels of A and B are ( y A 1 , . . .
, 1 Ai , . . .
, y An ) and ( y B 1 , . . .
Bi , . .
, y Bn ) , respectively.
We copy Enc( A ) directly as the latent representation of
A 1 , and copy Enc( B ) and annihilate b i as the latent representation of B 1 .
The annihilating operation means replacing all elements with zeros.
It plays a key role in disentangling the attribute, which we will discuss in detail in Section 3.3.
By swapping a i and 0 i , we obtain two new latent representations [ a 1 , . . .
, 0 i , . .
. , a n , z a ] and [ b 1 , . .
. , a i , . . .
, b n , z b ] that are supposed to be decoded into A 2 and B 2 .
Though a decoder Dec , we can get four newly generated images A 1 , B 1 , A 2 and B 2 .
[Equation]
Out of these four children, A 1 and B 1 are reconstructions of A and B , while A 2 and B 2 are novel crossbreeds.
The reconstruction losses between A and A 1 , B and B 1 ensure the quality of reconstructed samples.
Besides, using an adversarial discriminator D that helps make generated samples
A 2 indistinguishable from B , and B 2 indistinguishable from A , we can enforce attribute-related information to be encoded in a i .
3. L OSS F UNCTIONS
Given two images A and B and their labels Y A
=
( y A 1 , . .
, 1 Ai , . . .
, y An ) and Y B =
( y B 1 , . . .
Bi , . .
, y Bn ) which are different at the i -th position, the data ﬂow can be summarized by (1) and (2).
We force the i -th latent encoding of B to be zero in order to prevent from trivial solutions as we will discuss in Section 3.3.
The encoder and decoder receive two types of losses: (1) the reconstruction loss,
[Equation]
which measures the reconstruction quality after a sequence of encoding and decoding; (2) the standard GAN loss,
[Equation]
which measures how realistic the generated images are.
The discriminator takes the generated image and the i -th element of its label as inputs, and outputs a number which represents how realistic the input image is.
The larger the number is, the more realistic the image is.
Omitting the coefﬁcient, the loss function for the encoder and decoder is
[Equation]
The discriminator D receives the standard GAN discriminator loss
[Equation]
where L D 1 drives D to tell A from B 2 , and L D 0 drives D to tell B from A 2 .
3. A NNIHILATING O PERATION P REVENTS FROM T RIVIAL S OLUTIONS
Through experiments, we observe that there exist trivial solutions to our model without the annihilating operation.
We just take the single-attribute case as an example.
Suppose that Enc( A ) =
[ a, z a ] and Enc( B ) =
[ b, z b ] , we can get four children without annihilating operation
[Equation]
The reconstruction loss makes it invertible between the latent encoding space and image space.
The adversarial discriminator D is supposed to disentangle the attribute from other information by telling whether A 2 looks as real as B and B 2 looks as real as A or not.
As we know that the generative adversarial networks give the best solution when achieving Nash equilibrium.
But without the annihilating operation, the information of an whole image could be encoded into the attribute-relevant part, which means
[Equation]
Therefore, we obtain the following four children
[Equation]
In this situation, the discriminator D cannot discriminate A 2 from B , since they share the same latent encodings.
By reconstruction loss, A 2 and B are exactly the same image, which is against our expectation that A 2 should depict the person A with the attribute borrowed from B .
The same thing happens to B 2 and A as well.
To prevent from learning trivial solutions, we adopt the annihilating operation by replacing the recessive pattern b with a zero tensor of the same size 1 .
In this case, the four children obtained will be
[Equation]
[Equation]
The encodings of B 1 and A 2 contain no information at all, thus neither the person in B 1 nor A 2 who is supposed to be the same as in B can be reconstructed by Dec .
This forces the attribute-irrelevant part to encode some information of images.
3. I TERATIVE T RAINING
To reduce the difﬁculty of disentangling multiple attributes, we take the strategy of iterative training: we update our model using a pair of images with opposite labels at a certain position each time.
Suppose that we are at the i -th position, the label of image
A is ( y A 1 , . . .
, 1 Ai , . . .
, y An ) , while the label of image B is ( y B 1 , . . .
Bi , . .
, y Bn ) .
During each iteration, as i goes through from 1 to n repeatedly, our model fed with such a pair of images can disentangle multiple attributes one-by-one.
Compared with training with random pairs of images, iterative training is proved to be more effective.
Random pairs of images means randomly selecting pairs of images each time without label constraints.
A pair of images with different labels is called a useful pair .
We theoretically shows that our iterative training is much more efﬁcient than random image pairs especially when the dataset is unbalanced.
All proofs can be found in the Appendix.
Theorem 1.
Let X
= { ( X 1 , Y 1 ) , . . .
, ( X m , Y m ) } denotes the whole multi-attribute image dataset, where X i is a multi-attribute image and its label Y i
=
( y i 1 , . . .
, y in ) is an n -dimensional vector.
There are totally 2 n kinds of labels, denoted by L = { l 1 , . . .
, l 2 n } .
The number of images with label l i is m i , and (cid:80) 2 n i =
m i = m .
To select all useful pairs at least once, the expected numbers of iterations needed for randomly selecting pairs and for iterative training are denoted by E 1 and
E 2 respectively.
Then,
[Equation]
where I s represents the indices of labels where the s -th element is 1 , and J s represents the indices of labels where the s -th element is 0 .
Deﬁnition 1.
(Balancedness) Deﬁne the balancedness of a dataset X described above with respect to the s -th attribute as follows:
[Equation]
where I s represents the indices of labels where the s -th element is 1 , and J s represents the indices of labels where the s -th element is 0 .
Theorem 2.
We have E 2 ≤ E 1 , when
[Equation]
Speciﬁcally, E 2 ≤ E 1 holds true for all n ≤ 2 .
The property of the function ( ρ + 1) 2 / (2 ρ ) suits well with the deﬁnition of balancedness, because it attains the same value for ρ and 1 /ρ , which is invariant to different labeling methods.
Its value gets larger as the dataset becomes more unbalanced.
The minimum is obtained at ρ = 1 , which is the case of a balanced dataset.
Theorem 2 demonstrates that the iterative training mechanism is always more efﬁcient than random pairs of images when the number of attributes met the criterion (16).
As the dataset becomes more unbalanced, ( ρ s + 1) 2 / (2 ρ s ) goes larger, which means (16) can be more easily satisﬁed.
More importantly, iterative training helps stabilize the training process on unbalanced datasets.
For example, given a two-attribute dataset, the number of data of each kind is as follows:
Label (0 ,
[Equation]
Number
[Table]
data  m m
If m (cid:29) 1 is a very large number, then it is highly likely that we will select a pair of images whose labels are (1 , 0) and (1 , 1) each time by randomly selecting pairs.
We ignore the pair of images
[Figure]
whose labels are (1 , 0) and (1 , 0) or (1 , 1) and (1 , 1) , though these two cases have equal probabilities of being chosen.
Because they are not useful pairs, thus do not participated in training.
In this case, most of the time the model is trained with respect to the second attribute, which will cause the ﬁnal learnt model less effective to the ﬁrst attribute.
However, iterative training can prevent this from happening, since we update our model evenly with respect to two attributes.
E XPERIMENTS
In this section, we perform different kinds of experiments on two real-world datasets to validate the effectiveness of our methods.
We used RMSProp (Sutskever et al., 2013) optimization method initialized by a learning rate of 5e-5 and momentum 0 .
All neural networks are equipped with
Batch Normalization (Ioffe & Szegedy, 2015) after convolutions or deconvolutions.
We used Leaky
Relu (Maas et al., 2013) as the activation function in the encoder.
Besides, we adopt strategies mentioned in Wasserstein GAN (Arjovsky et al., 2017) for stable training.
More details will be available online.
We divide all images into training images and test images according to the ratio of 9:1.
All of the following results are from test images without cherry-picking.
4. M ULTI -PIE D ATABASE
The Multi-PIE (Gross et al., 2010) face database contains over 750,000 images of 337 subjects captured under 15 view points and 19 illumination conditions.
We collected all front faces images of different illuminations and aligned them based on 5-point landmarks on eyes, nose and mouth.
All aligned images are resized into 128 × 128 as inputs in our experiments.
We labeled the light illumination face images by 1 and the dark illumination face images by 0.
As shown in Figure 2, the illumination on one face was successfully transferred into the other face without modifying any other information in the images.
This demonstrates that DNA-GAN can effectively disentangle the illumination factor from other factors in the latent space.
4. C ELEB A D ATASET
CelebA (Liu et al., 2015) is a dataset composed of 202599 face images and 40 attribute binary vectors and 5 landmark locations.
We use the aligned and cropped version and scaled all images down to 64 × 64 .
To better demonstrate the advantage of our method, we choose TD-GAN (Wang et al., 2017) and IcGAN (Perarnau et al., 2016) for comparisons.
As we mentioned before, TD-GAN requires the explicit id information in the label, thus cannot be applied to the CelebA dataset directly.
To overcome this limitation, we use some channels to encode the id information in its latent representations.
In our experiments, the id information is preserved when swapping the attribute information in the latent encodings.
We also compared the experimental results of IcGAN with ours in the celebA dataset.
The following results are obtained using the the ofﬁcial code and pre-trained celebA model provided by the author 2 .
[Figure]
As displayed in Figure 3a, modiﬁed TD-GAN encounters the problem of trivial solutions.
Without id information explicitly contained in the label, TD-GAN encodes the information of the whole image into the attribute-related part in the latent representations.
As a result, two faces are swapped directly.
Whereas in Figure 3b, the quality of images generated by IcGAN are very bad.
This is probably due to the multi-stage training process of IcGAN.
Since the overall effect of the model relies much on the each stage.
DNA-GAN is able to disentangle multiple attributes in the latent representations as shown in Figure 4.
Since different attributes are encoded in different DNA pieces in our latent representations, we are able to interpolate the attribute subspaces by linear combination of disentangled encodings.
Figure 4a, 4b and 4c present disentangled attribute subspaces spanned by any two attributes of Bangs,
Eyeglasses and Smiling.
They demonstrate that our model is effective in learning disentangled representations.
Figure 4d shows the hairstyle transfer process among different Bangs styles.
It is worth mentioning that the top-left image in Figure (4d) is outside the training data, which further validate the generalization potential of our model on unseen data.
Please refer to Figure 5 in the Appendix for more results.
[Figure]
C ONCLUSION
In this paper, we proposed DNA-GAN, a supervised algorithm that can learn disentangled representations from multi-attribute images.
The latent representations of images are DNA-like, consisting of attribute-relevant and attribute-irrelevant parts.
By the annihilating operation and attribute hybridization, we are able to create new latent representations which could be decoded into novel images with designed attributes.
The iterative training strategy effectively overcomes the difﬁculty of training on unbalanced datasets and helps disentangle multiple attributes in the latent space.
The experimental results not only demonstrate that DNA-GAN is effective in learning disentangled representations and image editing, but also point out its potential in interpretable deep learning, image understanding and transfer learning.
There also exist some limitations of our model.
Without strong guidance on the attribute-irrelevant parts, some background information is encoded into the attribute-relevant part.
As we can see in
Figure 4, the background color gets changed when swapping attributes.
Besides, our model may fail when several attributes are highly correlated with each other.
For example, Male and Mustache are statistically dependent, which are hard to disentangle in the latent representations.
These are left as our future work.
A PPENDIX
To prove the Theorem 1, we need the following lemma.
Lemma 1.
Suppose the set S
= { s 1 , . . .
, s m } has m different elements, from which elements are being selected equally likely with replacement.
The expected number of trials needed to collect a subset R = { s 1 , . . .
, s n } of n (1 ≤ n ≤ m ) elements is
[Equation]
Proof.
Let T be the time to collect all n elements in the subset R , and let t i be the time to collect the i -th new elements after i − 1 elements in R have been collected.
Observe that the probability of collecting a new elements is p i = ( n − ( i − 1)) /m .
Therefore, the random variable t i has geometric distributions with expectation 1 /p
i .
By the linearity of expectations, we have:
[Equation]
Proof.
(of Theorem 1)
We ﬁrst consider the case of randomly selecting pairs.
All possible image pairs are actually in the product space
X × X , whose cardinality is m 2 .
If we take the order of two images in a pair into consideration, the number of possible pairs is m 2 .
Recall that the useful pair denotes a pair of image of different labels.
Therefore, the number of all useful pairs is (cid:80) i (cid:54) =
j m i m j .
By Lemma 1, the expected number of iterations for randomly selecting pairs to select all useful pairs at least once is
[Equation]
Now we consider the case of iterative training.
We always select a pair of images of different labels each time.
Suppose we are selecting images with opposite labels at the s -th position.
Let I s denote the indices of all labels with the s -th element 1 , and J s denote the indices of all labels with the s -th element 0 , where | I s | = | J s | = 2 n − 1 .
Then we consider the subproblem by neglecting the ﬁrst position in data labels, the number of all possible pairs is 2 (cid:80)
i ∈
I s ,
j ∈ J s m i m j (regarding of order), and the number of useful pairs is
[Equation]
Therefore, the expectation to select all useful pairs at least one regardless of the s -th element in the label is
[Equation]
Since we rotate the subscript s from 1 to n
[Equation]
the expected number of iterations for iterative training to select all useful pairs at least once is
[Equation]
Proof.
(of Theorem 2)
We ﬁrstly show that
[Equation] [Equation]
According to the result of Theorem 1 and the Deﬁnition 1 of balancedness
[Equation]
we have
[Equation] [Equation]
Speciﬁcally, if n ≤ 2 ,
[Equation]
The inequality holds true forever.
[Figure] [Figure]