This code is modified from duxingren14/DualGAN, in order to make it less coupled.
There are 2 changes:
-
Split up training process from DualGAN model part.
In origin code, the training operation is excuted inside DualGAN model part, this make it hard to change runing mode of Batch Normalization (Batch Normalization has different behavior in training and inference phase).
-
Set
is_training=True
in training phase and setis_training=False
in inference phase. Have a look at ops.py.In origin code, the Batch Normalization is always running in training mode even when sampling images, which is supposed to be set to
is_training=False
as described above.
I did't mean to generate very realistic images that can fool human, I just want to make it clear how it is different of generated images when using Batch Normalization, Batch Renormalization, Instance Normalization.
As a result, the generated images looks bad, but after carefully tuning model and training parameters, good results can also be generated.
-
Numpy
-
TensorFlow 1.2 or higher
-
scipy.misc
Datasets could be downloaded from duxingren14/DualGAN.
There are many parameters with which you can play, have a look at main.py.
-
Train
python main.py --phase train --dataset_name day-night
-
Inference
python main.py --phase infer --dataset_name day-night
-
Training mode
The generated images in training mode still look good. More samples could be seen at duxingren14/DualGAN.
Images generated in train mode:
Note:
All of images in duxingren14/DualGAN are generated in training mode, which means setting
is_training=True
when sampling images. -
Inference mode
However, in inference phase, the generated images looks very bad, there are just noisy points.
Images generated in inference mode:
I don't know what exactly is going on here. Someone could explain this ?
-
It seems that the bad results generated in inference mode is caused by Batch Normalization, see links bellow for explaination.
-
To solve this problem, you can use Batch Renormalization or Instance Normalization.
-
I tried Batch Renormalization (tf.layers.batch_normalization in tensorflow), and the results on dataset are much better than that generated using Batch Normalization, but results on other datasets are as bad as Batch Normalization. Maybe the hyper-parameters (
renorm_clipping
,renorm_momentum
and other model or training parameters) are what matters. -
Instance Normalization is not test, Instance Normalization is supposed to get as good as runing in training mode in Batch Normalization. You can have a try and see what will happen.