Build a neural network
We will use the Keras
library to create neural networks and to train these neural networks to classify images. These models will all be of the Sequential
type, meaning that the outputs of one layer are provided as inputs only to the next layer.
In this exercise, you will create a neural network with Dense
layers, meaning that each unit in each layer is connected to all of the units in the previous layer. For example, each unit in the first layer is connected to all of the pixels in the input images. The Dense
layer object receives as arguments the number of units in that layer, and the activation function for the units. For the first layer in the network, it also receives an input_shape
keyword argument.
This course touches on a lot of concepts you may have forgotten, so if you ever need a quick refresher, download the Keras Cheat Sheet and keep it handy!
This exercise is part of the course
Image Modeling with Keras
Exercise instructions
- The first layer receives images as input, has 10 units and
'relu'
activation. - The second input layer has 10 units and
'relu'
activation. - The output layer has one unit for each category (3 categories) and
'softmax'
activation.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Imports components from Keras
from keras.models import Sequential
from keras.layers import Dense
# Initializes a sequential model
model = Sequential()
# First layer
model.add(____(10, activation=____, input_shape=(784,)))
# Second layer
model.add(____(____, activation=____))
# Output layer
____