Skip to Content
TensorFlow 2 Pocket Reference
book

TensorFlow 2 Pocket Reference

by KC Tung
July 2021
Intermediate to advanced
253 pages
5h 1m
English
O'Reilly Media, Inc.
Content preview from TensorFlow 2 Pocket Reference

Chapter 6. Model Creation Styles

As you may have imagined, there is more than one way to build a deep learning model. In the previous chapters, you learned about tf.keras.Sequential, known as the symbolic API, which is commonly the starting point when teaching model creation. Another style of API that you might come across is known as the imperative API. Both symbolic and imperative APIs are capable of building deep learning models.

By and large, which API you choose is a matter of style. Depending on your programming experience and background, one or the other might feel more natural for you. In this chapter, you will learn how to build the same model with both APIs. Specifically, you will learn how to build an image classification model using the CIFAR-10 image dataset. This dataset consists of 10 commonly seen classes, or categories, of images. Like the flower images we used previously, the CIFAR-10 images are available as part of the TensorFlow distribution. However, while the flower images came in JPEG format, the CIFAR-10 images are NumPy arrays. To stream them into the training process, instead of using the flow_from_directory method as you did in Chapter 5, you’ll use the from_tensor_slices method.

After establishing the data streaming process with from_tensor_slices, you’ll first use the symbolic API to build and train the image classification model, and then use the imperative API. You will see that regardless of how you build the model architecture, the results are ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The TensorFlow Workshop

The TensorFlow Workshop

Matthew Moocarme, Abhranshu Bagchi, Anthony So, Anthony Maddalone

Publisher Resources

ISBN: 9781492089179Errata PageSupplemental Content