I'm doing a beginner's TensorFlow course, we are given a mini-project about predicting the MNIST data set (hand written digits) and we have to finish the code such that we get a 99% accuracy (measured as 0.01 loss) in less than 10 epochs. In principle I am getting the accuracy, but the loss only reaches <0.01 at the 10th epoch (hence assignment is counted as failed). As per instructions, I'm not allowed to change the model.compile arguments, so I decided I can try to change the activation function to a leaky relu, using the code I was given. It is not as straightforward as it seems and everything I found online does not seem to work. Most suggestions are in the model.add() format, which I can't figure out how to incorporate/substitute in the code they provided us, without changing it too much (everything failed). The current code is given below:

model = tf.keras.models.Sequential([ keras.layers.Flatten(input_shape=(28,28)), keras.layers.Dense(128,activation=tf.nn.relu), keras.layers.Dense(10,activation=tf.nn.softmax) ])

Any help would be appreciated!

  • $\begingroup$ Change activation to tf.nn.leaky_relu(alpha=<value to set>) $\endgroup$ May 13, 2020 at 1:33

1 Answer 1


Try this, and tune alpha.

model = tf.keras.models.Sequential([ 
  • $\begingroup$ This worked, thank you loads! $\endgroup$
    – ISquared
    May 13, 2020 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.