The image-to-image translation is the task of taking images from one domain and transforming them so they have the style (or characteristics) of images from another domain. Our project’s goal is to implement a cross-domain image transform, in which the senses of the blocks-based world in Minecraft could be converted into an actual photo composed by items and scenes similar to those in the real world. In particular, we used unpaired images captured in the Minecraft world and photos of actual environments to train the networks. Our model is supposed to capturing special characteristics of one image collection and figuring out how these characteristics could be translated into the other image collection. Therefore, we expected to achieve that the generated pictures from Minecraft are composed of recognizable items and scenes as same as those in input image but with smooth edges and authentic textures (and vice versa).
By implementing the translation, Minecraft users are able to enjoy the experience in a more realistic scene. Meanwhile, the possible applications of Minecraft have been discussed extensively, especially in the fields of computer-aided design and education. Well-constructed networks can be applied to these fields as well to convert models from Minecraft into photos of the actual objects even without paired training data.
Cycle-Consistent Adversarial Networks (CycleGANs)
Cycle-Consistent Adversarial Network (CycleGAN) is introduced in the paper “Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks” from UC Berkeley. The figure below illustrates how CycleGANs work:
From the figure, (a) CycleGANs have two mapping functions and , and two corresponding discriminators and . The discriminator encourages to translate into outputs indistinguishable from domain , and vice versa for and . In addition, there are two cycle-consistence losses that enforce the consistency between original and reconstructed images: (b) forward cycle-consistency loss: , and (c) backward cycle-consistency loss: .
Adversarial Loss
For the mapping function and its corresponding discriminator , the adversarial loss is defined as
Similarly, for the mapping function and its corresponding discriminator , the adversarial loss is defined as
The generative network aims to minimize the adversarial loss, while the discriminative network strives to maximize this objective, i.e., and .
Following the orginal paper, the negative log likelihood objective is replaced by a least-squares loss. For the modified adversarial loss , the mapping function tries to minimize during training, while the corresponding discriminator minimizes .
Cycle Consistency Loss
We expect that if we transform a image from one domain to another one and then convert it back, the reconstructed image should be similar with the original one. Therefore, the two mapping functions and should be cycle-consistent. For every image from the domain , the cycle consistency is to enforce that . Similarly, for each image from the domain , the image translation cycle should be able to reconstruct the orginal image, i.e., . The cycle consistency loss is defined using L1 loss in the orginal paper, which is
In preliminary experiments, we also tried to define the cycle consistency loss using L2 loss. However, we did not see any improvement.
Full Objective
Combining the loss functons defined above, we obtain the full objective for our model:
where is the relative weight of the cycle consistency loss. Hence, we are aiming to solve
Generator Architectures
There are three sections contained in each CycleGAN generator: an encoder, a transformer, and a decoder. The input image is transported into the encoder which is composed of three convolution layers. The result is then passed to transformer, which is a series of six residual blocks. After that it is expanded again by the decoder. As we can see from the picture, the representation size shrinks in the encoder phase, stay the same in the transformer phase and then expends in the decoder phase. The representation size is listed below each layer in terms of the input image size, . Every layer is listed the number of filters, the stride and the size of filters. Each layer is followed by an instance normalization and ReLU activation.
Source: “CycleGAN: Learning to Translate Images (Without Paired Training Data)”
Discriminator Architectures
The discriminators are PatchGANs, a fully convolutional neural network that focus on the “patch” of the input image and outputs how likely the patch being “real”. It’s much more computationally efficient than looking at the entire input image.And it’s also more effective since it allows the discriminator to focus on more surface-level features which is often being changed in an image translation task. As we can see from the picture below, the means the input image size and one each layer is listed the number of filters, the stride and the size of filters.
Source: “CycleGAN: Learning to Translate Images (Without Paired Training Data)”
Implementation
We build the model from scratch using PyTorch, a machine learning library for the programming language Python. The implementation can be found here.
Data Collection
For Minecraft data collection, we have an agent walk randomly and look around in the Minecraft world. We capture an image every second. The real-world images are photos downloaded from Flickr using Flickr API. The images were scaled to 128 × 128 pixels. The training set size of each class is 3295 (Minecraft) and 3116 (Real-world images). During training, the dataloader have the data reshuffled at every epoch.
Hyperparameter Tuning
For our experiments, we set the weight of the cycle consistency loss . Same as the original paper, we use the Adam solver with a batch size of 1. The learning rate is set to 0.0002. The coefficients used for computing running averages of gradient and its square are set to (0.5, 0.999).
Here is an example of real-time transformation:
We are not able to utilize some common metrics such as pixel accuracy or Intersection over Union (IoU) to conduct qualitative evaluations due to the lack of ground truth. On the other hand, the perceptual study we mentioned in the proposal is time consuming and difficut to receive the accurate feedbacks. Therefore, we present the plots of loss functions to illustrate the quantitative evaluation on our model. First, the plot of the adversarial losses and :
In addition, the visualization of cycle consistency losses is shown below:
It is difficult for us to interpret of loss functions for our model, which shares the similarity with other GANs. The convergence of these objectives is unclear.
The qualitative evaluation is to see if the created pictures is akin to that of the real world objects. Here, we present comparisons between original image (Minecraft image) and generated image (real-world image):
after 1 epoch:
after 25 epoches:
after 50 epoches:
after 100 epoches:
Based on the results shown above, we could see that through the training process, the generated image become more natural and real. The desert and clouds in Minecraft are transparently transformed to those in real world. We also do the experiment on transformation from real-world photo to Minecraft landscape. The comparison is shown below:
Although our method can achieve compelling results in many cases, the results are far from uniformly positive. A failure case is shown below:
I. Goodfellow, J. Pouget-Abadie, M. Mirza, B. Xu, D. Warde-Farley, S. Ozair, A. Courville, and Y. Bengio. Generative Adversarial Nets. In NIPS, 2014.
J.-Y. Zhu, T. Park, P. Isola, and A. A. Efros. Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks. In ICCV, 2017.
S. Wolf. CycleGAN: Learning to Translate Images (Without Paired Training Data).
PyTorch. https://pytorch.org.