Open 7color94 opened 5 years ago
Not sure if I understand your question. First of all you refer to conditional generation based on labels, image2image or unconditional generation based on noise?
Sorry for my poor descriptions. I am reading your pose-gan project, which is a image2image problem. But in train_one_step, it implement the training phase of unconditional generation based on noise in this paper, right? And one more question is that why use y_pred (instead of y_true) to compute true loss for discriminator ?
Initially, I tried to create this gan sub-module to being easily adapted for arbitrary gan (image2image, conditional and staff). But I have to admit that this was not very good decision, and because of this some parts is hard to understand and it is not perfectly optimized. 1) In train_one_step, when training discriminator, it loads discrimiantor_batch and generator_batch as follows:
Indeed you a right the usual way to implement it in image2image: take a batch of pairs (image_from_A, image_from_B) forward images_from_A through generator and obtain generated_from_B. Then forward (image_from_a, image_from_B) and (image_from_a, generated_from_B) through discriminator. In this way you can save some computational time (one generator pass), but on the other hand iid assumption for discriminator breaks.
In my implementation I separated discriminator step from generator step. In details I train discriminator with some data, then sample different data for training generator. This is less efficient, but more theoretically correct. And it was also easier to implement, when I need to do multiple discriminator steps, e.g (training_ratio > 1).
2) But in train_one_step, it implement the training phase of unconditional generation based on noise in this paper, right?
As I said above I tried to implement everything in this function. Both unconditional, conditional and image2image.
3) And one more question is that why use y_pred (instead of y_true) to compute true loss for discriminator ?
This is another consequence of poor initial decisions. Loss in keras should always have the following signature loss(y_true, y_pred). Because of that in order to have the loss that depends only on predictions (like in Discriminator loss for real images, or loss for fake images) I need to pass dummy labels: https://github.com/AliaksandrSiarohin/gan/blob/a4aa9a38792e89480ffbb15dc7e9beba8513e893/train.py#L62.
In later version of this module I fix this staff, and it seems more clear.
Hope this clarify some of your doubts.
In train_one_step, when training discriminator, it loads
discrimiantor_batch
andgenerator_batch
as follows:, but the question is that the batch images in
discrimiantor_batch
andgenerator_batch
are totally different, which means that the discriminator computes the true loss (using discrimiantor_batch) and fake loss (using generator_batch) using different images. It seems uncommon when training the discriminator. Could you please explain it? Thanks.