Get startedGet started for free

Building a CNN model

Building a CNN model in Keras isn't much more difficult than building any of the models you've already built throughout the course! You just need to make use of convolutional layers.

You're going to build a shallow convolutional model that classifies the MNIST digits dataset. The same one you de-noised with your autoencoder! The images are 28 x 28 pixels and just have one channel, since they are black and white pictures.

Go ahead and build this small convolutional model!

This exercise is part of the course

Introduction to Deep Learning with Keras

View Course

Exercise instructions

  • Import the Conv2D and Flatten layers and instantiate your model.
  • Add a first convolutional layer with 32 filters of size 3x3 and the corresponding 3D tuple as input_shape.
  • Add a second convolutional layer with 16 filters of size 3x3 with relu activation.
  • Flatten the previous layer output to create a one-dimensional vector.

Hands-on interactive exercise

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

# Import the Conv2D and Flatten layers and instantiate model
from tensorflow.keras.____ import ____,____
model = ____

# Add a convolutional layer of 32 filters of size 3x3
model.add(Conv2D(____, kernel_size = ____, input_shape = (____, ____, 1), activation = 'relu'))

# Add a convolutional layer of 16 filters of size 3x3
model.add(____(____, ____ = ____, activation = ____))

# Flatten the previous layer output
model.add(____)

# Add as many outputs as classes with softmax activation
model.add(Dense(10, activation = 'softmax'))
Edit and Run Code