Reputation: 1217
I have two Keras networks. Let's say for the sake of explanation that my model is similar to GAN. So, we have a Discriminator(D) and a Generator(G).
Obviously, in order to train the (G), the (D) layers should be frozen.
If, I freeze them using D.trainable = False
then should I invert this parameter when to train the (D)?
What is the scope of model.trainable
in Keras?
I have seen codes that only change this argument status once:
https://github.com/nairouz/Keras-GAN/blob/master/gan/gan.py
How is it possible to do so? Any explanation?
Upvotes: 1
Views: 178
Reputation: 11895
From How can I "freeze" Keras layers?:
Additionally, you can set the trainable property of a layer to
True
orFalse
after instantiation. For this to take effect, you will need to callcompile()
on your model after modifying the trainable property.
And the same applies to models. This means that when you set D.trainable = False
, this doesn't take effect until you compile D
(or any other model leveraging D
), so it doesn't affect models that you have previously compiled.
Upvotes: 1