eriklindernoren / Keras-GAN

Keras implementations of Generative Adversarial Networks.
MIT License
9.18k stars 3.14k forks source link

labels as input to cgan combined model #105

Open zhchyang2004 opened 5 years ago

zhchyang2004 commented 5 years ago

Regarding the parameter on Line 152 in Keras-GAN/cgan/cgan.py, does it make more sense to replace the input 'sampled_labels' with 'labels' defined in Line 131?

Line 131: imgs, labels = X_train[idx], y_train[idx] Line 152: g_loss = self.combined.train_on_batch([noise, sampled_labels], valid)

It is desired and appreciated to get your idea on it.

ghost commented 5 years ago

the G model needs two inputs(noise and condition),and D model needs what G generates and the label(what number G model generates) sampled_labels means the number that G model should generate. Sorry,English is not my native language.

zhchyang2004 commented 5 years ago

Thanks CreeperGo. I understand your meaning. But I don't think the label feeding to Discriminator should be generated by Generator. Labels feeding to Discriminator should be as same as those to Generator.

It is cited in '3.2 Conditional AdversarialNets' of the Paper via https://arxiv.org/abs/1411.1784, 'Generative adversarial nets can be extended to a conditional model if both the generator and discriminator are conditioned on some extra information y. y could be any kind of auxiliary information, such as class labels or data from other modalities. We can perform the conditioning by feeding y into the both the discriminator and generator as additional input layer.'

So, y should be the same one feeding into both the discriminator and generator. Right?

ghost commented 5 years ago

So, y should be the same one feeding into both the discriminator and generator. Right?

nope. Comparing with GAN,CGAN gives extra conditions to both G and D model.The G model learns from the gradients from D model.G model turns noise into generated samples.

ghost commented 5 years ago

GAN: [noise] -> G;[generated samples,true samples]->D; CGAN:[noise,conditions] -> G; [generated samples with conditions,true samples with conditions]->D;

eriklindernoren commented 5 years ago

Hi @CreeperGo. The discriminator evaluates whether the image samples are valid examples of the digit labels which it also receives as inputs. The randomly sampled labels which the generator tries to generate are fed to the discriminator together with the generator samples, where the generators objective is to have those samples being labeled as valid given the digit labels. Hope this clarifies.

daa233 commented 4 years ago

Hi @eriklindernoren! Thanks for your interpretation.

However, I have the same question as @zhchyang2004 issued.

I have seen several CGAN implementations. There are two ways to use the condition labels:

  1. feed G with a random label, feed D with the real label
  2. feed both G and D with the same real label

Here are my questions: