Keras - LeakyReLU has no attribute name error when saving model

Edited part( Thanks @NagabhushanSN for mentioning the remaining issue)

There is a line of the code where we still have discriminator_model.add(Conv2D(64, 5, strides=2, input_shape=(28, 28, 1), padding='same', activation=LeakyReLU(alpha=0.2))) , it is the second line of the code.

If we modify that line, the final corrected code should be like this:

discriminator_model = Sequential()
discriminator_model.add(Conv2D(64, 5, strides=2, input_shape=(28, 28, 1), padding='same'))
discriminator_model.add(LeakyReLU(alpha=0.2))
discriminator_model.add(Dropout(0.4))
discriminator_model.add(Conv2D(128, 5, strides=2, padding='same'))
discriminator_model.add(LeakyReLU(alpha=0.2))
discriminator_model.add(Dropout(0.4))
discriminator_model.add(Conv2D(256, 5, strides=2, padding='same'))
discriminator_model.add(LeakyReLU(alpha=0.2))
discriminator_model.add(Dropout(0.4))
discriminator_model.add(Conv2D(512, 5, strides=2, padding='same'))
discriminator_model.add(LeakyReLU(alpha=0.2))
discriminator_model.add(Dropout(0.4))
discriminator_model.add(Flatten())
discriminator_model.add(Dense(1))
discriminator_model.add(Activation('sigmoid'))
discriminator_model.summary()

And this one should work well on the most recent version of tensroflow, I tested on 1.8.0 and it works fine. However, if check your code with older version like tesnorflow1.1.0, we get the same error.

For that case, I suggest update tensorflow to a higher version

  • To check the current tensorflow version python is using, do as here.
  • To update tensorflow, this post seems good enough to show how to do it.