What are optimization in keras models?
Whenever a neural network finishes processing a batch through the ANN model and generates prediction results, it calculates the difference between the true value and predicted value and then decide how to use the difference between them, then adjust the weights on the nodes so that the network steps towards the required solution. The algorithm that determines that step is known as the optimization algorithm.
There are many types of optimizers like SGD, SGD with [Nesterov] momentum, Adagrad, Adadelta, RMSprop, Adam, AdaMax, Nadam, AMSgrad We will take the example of the ADAM optimizer as it is more common.
from tensorflow import keras from tensorflow.keras import layers
We will define the layers, kernel initializer, and its input nodes shape.
model = keras.Sequential() model.add(layers.Dense(64, kernel_initializer='uniform', input_shape=(10,)))
We will define Relu as the activation function.
we will use Adam optimizer with the learning rate = 0.001 and loss function as 'categorical_crossentropy'.
optimizer = keras.optimizers.Adam(learning_rate=0.001) model.compile(loss='categorical_crossentropy', optimizer=optimizer)