LoslegenKostenlos loslegen

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!

Diese Übung ist Teil des Kurses

Introduction to Deep Learning with Keras

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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'))
Code bearbeiten und ausführen