Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AC-GAN using keras-adversarial package #62

Open
rjpg opened this issue Jul 13, 2018 · 0 comments
Open

AC-GAN using keras-adversarial package #62

rjpg opened this issue Jul 13, 2018 · 0 comments

Comments

@rjpg
Copy link

rjpg commented Jul 13, 2018

A complete example of AC-GAN using keras-adversarial would be nice !

I have ac-gan implemented here :

https://github.com/rjpg/bftensor/blob/master/Autoencoder/src/ac-gan2.py

but it is slow ... I notice that it only uses one core ... this keras-adversarial package seams to be optimized to work with all cores ... that is why it is important.

If someone takes this task, it is important to have the accuracy metric (train/test) of the softmax on the discriminator side among with loss ..

In AC-GAN:
1 - the discriminator input is only the image : [image]
2 - the discriminator output is one softmax with N classes and one sigmoid to identify real/fake [labels,valid]
3 - the generator input is : [noise,label] (then they are multiplied to give color to the noise to be oriented to generate one class )
4 - the generator output is only one image : [image]

when training fake images the random labels to use in the generator to create images to train must be used also in the discriminator training , something like :

....
# Adversarial ground truths
valid = np.ones((batch_size, 1))
fake = np.zeros((batch_size, 1))
...

#inside train cycle
                ...
                # real data 
                imgs = X_train[index * batch_size:(index + 1) * batch_size]
                img_labels = y_train[index * batch_size:(index + 1) * batch_size]
                #end real data

                # generated data 
                noise = np.random.normal(0, 1, (batch_size, 100))
    
                # The labels of the digits that the generator tries to create an
                # image representation of
--->          sampled_labels = np.random.randint(0, 10, (batch_size, 1))
    
                # Generate a half batch of new images
--->            gen_imgs = self.generator.predict([noise, sampled_labels])
                #end generated data

                # Train the discriminator
                d_loss_real = self.discriminator.train_on_batch(imgs, [valid, img_labels])
--->           d_loss_fake = self.discriminator.train_on_batch(gen_imgs, [fake, sampled_labels])

                d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
                ...

if possible :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant