Get startedGet started for free

Batch normalizing a familiar model

Remember the digits dataset you trained in the first exercise of this chapter?

A multi-class classification problem that you solved using softmax and 10 neurons in your output layer.

You will now build a new deeper model consisting of 3 hidden layers of 50 neurons each, using batch normalization in between layers. The kernel_initializer parameter is used to initialize weights in a similar way.

This exercise is part of the course

Introduction to Deep Learning with Keras

View Course

Exercise instructions

  • Import BatchNormalization from tensorflow.keras layers.
  • Build your deep network model, use 50 neurons for each hidden layer adding batch normalization in between layers.
  • Compile your model with stochastic gradient descent, sgd, as an optimizer.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import batch normalization from keras layers
from tensorflow.____.____ import ____

# Build your deep network
batchnorm_model = ____
batchnorm_model.add(Dense(____, input_shape=(64,), activation='relu', kernel_initializer='normal'))
batchnorm_model.add(____)
batchnorm_model.add(Dense(____, activation='relu', kernel_initializer='normal'))
batchnorm_model.add(____)
batchnorm_model.add(Dense(____, activation='relu', kernel_initializer='normal'))
batchnorm_model.add(____)
batchnorm_model.add(Dense(10, activation='softmax', kernel_initializer='normal'))

# Compile your model with sgd
batchnorm_model.compile(optimizer=____, loss='categorical_crossentropy', metrics=['accuracy'])
Edit and Run Code