3 Keras and data retrieval in TensorFlow 2

 

This chapter covers

  • Different APIs for building models in Keras
  • Retrieving and manipulating persisted data

We have explored the details of the low-level TensorFlow API, such as defining tf.Variable objects and tf.Tensor objects, which can be used to store things like numbers and strings. We also looked at some of the commonly used functionality provided in TensorFlow in the form of tf.Operation. Finally, we looked at some complex operations, such as matrix multiplication and convolution, in detail. If you analyze any standard deep neural network, you will see that it is made from standard mathematical operations such as matrix multiplication and convolution.

However, if you were to implement these networks using the low-level TensorFlow API, you’d find yourself replicating these operations in code many times, costing you valuable hours and making the code unmaintainable. But the good news is that you don’t have to. TensorFlow provides a submodule called Keras that takes care of this problem, and this is the focus of this chapter. Keras is a sub-library in TensorFlow that hides building blocks and provides a high-level API for developing machine learning models. In this chapter, we will see that Keras has several different APIs to choose from, depending on the complexity of your solution.

3.1 Keras model-building APIs

3.1.1 Introducing the data set

3.1.2 The Sequential API

3.1.3 The functional API

3.1.4 The sub-classing API

3.2 Retrieving data for TensorFlow/Keras models

3.2.1 tf.data API

3.2.2 Keras DataGenerators

3.2.3 tensorflow-datasets package

Summary

Answers to exercises