discoGAN.tensorflow.slim
None
view repo
While humans easily recognize relations between data from different domains without any supervision, learning to automatically discover them is in general very challenging and needs many ground-truth pairs that illustrate the relations. To avoid costly pairing, we address the task of discovering cross-domain relations given unpaired data. We propose a method based on generative adversarial networks that learns to discover relations between different domains (DiscoGAN). Using the discovered relations, our proposed network successfully transfers style from one domain to another while preserving key attributes such as orientation and face identity. Source code for official implementation is publicly available https://github.com/SKTBrain/DiscoGAN
READ FULL TEXT VIEW PDFNone
Interserstic Papers in Machine Learning and Computer Vision
Convert sketches to faces with Generative Adversarial Networks
Relations between two different domains, the way in which concepts, objects, or people are connected, arise ubiquitously. Cross-domain relations are often natural to humans. For example, we recognize the relationship between an English sentence and its translated sentence in French. We also choose a suit jacket with pants or shoes in the same style to wear.
Can machines also achieve a similar ability to relate two different image domains? This question can be reformulated as a conditional image generation problem. In other words, finding a mapping function from one domain to the other can be thought as generating an image in one domain given another image in the other domain. While this problem tackled by generative adversarial networks (GAN) (Isola et al., 2016) has gained a huge attention recently, most of today’s training approaches use explicitly paired data, provided by human or another algorithm.
(a) Learning cross-domain relations without any extra label |
(b) Handbag images (input) & Generated shoe images (output) |
(c) Shoe images (input) & Generated handbag images (output) |
This problem also brings an interesting challenge from a learning point of view. Explicitly supervised data is seldom available and labeling can be labor intensive. Moreover, pairing images can become tricky if corresponding images are missing in one domain or there are multiple best candidates. Hence, we push one step further by discovering relations between two visual domains without any explicitly paired data.
In order to tackle this challenge, we introduce a model that discovers cross-domain relations with GANs (DiscoGAN). Unlike previous methods, our model can be trained with two sets of images without any explicit pair labels (see Figure 1a) and does not require any pre-training. Our proposed model can then take one image in one domain as an input and generate its corresponding image in another domain (see Figure 1b). The core of our model is based on two different GANs coupled together – each of them ensures our generative functions can map each domain to its counterpart domain. A key intuition we rely on is to constraint all images in one domain to be representable by images in the other domain. For example, when learning to generate a shoe image based on each handbag image, we force this generated image to be an image-based representation of the handbag image (and hence reconstruct the handbag image) through a reconstruction loss, and to be as close to images in the shoe domain as possible through a GAN loss. We use these two properties to encourage the mapping between two domains to be well covered on both directions (i.e. encouraging one-to-one rather than many-to-one or one-to-many). In the experimental section, we show that this simple intuition discovered common properties and styles of two domains very well.
Both experiments on toy domain and real world image datasets support the claim that our proposed model is well-suited for discovering cross-domain relations. When translating data points between simple 2-dimensional domains and between face image domains, our DiscoGAN model was more robust to the mode collapse problem compared to two other baseline models. It also learns the bidirectional mapping between two image domains, such as faces, cars, chairs, edges and photos, and successfully apply them in image translation. Translated images consistently change specified attributes such as hair color, gender and orientation while maintaining all other components. Results also show that our model is robust to repeated application of translation mappings.
We now formally define cross-domain relations and present the problem of learning to discover such relations in two different domains. Standard GAN model and a similar variant model with additional components are investigated for their applicability for this task. Limitations of these models are then explained, and we propose a new architecture based on GANs that can be used to discover cross-domain relations.
Relation is mathematically defined as a function that maps elements from its domain to elements in its codomain and is similarly defined. In fully unsupervised setting, and can be arbitrarily defined. To find a meaningful relation, we need to impose a condition on the relation of interest. Here, we constrain relation to be a one-to-one correspondence (bijective mapping). That means is the inverse mapping of .
The range of function , the complete set of all possible resulting values for all ’s in domain , should be contained in domain and similarly for .
We now relate these constraints to objective functions. Ideally, the equality should be satisfied, but this hard constraint is difficult to optimize and relaxed soft constraint is more desirable in the view of optimization. For this reason, we minimize the distance , where any form of metric function (, , Huber loss) can be used. Similarly, we also need to minimize .
Guaranteeing that maps to domain is also very difficult to optimize. We relax this constraint as follows: we instead minimize generative adversarial loss . Similarly, we minimize .
Now, we explore several GAN architectures to learn with these loss functions.
We use the following notations in sections below. A generator network is denoted , and the subscripts denote the input and output domains and superscripts denote the input and output image size. The discriminator network is denoted as , and the subscript B denotes that it discriminates images in domain B. Notations and are used similarly.
Each generator takes image of size and feeds it through an encoder-decoder pair. The encoder part of each generator is composed of convolution layers with
filters, each followed by leaky ReLU
(Maas et al., 2013; Xu et al., 2015). The decoder part is composed of deconvolution layers with filters, followed by a ReLU, and outputs a target domain image of size . The number of convolution and deconvolution layers ranges from four to five, depending on the domain.The discriminator is similar to the encoder part of the generator. In addition to the convolution layers and leaky ReLUs, the discriminator has an additional convolution layer with filters, and a final sigmoid to output a scalar output between .
We first consider a standard GAN model (Goodfellow et al., 2014) for the relation discovery task (Figure 2a). Originally, a standard GAN takes random Gaussian noise , encodes it into hidden features and generates images such as MNIST digits. We make a slight modification to this model to fit our task: the model we use takes in image as input instead of noise.
In addition, since this architecture only learns one mapping from domain A to domain B, we add a second generator that maps domain B back into domain A (Figure 2b). We also add a reconstruction loss term that compares the input image with the reconstructed image. With these additional changes, each generator in the model can learn mapping from its input domain to output domain and discover relations between them.
A generator translates input image from domain A into in domain B. The generated image is then translated into a domain A image to match the original input image (Equation 1, 2). Various forms of distance functions, such as MSE, cosine distance, and hinge-loss, can be used as the reconstruction loss (Equation 3). The translated output is then scored by the discriminator which compares it to a real domain B sample .
(1) | ||||
(2) | ||||
(3) | ||||
(4) |
The generator receives two types of losses – a reconstruction loss (Equation 3) that measures how well the original input is reconstructed after a sequence of two generations, and a standard GAN generator loss (Equation 4) that measures how realistic the generated image is in domain B. The discriminator receives the standard GAN discriminator loss of Equation 6.
(5) |
(6) | |||||
During training, the generator learns the mapping from domain A to domain B under two relaxed constraints: that domain A maps to domain B, and that the mapping on domain B is reconstructed to domain A. However, this model lacks a constraint on mapping from B to A, and these two conditions alone does not guarantee a cross-domain relation (as defined in section 2.1) because the mapping satisfying these constraints is one-directional. In other words, the mapping is an injection, not bijection, and one-to-one correspondence is not guaranteed.
Consider the two possibly multi-modal image domains A and B. Figure 3 illustrates the two multi-modal data domains on a simplified one-dimensional representation. Figure 3a shows the ideal mapping from input domain A to domain B, where each mode of data is mapped to a separate mode in the target domain. Figure 3b, in contrast, shows the mode collapse problem, a prevalent phenomenon in GANs, where data from multiple modes of a domain map to a single mode of a different domain. For instance, this case is where the mapping maps images of cars in two different orientations into the same mode of face images.
In some sense, the addition of a reconstruction loss to a standard GAN is an attempt to remedy the mode collapse problem. In Figure 3c, two domain A modes are matched with the same domain B mode, but the domain B mode can only direct to one of the two domain A modes. Although the additional reconstruction loss forces the reconstructed sample to match the original (Figure 3c), this change only leads to a similar symmetric problem. The reconstruction loss leads to an oscillation between the two states and does not resolve mode-collapsing.
Our proposed GAN model for relation discovery – DiscoGAN – couples the previously proposed model (Figure 2c). Each of the two coupled models learns the mapping from one domain to another, and also the reverse mapping to for reconstruction. The two models are trained together simultaneously. The two generators ’s and the two generators ’s share parameters, and the generated images and are each fed into separate discriminators and , respectively.
One key difference from the previous model is that input images from both domains are reconstructed and that there are two reconstruction losses: and .
(7) | ||||
(8) |
As a result of coupling two models, the total generator loss is the sum of GAN loss and reconstruction loss for each partial model (Equation 7). Similarly, the total discriminator loss is a sum of discriminator loss for the two discriminators and , which discriminate real and fake images of domain A and domain B (Equation 8).
Now, this model is constrained by two losses and two losses. Therefore a bijective mapping is achieved, and a one-to-one correspondence, which we defined as cross-domain relation, can be discovered.
(a) | (b) | (c) | (d) |
To empirically demonstrate our explanations on the differences between a standard GAN, a GAN with reconstruction loss and our proposed model (DiscoGAN), we designed an illustrative experiment based on synthetic data in 2-dimensional A and B domains. Both source and target data samples are drawn from Gaussian mixture models.
In Figure 4, the left-most figure shows the initial state of toy experiment where all the A domain modes map to almost a single point because of initialization of the generator. For all other plots the target domain 2D plane is shown with target domain modes marked with black ‘x’s. Colored points on B domain planes represent samples from A domain that are mapped to the B domain, and each color denotes samples from each A domain mode. In this case, the task is to discover cross-domain relations between the A and B domain and translate samples from five A domain modes into the B domain, which has ten modes spread around the arc of a circle.
We use a neural network with three linear layers that are each followed by a ReLU nonlinearity as the generator. For the discriminator we use five linear layers that are each followed by a ReLU, except for the last layer which is switched out with a sigmoid that outputs a scalar
. The colored background shows the output value of the discriminator , which discriminates real target domain samples from synthetic, translated samples from domain A. The contour lines show regions of same discriminator value.The training was performed for 50,000 iterations, and due to the domain simplicity our model often converged much earlier. The results from this experiment match our claim and illustrations in Figure 4 and the resulting translated samples show very different behavior depending on the model used.
In the baseline (standard GAN) case, many translated points of different colors are located around the same B domain mode. For example, navy and light-blue colored points are located together, as well as green and orange colored points. This result illustrates the mode-collapse problem of GANs since points of multiple colors (multiple A domain modes) are mapped to the same B domain mode. The baseline model still oscillate around B modes throughout the iterations.
In the case of GAN with a reconstruction loss, the collapsing problem is less prevalent, but navy, green and light-blue points still overlap at a few modes. The contour plot also demonstrates the difference from baseline: regions around all B modes are leveled in a green colored plateau in the baseline, allowing translated samples to freely move between modes, whereas in the single model case the regions between B modes are clearly separated.
In addition, both this model and the standard GAN model fail to cover all modes in B domain since the mapping from A domain to B domain is injective. Our proposed DiscoGAN model, on the other hand, is able to not only prevent mode-collapse by translating into distinct well-bounded regions that do not overlap, but also generate B samples in all ten modes as the mappings in our model is bijective. It is noticeable that the discriminator for B domain is perfectly fooled by translated samples from A domain around B domain modes.
Although this experiment is limited due to its simplicity, the results clearly support the superiority of our proposed model over other variants of GANs.
To evaluate whether our DiscoGAN successfully learns underlying relationship between domains, we trained and tested our model using several image-to-image translation tasks that require the use of discovered cross-domain relations between source and target domains.
In each real domain experiment, all input images and translated images were of size . For training, we used learning rate of 0.0002 and used the Adam optimizer (Kingma & Ba, 2015) with and
. We applied Batch Normalization
(Ioffe & Szegedy, 2015) to all convolution and deconvolution layers except the first and the last layers, weight decay regularization coefficient of and minibatch of size 200. All computations were conducted on a single machine with an Nvidia Titan X Pascal GPU and an Intel(R) Xeon(R) E5-1620 CPU.We used a Car dataset (Fidler et al., 2012) which consists of rendered images of 3D car models with varying azimuth angles at 15 intervals. We split the dataset into train and test sets and again split the train set into two groups, each of which is used as A domain and B domain samples. In addition to training a standard GAN model, a GAN with a reconstruction model and a proposed DiscoGAN model, we also trained a regressor that predicts the azimuth angle of a car image using the train set. To evaluate, we translated images in the test set using each of the three trained models, and azimuth angles were predicted using the regressor for both input and translated images. Figure 5 shows the predicted azimuth angles of input and translated images for each model. In standard GAN and GAN with reconstruction (5a and 5b), most of the red dots are grouped in a few clusters, indicating that most of the input images are translated into images with same azimuth, and that these models suffer from mode collapsing problem as predicted and shown in Figures 3 and 4. Our proposed DiscoGAN (5c), on the other hand, shows strong correlation between predicted angles of input and translated images, indicating that our model successfully discovers azimuth relation between the two domains. In this experiment, the translated images either have the same azimuth range (5b), or the opposite (5a and 5c) of the input images.
Next, we use a Face dataset (Paysan et al., 2009) shown in Figure 6a, in which the data images vary in azimuth rotation from -90 to +90. Similar to previous car to car experiment, input images in the -90 to +90 rotation range generated output images either in the same range, from -90 to +90, or the opposite range, from +90 to -90 when our proposed model was used (6d). We also trained a standard GAN and a GAN with reconstruction loss for comparison. When a standard GAN and GAN with reconstruction loss were used, the generated images do not vary as much as the input images in terms of rotation. In this sense, similar to what has been shown in previous Car to Car experiment, the two models suffered from mode collapse.
In terms of the amount of related information between two domains, we can consider a few extreme cases: two domains sharing almost all features and two domains sharing only one feature. To investigate former case, we applied the face attribute conversion task on CelebA dataset (Liu et al., 2015), where only one feature, such as gender or hair color, varies between two domains and all the other facial features are shared. The results are listed in Figure 7.
In Figure 7a, we can see that various facial features are well-preserved while a single desired attribute (gender) is changed. Also, 7b and 7d shows that background is also well-preserved and images are visually natural, although the background does change in a few cases such as Figure 7c. An extension to this experiment was sequentially applying several translations – for example, changing the gender and then the hair color (7e), or repeatedly applying gender transforms (7f).
We also investigated the opposite case where there is a single shared feature between two domains. 3D rendered images of chair (Aubry et al., 2014) and the previously used car and face datasets (Fidler et al., 2012; Paysan et al., 2009) were used in this task. All three datasets vary along the azimuth rotation. Figure 8 shows the results of image-to-image translation from chair to car and from car to face datasets. The translated images clearly match the rotation feature of the input images while preserving visual features of car and face domain, respectively.
Edges-to-photos is an interesting task as it is a 1-to-N problem, where a single edge image of items such as shoes and handbags can generate multiple colorized images of such items. In fact, an edge image can be colored in infinitely many ways. We validated that our DiscoGAN performs very well on this type of image-to-image translation task and generate realistic photos of handbags (Zhu et al., 2016) and shoes (Yu & Grauman, 2014). The generated images are presented in Figure 9.
Finally, we investigated the case with two domains that are visually very different, where shared features are not explicit even to humans. We trained a DiscoGAN using previously used handbags and shoes datasets, not assuming any specific relation between those two. In the translation results shown in Figure 1, our proposed model discovers fashion style as a related feature between the two domains. Note that translated results not only have similar colors and patterns, but they also have similar level of fashion formality as the input fashion item.
Recently, a novel method to train generative models named Generative Adversarial Networks (GANs) (Goodfellow et al., 2014) was developed. A GAN is composed of two modules – a generator and a discriminator . The generator’s objective is to generate (synthesize) data samples whose distribution closely matches that of real data samples while the discriminator’s objective is to distinguish real ones from generated samples. The two models and , formulated as a two-player minimax game, are trained simultaneously.
Researchers have studied GANs vigorously in two years: network models such as LAPGAN (Denton et al., 2015) and DCGAN (Radford et al., 2016) and improved training techniques (Salimans et al., 2016; Arjovsky et al., 2017). More recent GAN works are described in (Goodfellow, 2017).
Several methods were developed to generate images based on GANs. Conditional Generative Adversarial Nets (cGANs) (Mirza & Osindero, 2014) use MNIST digit class label as an additional information to both generator and discriminator and can generate digit images of the specified class. Similarly, Dosovitskiy et al. (2015) showed that GAN can generate images of objects based on specified characteristic codes such as color and viewpoint. Other approaches used conditional features from a completely different domain for image generation. For example, Reed et al. (2016) used encoded text description of images as the conditional information to generating images that match the description.
Some researchers have attempted to use multiple GANs in prior works. (Liu & Tuzel, 2016)
proposed to couple two GANs (coupled generative adversarial networks, CoGAN) in which two generators and two discriminators are coupled by weight-sharing to learn the joint distribution of images in two different domains without using pair-wise data. In Stacked GANs (StackGAN)
(Zhang et al., 2016), two GANs are arranged sequentially where the Stage-I GAN generates low resolution images given text description and the Stage-II GAN improves the generated image into high resolution images. Similarly, Style and Structure GAN (S-GAN) (Wang & Gupta, 2016) used two sequentially connected GANs where the Structure GAN first generates surface normal image and the Style GAN transforms it into natural indoor scene image.In order to control specific attributes of an image, T. Kulkarni & P. Kohli (2015) proposed a method to disentangle specific factors by explicitly controlling target code. Perarnau et al. (2016)
tackled image generation problems conditioned on specific attribute vectors by training an attribute predictor along with latent encoder.
In addition to using conditional information such as class labels and text encodings, several works in the field of image-to-image translation used images of one domain to generate images in another domain. (Isola et al., 2016) translated black-and-white images to colored images by training on paired black-and-white and colored image data. Similarly, Taigman et al. (2016)
translated face images to emojis by providing image features from pre-trained face recognition module as conditional input to a GAN.
Recently, Tong et al. (2017) tackled mode-collapsing and instability problems in GAN training. They introduced two ways of regularizing general GAN objective – geometric metrics regularizer and mode regularizer.
This paper presents a learning method to discover cross-domain relations with a generative adversarial network called DiscoGAN. Our approach works without any explicit pair labels and learns to relate datasets from very different domains. We have demonstrated that DiscoGAN can generate high-quality images with transferred style. One possible future direction is to modify DiscoGAN to handle mixed modalities (e.g. text and image).
Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR)
, 2014.Learning to generate chairs with convolutional neural networks.
In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2015.3d object detection and viewpoint estimation with a deformable 3d cuboid model.
In Advances in Neural Information Processing Systems (NIPS), 2012.Proceedings of the 30th International Conference on Machine Learning (ICML)
, 2013.