lukedeo / keras-acgan

Auxiliary Classifier Generative Adversarial Networks in Keras
213 stars 69 forks source link

Could this model be applied to cifar10? #6

Open King-Of-Knights opened 7 years ago

King-Of-Knights commented 7 years ago

Thanks for your great work in advance! I notice the paper author of "Conditional Image Synthesis with Auxiliary Classifier GANs" has applied their model in cifar10 and ImageNet. I guess I could modify your code and their hyper parameter to reconstruct their job. In the block of Generator, I did some modification to cater to the 3-channel figure: `def build_generator(latent_size):

we will map a pair of (z, L), where z is a latent vector and L is a

# label drawn from P_c, to image space (..., 3, 32, 32)
cnn = Sequential()
cnn.add(Dense(384, input_dim=(latent_size), activation='relu'))
cnn.add(Dense(192 * 4 * 4, activation='relu'))
cnn.add(Reshape((192, 4, 4)))

cnn.add(UpSampling2D(size=(2, 2)))
cnn.add(BatchNormalization())
cnn.add(Convolution2D(192, 5, border_mode='same', activation='relu', init='glorot_normal'))

cnn.add(UpSampling2D(size=(2, 2)))
cnn.add(BatchNormalization())
cnn.add(Convolution2D(96, 5, border_mode='same',
                      activation='relu', init='glorot_normal'))

cnn.add(UpSampling2D(size=(2, 2)))
cnn.add(Convolution2D(3, 5, border_mode='same',
                      activation='tanh', init='glorot_normal'))

# this is the z space commonly refered to in GAN papers
latent = Input(shape=(latent_size, ))

# this will be our label
image_class = Input(shape=(1,), dtype='int32')

# 10 classes in CIFAR10
cls = Flatten()(Embedding(10, latent_size,
                          init='glorot_normal')(image_class))

# hadamard product between z-space and a class conditional embedding
h = merge([latent, cls], mode='mul')

fake_image = cnn(h)

return Model(input=[latent, image_class], output=fake_image)

`------------------------------------------------------------------------ In the block of discriminator:

`def build_discriminator():

build a relatively standard conv net, with LeakyReLUs as suggested in

# the reference paper
cnn = Sequential()

cnn.add(Convolution2D(16, 3, 3, border_mode='same', subsample=(2, 2), init='glorot_normal', input_shape=(3, 32, 32)))
cnn.add(LeakyReLU(alpha=0.2))
cnn.add(Dropout(0.5))

cnn.add(BatchNormalization())
cnn.add(Convolution2D(32, 3, 3, border_mode='same', init='glorot_normal', subsample=(1, 1)))
cnn.add(LeakyReLU(alpha=0.2))
cnn.add(Dropout(0.5))

cnn.add(BatchNormalization())
cnn.add(Convolution2D(64, 3, 3, border_mode='same', init='glorot_normal', subsample=(2, 2)))
cnn.add(LeakyReLU(alpha=0.2))
cnn.add(Dropout(0.5))

cnn.add(BatchNormalization())
cnn.add(Convolution2D(128, 3, 3, border_mode='same', init='glorot_normal', subsample=(1, 1)))
cnn.add(LeakyReLU(alpha=0.2))
cnn.add(Dropout(0.5))

cnn.add(BatchNormalization())
cnn.add(Convolution2D(256, 3, 3, border_mode='same', init='glorot_normal', subsample=(2, 2)))
cnn.add(LeakyReLU(alpha=0.2))
cnn.add(Dropout(0.5))

cnn.add(BatchNormalization())
cnn.add(Convolution2D(512, 3, 3, border_mode='same', init='glorot_normal', subsample=(1, 1)))
cnn.add(LeakyReLU(alpha=0.2))
cnn.add(Dropout(0.5))

cnn.add(Flatten())

image = Input(shape=(3, 32, 32))

features = cnn(image)

# first output (name=generation) is whether or not the discriminator
# thinks the image that is being shown is fake, and the second output
# (name=auxiliary) is the class that the discriminator thinks the image
# belongs to.
fake = Dense(1, activation='sigmoid', name='generation')(features)
aux = Dense(10, activation='softmax', name='auxiliary')(features)

return Model(input=image, output=[fake, aux])`

I use the default learning rate for both generator and discriminator, but after several Epoch, ` component | loss | generation_loss | auxiliary_loss

generator (train) | 0.00 | 0.00 | 0.00 generator (test) | 3.09 | 3.09 | 0.00 discriminator (train) | 0.59 | 0.00 | 0.59 discriminator (test) | 0.63 | 0.04 | 0.59 ` generator(test) loss will become bigger and bigger(Does it mean overfitting?) while other loss stay stabilize ,and the picture it generate just like trash. 👎 Any advices will be appreciated!! 👍

King-Of-Knights commented 7 years ago

I solve it by using some tricks! Thanks anyway!

pribadihcr commented 6 years ago

@King-Of-Knights,

Can you share, whats the tricks.

King-Of-Knights commented 6 years ago

Yes , It comes mainly from Soumith Chintala ganhacks,Since I don't know how to share the modified code. I can send you the email if you want to see the code @pribadihcr

pribadihcr commented 6 years ago

@King-Of-Knights,

Yes please.

King-Of-Knights commented 6 years ago

OK I have sent it to you, I have put my train weight in the file, so you can just start at the epoch 958(thought it display epoch 0, but it reload epoch 958 training weight) @pribadihcr

pribadihcr commented 6 years ago

Thanks

King-Of-Knights commented 6 years ago

see Pull Request

King-Of-Knights commented 6 years ago

@pribadihcr please see here for the code update, there are some mistakes in that code!