7 Working with Keras: A deep dive

 

This chapter covers:

  • Creating Keras models with keras_model_ sequential(), the Functional API, and model subclassing
  • Using built-in Keras training and evaluation loops
  • Using Keras callbacks to customize training
  • Using TensorBoard to monitor training and evaluation metrics
  • Writing training and evaluation loops from scratch

You’ve now got some experience with Keras—you’re familiar with the Sequential model, dense layers, and built-in APIs for training, evaluation, and inference— compile(), fit(), evaluate(), and predict(). You even learned in chapter 3 how to use new_layer_class() to create custom layers, and how to use the TensorFlow GradientTape() to implement a step-by-step training loop.

In the coming chapters, we’ll dig into computer vision, time-series forecasting, natural language processing, and generative deep learning. These complex applications will require much more than a keras_model_sequential() architecture and the default fit() loop. So, let’s first turn you into a Keras expert! In this chapter, you’ll get a complete overview of the key ways to work with Keras APIs: everything you’re going to need to handle the advanced deep learning use cases you’ll encounter next.

7.1 A spectrum of workflows

7.2 Different ways to build Keras models

7.2.1 The Sequential model

7.2.2 The Functional API

7.2.3 Subclassing the Model class

7.2.4 Mixing and matching different components

7.2.5 Remember: Use the right tool for the job

7.3 Using built-in training and evaluation loops

7.3.1 Writing your own metrics

7.3.2 Using callbacks

7.3.3 Writing your own callbacks

7.3.4 Monitoring and visualization with TensorBoard

7.4 Writing your own training and evaluation loops

7.4.1 Training vs. inference

7.4.2 Low-level usage of metrics

7.4.3 A complete training and evaluation loop

7.4.4 Make it fast with tf_function()

7.4.5 Leveraging fit() with a custom training loop

Summary