MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Introduction to TensorFlow in Python

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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())
Edit dan Jalankan Kode