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 ...
Get TensorFlow 2 Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.