LoslegenKostenlos loslegen

The sequential model in Keras

In chapter 3, we used components of the keras API in tensorflow to define a neural network, but we stopped short of using its full capabilities to streamline model definition and training. In this exercise, you will use the keras sequential model API to define a neural network that can be used to classify images of sign language letters. You will also use the .summary() method to print the model's architecture, including the shape and number of parameters associated with each layer.

Note that the images were reshaped from (28, 28) to (784,), so that they could be used as inputs to a dense layer. Additionally, note that keras has been imported from tensorflow for you.

Diese Übung ist Teil des Kurses

Introduction to TensorFlow in Python

Kurs anzeigen

Anleitung zur Übung

  • Define a keras sequential model named model.
  • Set the first layer to be Dense() and to have 16 nodes and a relu activation.
  • Define the second layer to be Dense() and to have 8 nodes and a relu activation.
  • Set the output layer to have 4 nodes and use a softmax activation function.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Define a Keras sequential model
____

# Define the first dense layer
model.add(keras.layers.____(____, activation='____', input_shape=(784,)))

# Define the second dense layer
____

# Define the output layer
model.add(keras.layers.Dense(____))

# Print the model architecture
print(model.summary())
Code bearbeiten und ausführen