{'fraction_non_alphanumeric': 0.0352905487393825, 'fraction_numerical': 0.017999191047593368, 'mean_word_length': 4.5947576843296245, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learning Unsupervised Cross-domain Image-to-Image Translation Using a Shared Discriminator

Unsupervised image-to-image translation is used to transform images from a source domain to generate images in a target domain without using source-target image pairs. Promising results have been obtained for this problem in an adversarial setting using two independent GANs and attention mechanisms. We propose a new method that uses a single shared discriminator between the two GANs, which improves the overall efficacy. We assess the qualitative and quantitative results on image transfiguration, a cross-domain translation task, in a setting where the target domain shares similar semantics to the source domain. Our results indicate that even without adding attention mechanisms, our method performs at par with attention-based methods and generates images of comparable quality.


INTRODUCTION
Generative Adversarial Networks(GANs) (Goodfellow et al., 2014) belong to the class of generative models (Kingma and Welling, 2013) widely used in various image generation and translation tasks like computer vision and image processing (Johnson et al., 2016), , (Wu et al., 2017). While the state-of-the-art methods (Huang et al., 2018), , (Park et al., 2019) in image-to-image translation tasks are significantly good (Wang et al., 2018b), (Mejjati et al., 2018),  across multi-domain and crossdomain tasks, there is still room for improvement in image transfiguration tasks. Most of the imageto-image translation tasks assume the availability of source-target image pairs , (Zhu et al., 2017b) or expect the source-target pairs to have rough alignment between them , (Wang et al., 2018b). However, there are scenarios where source-target image pairs are not available or when arbitrarily selected source-target image pairs have poor alignment between them.
While most image-to-image translation tasks involve translation over the complete image, there are cases where only an object of interest needs to be a https://orcid.org/0000-0003-4174-8587 b https://orcid.org/0000-0003-2890-6421 translated in the source and target domain. Let's consider the case of translating images of apples to oranges or horses to zebras. In both cases, only the object of interest needs to be translated, without affecting the rest of the image or it's background. This calls for the need of attention mechanisms (Kastaniotis et al., 2018), , (Zhang et al., 2018), (Talreja et al., 2019) to attend to the objects of interest. Contrast-GAN (Liang et al., 2017) is a work that has used object-mask annotations to guide the translation at high-level semantic levels at the cost of extra data. However, recent works have used attention mechanisms (Wang et al., 2017), (Mejjati et al., 2018),  without using any extra data or pretrained models. Moreover, very few works focus on image transfiguration, a cross-domain imageto-image translation task in an unsupervised setting without using additional networks, extra data or attention mechanisms.
In this paper, we focus on the above problem by proposing a framework that unifies the capabilities of multiple discriminators into a shared one, which not only improves the efficacy but also works without using extra data(object masks) or attention mechanisms. Adversarial training of the network involves combining the labels of the domains from different tasks conditioned on the input image and optimizing the objectives of the networks. We believe that there has not been any previous work where a dual generator shared discriminator setup has been used for crossdomain image-to-image translation and we are the first to propose a novel method. We summarize the paper contribution as follows: 1. We improve the efficacy of the GANs used for unsupervised cross-domain image-to-image translation tasks by introducing a novel shared discriminator setup. We empirically demonstrate the effectiveness of our method on image transfiguration tasks and report the qualitative and quantitative results on two datasets.
2. We conduct an ablation study to study the efficacy of the networks, training objectives and architectures keeping the dataset and other parameters constant and report the quantitative results of the study.

Related work
Generative Adversarial Networks: GANs are generative networks that use a trainable loss function to adapt to the differences between the data distributions of generated images and the real images. Since their inception (Goodfellow et al., 2014) (Radford et al., 2015), GANs have been used in various applications from computer vision (Ma et al., 2017), (Vondrick et al., 2016), image-to-image translation (Taigman et al., 2016), (Tung et al., 2017), video-tovideo translation , (Wang et al., 2018a), image super-resolution (Ledig et al., 2016), etc. among others. We refer interested readers to read more about GANs from (Creswell et al., 2018), (Jabbar et al., 2020), (Kurach et al., 2018) and (Wang et al., 2020). Image-to-image translation: Recent image-toimage translation works like pix2pix , pix2pixHD (Wang et al., 2018b) use conditional GANs to learn a mapping from source domain images to target domain images. While some rely on paired source-target images, works like CycleGAN, DualGAN, DiscoGAN (Kim et al., 2017) and (Tung et al., 2017), (Taigman et al., 2016), (Liu and Tuzel, 2016), , (Bousmalis et al., 2016) learn the mapping between the source domain and target domain without using any paired images. CoGAN (Liu and Tuzel, 2016) also learns the joint distribution of multi-domain images by sharing weights of generators and discriminators. UNIT  uses a shared latent space framework built on CoGANs to learn a joint distribution of different domain images and achieves very high quality image translation results.
In an adversarial setting, image-to-image translation involves generators that learn mappings to translate images from a source domain to a target domain and vice-versa. Furthermore, adversarial methods that involve GAN either share network weights (Liu and Tuzel, 2016), (Talreja et al., 2019) or use mechanisms (Yi et al., 2017), (Zhu et al., 2017a) that involve a primal GAN and a dual GAN. A Dual-GAN (or DualGAN) (Yi et al., 2017) setup employs two discriminators: a primal GAN and a dual GAN, performing inverse tasks of each other. Each discriminator is trained to discriminate target domain images as positive samples and translated source domain images as negative samples. Similarly, in CycleGAN (Zhu et al., 2017a), the primal-dual relation is regularized by a forward consistency loss and backward cycle consistency loss, which constitutes the cycleconsistency loss. This reduces the space of possible mappings by enforcing a strong relation across domains.
Conventionally, separate task-specific generators and discriminators are needed for image-to-image translation, since each network deals with a different set of real and fake images. However, StarGAN (Choi et al., 2018) achieves multi-domain image translation using a single generator by considering each domain as a set of images with a common attribute (for e.g. hair color, gender, age, etc.) and by exploiting the commonalities in the datasets. Similarly, a Dual Generator GAN(G 2 GAN)  consists of two task-specific generators and single discriminator focusing on multi-domain image-to-image translation. However, their optimization objective is complex, consisting of five components including color consistency loss, MS-SSIM loss and conditional identity preserving loss for preventing mode collapse. While Dual Generator GAN uses a single discriminator, the underlying task is multi-domain image translation. However, in this paper we focus on the task of cross-domain image translation using a single shared discriminator.

Methodology
We briefly explain the problem formulation in subsection 3.1, proposed framework in subsection 3.2, image pools in subsection 3.2.1, training stages in subsection 3.3 and loss functions in subsection 3.4 below.

Problem Formulation
For the image-to-image translation problem, our goal is to learn two mapping functions, G AB : A → B and G BA : B → A, between domains A and B modelled by generators G AB and G BA respectively. We consider task-specific generators since the input distribution is different for each task in cross-domain image-toimage translation. A domain is referred to as either source or target domain, based on its role in the translation task. The goal of the generator G AB is to translate an input image a from source domain A to the target domain, such that the generated image b * follows the distribution of the target domain B, p data (B). Likewise, the task of generator G BA is to translate an image b ∈ B to an image a * such that it follows the distribution of the target domain A, p data (A). We propose to provide adversarial supervision using a novel shared discriminator, D shared common to both the generators without using extra networks, masks or additional data. In this paper, we focus our method on transfiguration tasks, which requires translation of objects of interest while keeping other objects and the background same. Some transfiguration tasks include apples ↔ oranges, horses ↔ zebras, etc.

Proposed Framework
Each translation task (A → B and B → A) is mapped to a separate generator. For guided image generation, we use conditional GANs (Mirza and Osindero, 2014) that condition using the input images. During training, each generator learns to translate its input from source domain to the corresponding target domain. However, our approach differs from the conventional setting, which treats the target domain samples as real and translated images as fake. Instead, we exploit the fact that the data distributions of the source and the target domains of one translation task are the same as that of the target and the source domains of its inverse translation task.
In our novel formulation, the proposed shared discriminator D shared is trained to classify the generated images into either belonging to domain A or domain B. The translated images and random images from the two domains are conditioned on the input images to form the base for adversarial training using the shared discriminator. We hypothesize that this unification allows for domain-aware discrimination which is crucial for tasks like transfiguration, where a specific part of the image with distinct feature sets are to be transformed. GANs are infamous for unstable training and prone to model oscillation. To stabilize the model training, we leverage the power of image pools with modifications tailored for our approach. Once the training is complete, the generator outputs are treated as final prediction and the discriminators are not needed in inference stage. Figure 1: The above image corresponds to training stage 1, with two generators and two image pools. Here the generated images are pushed to the same image pool as that of the translation task. Shared discriminator has been avoided for brevity. Figure 2: The above image corresponds to training stage 2, with two generators and two image pools. Here the generated images are pushed to the image pool of the corresponding inverse translation task. Shared discriminator has been avoided for brevity.

Image Pools
Generally, the generator outputs are reused in imageto-image translation techniques that involves a reconstruction loss between the source image and the reconstructed image(the resulting image after undergoing two translations, from source domain to the target domain and back to the source domain). An image pool (Shrivastava et al., 2016) is generally used to store a history of generated images to feed the discriminator in order to reduce the model oscillation during adversarial training. In our method, we associate an image pool to the generator of each translation task, such that the translated images can be reused as inputs to either of the generators by pushing to one image pool or the other, i.e. image pool I AB is associated with G AB and image pool I BA is associated with G BA (see Fig. 1 and Fig. 2). We use this simple tweak to improve the robustness of the generators to deal with variety of input images. In some cases, we also observe performance improvements, which we discuss later in the ablation study. Since the generated images are pushed to the image pools, each image pool gets a static input set of source domain images and an evolving input set of generated images from one generator or the other, depending upon the training stage.

Training stages:
We consider the image-to-image translation task A ↔ B by learning the translation mapping G AB : A → B and it's inverse translation mapping G BA : B → A. Throughout the training process, the inputs to the generators G AB and G BA are from the image pools I AB = {a 1 , a 2 , . . . , a |I AB | } and I BA = {b 1 , b 2 , . . . , b |I BA | } respectively. The image pools are initialized by the images of their source domains, A and B. The details of each training stage are given below. Training stage 1: If we consider the initial stages of training, the translated images appear closer in appearance to the source domain with very few target domain features. Therefore, we interleave the translated images from the generator with the source domain images using the same image pool, i.e. I AB would pool-in images a from A and b * from G AB (a), and I BA would pool-in images b from B and a * from G BA (b) as depicted in Fig. 1. Training stage 2: As training proceeds, the generators improve upon their translation capabilities and the generated images possess more target domain features and very few source domain features. Therefore, each generator can take the outputs of the other generator as adversarial images, in addition to their respective source domain images, i.e. I AB would pool-in images a from A and a * from G BA (b), and I BA would pool-in images b from B and b * from G AB (a) as depicted in Fig. 2. The generated images are pushed to the image pool of the inverse translation task, to mimic cyclic translations as done in some related works.

Loss Functions
Conventionally, a discriminator is used to distinguish between real images from the dataset and fake images generated by the generator. However, we avoid the usage of the terms real images and fake images, and use abstract binary labels True and False instead. We assign the same labels for a domain irrespective of the translation task or their role in the translation task, i.e. the label assigned for the source domain images in the forward translation is the same as that of the target domain images in the inverse translation task. We assign true labels for domain B images and false labels for domain A images. Discriminator loss: All translated images are conditioned on the their input images when subjected to the discriminator, while optimizing the objectives of D shared , i.e. b * is conditioned on a and a * is conditioned on b . The generated images, a * from G AB (a ) and b * from G BA (b ) are labelled the same labels as their source domain images a and b respectively, while subjecting to the discriminator. The shared discriminator D shared is trained with a binary cross entropy loss L D shared . The goal of D shared is to classify the generated images into either domain A or domain B depending upon the source domain of the translation task. In addition, we subject the shared discriminator to random domain B images labelled as true and random domain A images labelled as false. These random images are conditioned on input images a or b depending on the translation task or whether they are input to generator G AB or G BA respectively. Formally, the complete training objective of D shared or the discriminator loss function is given by, The first three parts of Eq. 1 are conditioned on input images a from image pool I AB and represent the translation A → B, while the latter parts are conditioned on the input images b from image pool I BA and represent the translation B → A. Generator loss: We enforce a reconstruction loss between the generator's input and it's output involving only one image translation, in contrast to conventional pixel reconstruction objectives that involves translations over both directions. We choose a loss function that can preserve the median values, so that the objects of interest are translated without translating other objects in the image or the background. This motivates the use of L 1 pixel reconstruction loss between the input and output of each generator with additional help from adversarial training. The adversarial goal of each generator is to fool the shared discriminator into identifying generated images as belonging to the target domain images, i.e. G AB tries to map b * as belonging to B while G BA tries to map a * as belonging to A. The adversarial losses overrule the reconstruction loss over the membership score of the generated image, which results in the source images to take target domain features. We can express the full objective of G AB as the sum of Eq. 2, which corresponds to the adversarial loss and Eq. 3, which corresponds to the L 1 reconstruction loss. Similarly, we can express the full objective of G BA as the sum of Eq. 4, which corresponds to the adversarial loss and Eq. 5, which corresponds to the L 1 reconstruction loss.

Implementation
We trained the tasks on 128x128 size images as well as on 256x256 size images. For training, the training images were resized to 1.125 times and were randomly cropped to the required size. The batch size for all our experiments was 4. Smaller batch sizes enable training with larger image sizes. Also, the image pools could be stored in the main memory or cuda device memory. We experimented with the Adam optimizer as well as RMSProp, and found that Adam gives better performance for most of our experiments. We used a learning rate of 0.0001 with the Adam optimizer with betas of 0.5 and 0.999. We used the adversarial loss for membership score with the vanilla GAN or binary cross entropy with logit loss. We used a lambda of 10.0 for the adversarial losses and a lambda in [100.0, 200.0] for the reconstruction loss.

Architecture:
We use identical network architecture for both the generators throughout an experiment. We conduct experiments with the Resnet (He et al., 2015) architecture as well as Unet (Ronneberger et al., 2015) architecture. While using the Unet architecture, the generator has the same number of downsampling layers and upsampling layers with a bottleneck in between and skip connections connecting the downsampling and upsampling layers. Our proposed method doesn't use noise vectors as in the pix2pix implementation . Also, using dropout doesn't affect the performance of our method when implemented with the Unet architecture. In the Resnet architecture, the skip connections exist between Resnet blocks. The discriminator's architecture used in our experiments is PatchGAN (Zhu et al., 2017a).  Figure 3: Comparison of test images generated by different methods (Zhu et al., 2017a), (Wang et al., 2017), (Kim et al., 2017), , (Yi et al., 2017), (Mejjati et al., 2018),  (left to right) on zebra to horse task. Leftmost column shows the input, rightmost column shows results from our method. Figure 4: Comparison of test images generated by different methods (Zhu et al., 2017a), (Wang et al., 2017), (Kim et al., 2017), , (Yi et al., 2017), (Mejjati et al., 2018),  (left to right) on horse to zebra task. Leftmost column shows the input, rightmost column shows results from our method.

Evaluation metric:
We use the Frechet Inception Distance(FID) (Heusel et al., 2017) and Kernel Inception Distance(KID) (Bińkowski et al., 2018) preferably over metrics like Inception score. For both metrics, lower scores imply similarities in features between the compared sets of images. However, both metrics are adversely affected by the presence of adversarial noise and hallucinated features in the generated images that these metrics do not correlate to the judgement by human perception. This suggests that either metrics aren't better than each other, and better scores doesn't always imply better translation results. Hence, we consider those FID and KID scores from our experiments which are positively correlated.  (Kim et al., 2017), (Wang et al., 2017), (Yi et al., 2017), , (Zhu et al., 2017a), (Mejjati et al., 2018),

Experiments
We compute the KID score over 100 iterations and return its mean, while the FID scores are computed over 10 iterations and the mean value is returned. We compute the KID scores and FID scores on the test data using the generator models from the same checkpoint. We trained the tasks on 128x128 size images as well as on 256x256 size images and tested both category of models on 256x256 test images. We refer  to compile the experimental results in the qualitative comparisons and metric scores in Table 3 and 2. We report the performance comparison of different architectures on translation tasks horse ↔ zebra and apples ↔ oranges, measured in FID and KID scores in Table 1. We report the FID scores on horse → zebra translation task in Table 2. KID scores are compared over the horses ↔ zebras task and apples ↔ oranges task in Table 3. The results of qualitative comparisons includes the comparison of translated images from zebras → horses task in Fig. 3, horses → zebras task in Fig. 4, oranges → apples task in Fig. 5, and apples → oranges task in Fig. 6. Figure 5: Comparison of test images generated by different methods (Zhu et al., 2017a), (Wang et al., 2017), (Kim et al., 2017), , (Yi et al., 2017), (Mejjati et al., 2018),  (left to right) on oranges to apples task. Leftmost column shows the input, rightmost column shows results from our method. Figure 6: Comparison of test images generated by different methods (Zhu et al., 2017a), (Wang et al., 2017), (Kim et al., 2017), , (Yi et al., 2017), (Mejjati et al., 2018),  (left to right) on apples to oranges task. Leftmost column shows the input, rightmost column shows results from our method.

Results and Discussion
The results from Table 1 suggest that there is a slight gain in the performance by using dropout with the Resnet network architecture for the horse → zebra task, while the same is more or less not true for apples → oranges task. We hypothesize that this observation could be due to the simplicity of the apples → oranges task while the former task is more complex.
The results from Table 3 and Table 2 suggest that our method is at par to existing image translation methods where some related methods have an upper hand due to the underlying attention mechanisms. On comparing the qualitative results for zebras → horses in Fig.3, in the second row we can notice that the text color and the background are preserved only in the translated images from UAIT (Mejjati et al., 2018), AttentionGAN  and our method. Also, our method has comparable results to (Mejjati et al., 2018) and , which uses attention mechanisms. While CycleGAN does a great job in translating all zebra images to horse images, the background color and tint are affected in some of the images and is severe than ours.
On comparing the qualitative results for horses → zebras in Fig. 4, we notice that residual attention based method (Wang et al., 2017) generates convincing translation results, while there is a green tint in all the translated images which makes it unfavourable. Similarly, UNIT  also has artifacts in the background that makes the appearance just acceptable. Our method falls behind UAIT (Mejjati et al., 2018) and AttentionGAN results  but appears better than CycleGAN results, which has undesirable background tint in many images. Note that the translation quality drastically dropped for DualGAN (Yi et al., 2017), with slightly better results from DiscoGAN (Kim et al., 2017).
On comparing the qualitative results for oranges → apples in Fig. 5, we notice that our translation results are at par with UAIT (Mejjati et al., 2018) and AttentionGAN , which uses attention mechanisms. CycleGAN also follows our results except that it fails in some of the images with unwanted background translations. DualGAN, DiscoGAN, UNIT and residual attention (Wang et al., 2017) fails on a task much easier than the horses ↔ zebras task.
On comparing the qualitative results for apples → oranges in Fig. 6, we notice that our method consistently keeps the quality upto the mark of attention guided methods (Mejjati et al., 2018), . While CycleGAN is able to translate convincingly, it is affected by a strong tint in some of the images. The translation results from UNIT and residual attention method appear similar to that of DualGAN and DiscoGAN, despite the use of attention mechanisms. Ablation study: We perform an ablation study to isolate the effects and understand the effectiveness of various components of our method using FID and KID metric over horse ↔ zebra task comparing the baseline to different variants. We consider the original shared discriminator setup, D shared to be the baseline for comparing the variants. The quantitative results of the ablation study are available in Table 4 and 5 for images trained on 128x128 size images and tested on 256x256 size images and in Table 6 and 7 for images both trained and tested on 256x256 size images.
First, we modify the objective of the shared discriminator in a variant D shared 1 to see if all six components are really necessary. Out of the six components of the shared discriminator objective, four of them involves random source or target domain images conditioned on either a or b . It may seem logical to remove two random image components of one translation task or the other to make the shared discriminator objective compact, since they differ only in the conditioned part, i.e. a or b . To verify that, we deal with each domain only once and as target domain in the variant D shared 1 . The source domain images conditioned on the input images are not subjected to the shared discriminator and avoided in the objective assuming that the same domain images as target domain and labels will suffice. In other words, for the image translation task A → B, we consider only random target domain images b from B with true labels conditioned on the input images a to the shared discriminator. Analogously, for the image translation task B → A, we consider only random target domain images a from A, conditioned on the input images b with false labels to the shared discriminator. The generator's goal and objectives are unaltered in     Table 4, 5, 6 and 7 from the ablation study for D shared 1 (or variant 1 ) indicate that irrespective of the image sizes used for training, the performance of the shared discriminator setup drops on removing the components of D shared 's objectives. Both FID and KID values have gone higher for D shared 1 , which is not desirable for good image translation results.
The second variant that we consider is a shared discriminator setup without the image pool, i.e. the translated images are not reused as inputs to any of the generators. While the results in Table 6 and 7 suggest that using image pool doesn't improve the performance of our method, the results in Table 4 and 5 suggest that there is considerable drop in performance when the image pool is not used while training on smaller images and testing the model on larger images. We hypothesize that the generators become more robust when trained with additional translated images with the help of image pools.
The third variant that we consider is a shared discriminator setup without the training stage-1, i.e. the translated images are pushed to the image pool of the inverse translation task, throughout the training process. Similarly, the fourth variant that we consider is a shared discriminator setup without the training stage-2, i.e. the translated images are pushed back to the image pool of the same translation task throughout the training process. The results in Table 6 suggest that FID values are not really affected for variant 3 and variant 4 , while Table 7 suggests that the KID values increase (or performance drops) for variant 3 and variant 4 when either training stage-1 or stage-2 is used throughout the training process. Similarly, the results from Table 4 and 5 for variant 3 and variant 4 indicates that the performance drops on using only one of the training stages. We hypothesize that simply reusing translated images with an image pool doesn't improve the performance and can result in a drop in performance.

Summary
In this paper, we propose a framework for image transfiguration, a cross-domain image-to-image translation task improving the efficacy using a shared discriminator in an unsupervised setting. We also introduce a novel application of image pools to keep the generators more robust in the process. The qualitative and quantitative results, using metrics like FID and KID, suggest that our method, even without using masks or attention mechanisms, is at par with attention-based methods. For particular tasks, where the source domain shares similar semantics with the target domain, our method performs better than previous methods. Also, we observe that metrics like KID and FID are insufficient to evaluate the quality of translated images. They are also vulnerable to adversarial noise and hallucinated features, hampering a fair comparison of image translation methods. Future work could use attention mechanisms to further improve the results and better comparison metrics that correlate to human perception.