The Sequential API

The most common type of model is a stack of layers. The tf.keras.Sequential model allows you to define a Keras model by stacking tf.keras.layers.

The CNN that we defined in Chapter 3, TensorFlow Graph Architecture, can be recreated using a Keras sequential model in fewer lines and in an elegant way. Since we are training a classifier, we can use the Keras model's compile and fit methods to build the training loop and execute it, respectively. At the end of the training loop, we can also evaluate the performance of the model on the test set using the evaluate method—Keras will take care of all the boilerplate code:


import tensorflow as tffrom tensorflow.keras.datasets import fashion_mnistn_classes = 10model = tf.keras.Sequential([ ...

Get Hands-On Neural Networks with TensorFlow 2.0 now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.