What's New in TensorFlow 2.0

Book description

Get to grips with key structural changes in TensorFlow 2.0

Key Features

  • Explore TF Keras APIs and strategies to run GPUs, TPUs, and compatible APIs across the TensorFlow ecosystem
  • Learn and implement best practices for building data ingestion pipelines using TF 2.0 APIs
  • Migrate your existing code from TensorFlow 1.x to TensorFlow 2.0 seamlessly

Book Description

TensorFlow is an end-to-end machine learning platform for experts as well as beginners, and its new version, TensorFlow 2.0 (TF 2.0), improves its simplicity and ease of use. This book will help you understand and utilize the latest TensorFlow features.

What's New in TensorFlow 2.0 starts by focusing on advanced concepts such as the new TensorFlow Keras APIs, eager execution, and efficient distribution strategies that help you to run your machine learning models on multiple GPUs and TPUs. The book then takes you through the process of building data ingestion and training pipelines, and it provides recommendations and best practices for feeding data to models created using the new tf.keras API. You'll explore the process of building an inference pipeline using TF Serving and other multi-platform deployments before moving on to explore the newly released AIY, which is essentially do-it-yourself AI. This book delves into the core APIs to help you build unified convolutional and recurrent layers and use TensorBoard to visualize deep learning models using what-if analysis.

By the end of the book, you'll have learned about compatibility between TF 2.0 and TF 1.x and be able to migrate to TF 2.0 smoothly.

What you will learn

  • Implement tf.keras APIs in TF 2.0 to build, train, and deploy production-grade models
  • Build models with Keras integration and eager execution
  • Explore distribution strategies to run models on GPUs and TPUs
  • Perform what-if analysis with TensorBoard across a variety of models
  • Discover Vision Kit, Voice Kit, and the Edge TPU for model deployments
  • Build complex input data pipelines for ingesting large training datasets

Who this book is for

If you're a data scientist, machine learning practitioner, deep learning researcher, or AI enthusiast who wants to migrate code to TensorFlow 2.0 and explore the latest features of TensorFlow 2.0, this book is for you. Prior experience with TensorFlow and Python programming is necessary to understand the concepts covered in the book.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. What's New in TensorFlow 2.0
  3. Contributors
    1. About the authors
    2. About the reviewers
    3. Packt is searching for authors like you
  4. About Packt
    1. Why subscribe?
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Section 1: TensorFlow 2.0 - Architecture and API Changes
  7. Getting Started with TensorFlow 2.0
    1. Technical requirements
    2. What's new?
      1. Changes from TF 1.x
    3. TF 2.0 installation and setup
      1. Installing and using pip
      2. Using Docker
      3. GPU installation
        1. Installing using Docker
        2. Installing using pip
    4. Using TF 2.0
    5. Rich extensions
      1. Ragged Tensors
        1. What are Ragged Tensors, really?
        2. Constructing a Ragged Tensor
        3. Basic operations on Ragged Tensors
      2. New and important packages
    6. Summary
  8. Keras Default Integration and Eager Execution
    1. Technical requirements
    2. New abstractions in TF 2.0
    3. Diving deep into the Keras API
      1. What is Keras?
      2. Building models
        1. The Keras layers API
        2. Simple model building using the Sequential API
        3. Advanced model building using the functional API
      3. Training models
      4. Saving and loading models
        1. Loading and saving architecture and weights separately
          1. Loading and saving architectures
          2. Loading and saving weights
        2. Saving and loading entire models
          1. Using Keras
          2. Using the SavedModel API
      5. Other features
        1. The keras.applications module
        2. The keras.datasets module
      6. An end-to-end Sequential example
    4. Estimators
    5. Evaluating TensorFlow graphs
      1. Lazy loading versus eager execution
    6. Summary
  9. Section 2: TensorFlow 2.0 - Data and Model Training Pipelines
  10. Designing and Constructing Input Data Pipelines
    1. Technical requirements
    2. Designing and constructing the data pipeline
      1. Raw data
      2. Splitting data into train, validation, and test data
      3. Creating TFRecords
        1. TensorFlow protocol messages – tf.Example
      4. tf.data dataset object creation
        1. Creating dataset objects
        2. Creating datasets using TFRecords
        3. Creating datasets using in-memory objects and tensors
        4. Creating datasets using other formats directly without using TFRecords
    3. Transforming datasets
      1. The map function
      2. The flat_map function
      3. The zip function
      4. The concatenate function
      5. The interleave function
      6. The take(count) function
      7. The filter(predicate) function
      8. Shuffling and repeating the use of tf.data.Dataset
      9. Batching
      10. Prefetching
      11. Validating your data pipeline output before feeding it to the model
    4. Feeding the created dataset to the model
    5. Examples of complete end-to-end data pipelines
      1. Creating tfrecords using pickle files
    6. Best practices and the performance optimization of a data pipeline in TF 2.0
    7. Built-in datasets in TF 2.0
    8. Summary
    9. Further reading
  11. Model Training and Use of TensorBoard
    1. Technical requirements
    2. Comparing Keras and tf.keras
      1. Comparing estimator and tf.keras
      2. A quick review of machine learning taxonomy and TF support
    3. Creating models using tf.keras 2.0
      1. Sequential APIs
      2. Functional APIs
      3. Model subclassing APIs
    4. Model compilation and training
      1. The compile() API
      2. The fit() API
      3. Saving and restoring a model
        1. Saving checkpoints as the training progresses
        2. Manually saving and restoring weights
        3. Saving and restoring an entire model
    5. Custom training logic
    6. Distributed training
    7. TensorBoard
      1. Hooking up TensorBoard with callbacks and invocation
      2. Visualization of scalar, metrics, tensors, and image data
      3. Graph dashboard
      4. Hyperparameter tuning
      5. What-If Tool
      6. Profiling tool
    8. Summary
    9. Questions
    10. Further reading
  12. Section 3: TensorFlow 2.0 - Model Inference and Deployment and AIY
  13. Model Inference Pipelines - Multi-platform Deployments
    1. Technical requirements
    2. Machine learning workflow – the inference phase
      1. Understanding a model from an inference perspective
    3. Model artifact – the SavedModel format
      1. Understanding the core dataflow model
      2. The tf.function API
        1. The tf.autograph function
      3. Exporting your own SavedModel model
        1. Using the tf.function API
      4. Analyzing SavedModel artifacts
        1. The SavedModel command-line interface
    4. Inference on backend servers
      1. TensorFlow Serving
        1. Setting up TensorFlow Serving
        2. Setting up and running an inference server
      2. When TensorFlow.js meets Node.js
    5. Inference in the browser
    6. Inference on mobile and IoT devices
    7. Summary
  14. AIY Projects and TensorFlow Lite
    1. Introduction to TFLite
    2. Getting started with TFLite
    3. Running TFLite on mobile devices
      1. TFLite on Android
      2. TFLite on iOS
    4. Running TFLite on low-power machines
      1. Running TFLite on an Edge TPU processor
      2. Running TF on the NVIDIA Jetson Nano
    5. Comparing TFLite and TF
    6. AIY
      1. The Voice Kit
      2. The Vision Kit
    7. Summary
  15. Section 4: TensorFlow 2.0 - Migration, Summary
  16. Migrating From TensorFlow 1.x to 2.0
    1. Major changes in TF 2.0
    2. Recommended techniques to employ for idiomatic TF 2.0
    3. Making code TF 2.0-native
      1. Converting TF 1.x models
      2. Upgrading training loops
      3. Other things to note when converting
    4. Frequently asked questions
    5. The future of TF 2.0
      1. More resources to look at
    6. Summary
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: What's New in TensorFlow 2.0
  • Author(s): Ajay Baranwal, Alizishaan Khatri, Tanish Baranwal
  • Release date: August 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781838823856