jacobgil / keras-dcgan

Keras implementation of Deep Convolutional Generative Adversarial Networks
973 stars 412 forks source link

Why do you change d.trainable twice after d.compile during train? #19

Open haozhi1817 opened 7 years ago

haozhi1817 commented 7 years ago

It seems you can only change one model's trainable before model.compile, if you compile one model, your change of trainable will not work. So, why do you change model.trainable twice during train : x= np.concatenate((image_batch, generated_images)) y = [1] BATCH_SIZE + [0] BATCH_SIZE d_loss = d.train_on_batch(X, y) print("batch %d d_loss : %f" % (index, d_loss)) noise = np.random.uniform(-1, 1, (BATCH_SIZE, 100)) d.trainable = False #'here' g_loss = d_on_g.train_on_batch(noise, [1] * BATCH_SIZE) d.trainable = True #'here' print("batch %d g_loss : %f" % (index, g_loss))

germunwang commented 7 years ago

I found the same problem, there're some unnecessary line to change trainable, and it seems that you should recompile once you set trainable as True or False to freeze layers.

example: https://keras.io/applications/