O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering TensorFlow 1.x

Book Description

Build, scale, and deploy deep neural network models using the star libraries in Python

About This Book

  • Delve into advanced machine learning and deep learning use cases using Tensorflow and Keras
  • Build, deploy, and scale end-to-end deep neural network models in a production environment
  • Learn to deploy TensorFlow on mobile, and distributed TensorFlow on GPU, Clusters, and Kubernetes

Who This Book Is For

This book is for data scientists, machine learning engineers, artificial intelligence engineers, and for all TensorFlow users who wish to upgrade their TensorFlow knowledge and work on various machine learning and deep learning problems. If you are looking for an easy-to-follow guide that underlines the intricacies and complex use cases of machine learning, you will find this book extremely useful. Some basic understanding of TensorFlow is required to get the most out of the book.

What You Will Learn

  • Master advanced concepts of deep learning such as transfer learning, reinforcement learning, generative models and more, using TensorFlow and Keras
  • Perform supervised (classification and regression) and unsupervised (clustering) learning to solve machine learning tasks
  • Build end-to-end deep learning (CNN, RNN, and Autoencoders) models with TensorFlow
  • Scale and deploy production models with distributed and high-performance computing on GPU and clusters
  • Build TensorFlow models to work with multilayer perceptrons using Keras, TFLearn, and R
  • Learn the functionalities of smart apps by building and deploying TensorFlow models on iOS and Android devices
  • Supercharge TensorFlow with distributed training and deployment on Kubernetes and TensorFlow Clusters

In Detail

TensorFlow is the most popular numerical computation library built from the ground up for distributed, cloud, and mobile environments. TensorFlow represents the data as tensors and the computation as graphs.

This book is a comprehensive guide that lets you explore the advanced features of TensorFlow 1.x. Gain insight into TensorFlow Core, Keras, TF Estimators, TFLearn, TF Slim, Pretty Tensor, and Sonnet. Leverage the power of TensorFlow and Keras to build deep learning models, using concepts such as transfer learning, generative adversarial networks, and deep reinforcement learning. Throughout the book, you will obtain hands-on experience with varied datasets, such as MNIST, CIFAR-10, PTB, text8, and COCO-Images.

You will learn the advanced features of TensorFlow1.x, such as distributed TensorFlow with TF Clusters, deploy production models with TensorFlow Serving, and build and deploy TensorFlow models for mobile and embedded devices on Android and iOS platforms. You will see how to call TensorFlow and Keras API within the R statistical software, and learn the required techniques for debugging when the TensorFlow API-based code does not work as expected.

The book helps you obtain in-depth knowledge of TensorFlow, making you the go-to person for solving artificial intelligence problems. By the end of this guide, you will have mastered the offerings of TensorFlow and Keras, and gained the skills you need to build smarter, faster, and efficient machine learning and deep learning systems.

Style and approach

Step-by-step comprehensive guide filled with advanced, real-world examples to help you master Tensorflow 1.x

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. 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. Conventions used
    4. Get in touch
      1. Reviews
  2. TensorFlow 101
    1. What is TensorFlow?
    2. TensorFlow core
      1. Code warm-up - Hello TensorFlow
      2. Tensors
      3. Constants
      4. Operations
      5. Placeholders
      6. Creating tensors from Python objects
      7. Variables
      8. Tensors generated from library functions
        1. Populating tensor elements with the same values
        2. Populating tensor elements with sequences
        3. Populating tensor elements with a random distribution
      9. Getting Variables with tf.get_variable()
    3. Data flow graph or computation graph
      1. Order of execution and lazy loading
      2. Executing graphs across compute devices - CPU and GPGPU
        1. Placing graph nodes on specific compute devices
        2. Simple placement
        3. Dynamic placement
        4. Soft placement
        5. GPU memory handling
      3. Multiple graphs
    4. TensorBoard
      1. A TensorBoard minimal example
      2. TensorBoard details
    5. Summary
  3. High-Level Libraries for TensorFlow
    1. TF Estimator - previously TF Learn
    2. TF Slim
    3. TFLearn
      1. Creating the TFLearn Layers
        1. TFLearn core layers
        2. TFLearn convolutional layers
        3. TFLearn recurrent layers
        4. TFLearn normalization layers
        5. TFLearn embedding layers
        6. TFLearn merge layers
        7. TFLearn estimator layers
      2. Creating the TFLearn Model
        1. Types of TFLearn models
      3. Training the TFLearn Model
      4. Using the TFLearn Model
    4. PrettyTensor
    5. Sonnet
    6. Summary
  4. Keras 101
    1. Installing Keras
    2. Neural Network Models in Keras
      1. Workflow for building models in Keras
    3. Creating the Keras model
      1. Sequential API for creating the Keras model
      2. Functional API for creating the Keras model
    4. Keras Layers
      1. Keras core layers
      2. Keras convolutional layers
      3. Keras pooling layers
      4. Keras locally-connected layers
      5. Keras recurrent layers
      6. Keras embedding layers
      7. Keras merge layers
      8. Keras advanced activation layers
      9. Keras normalization layers
      10. Keras noise layers
    5. Adding Layers to the Keras Model
      1. Sequential API to add layers to the Keras model
      2. Functional API to add layers to the Keras Model
    6. Compiling the Keras model
    7. Training the Keras model
    8. Predicting with the Keras model
    9. Additional modules in Keras
    10. Keras sequential model example for MNIST dataset
    11. Summary
  5. Classical Machine Learning with TensorFlow
    1. Simple linear regression
      1. Data preparation
      2. Building a simple regression model
        1. Defining the inputs, parameters, and other variables
        2. Defining the model
        3. Defining the loss function
        4. Defining the optimizer function
        5. Training the model
      3. Using the trained model to predict
    2. Multi-regression
    3. Regularized regression
      1. Lasso regularization
      2. Ridge regularization
      3. ElasticNet regularization
    4. Classification using logistic regression
      1. Logistic regression for binary classification
      2. Logistic regression for multiclass classification
    5. Binary classification
    6. Multiclass classification
    7. Summary
  6. Neural Networks and MLP with TensorFlow and Keras
    1. The perceptron
    2. MultiLayer Perceptron
    3. MLP for image classification
      1. TensorFlow-based MLP for MNIST classification
      2. Keras-based MLP for MNIST classification
      3. TFLearn-based MLP for MNIST classification
      4. Summary of MLP with TensorFlow, Keras, and TFLearn
    4. MLP for time series regression
    5. Summary
  7. RNN with TensorFlow and Keras
    1. Simple Recurrent Neural Network
    2. RNN variants
    3. LSTM network
    4. GRU network
    5. TensorFlow for RNN
      1. TensorFlow RNN Cell Classes
      2. TensorFlow RNN Model Construction Classes
      3. TensorFlow RNN Cell Wrapper Classes
    6. Keras for RNN
    7. Application areas of RNNs
    8. RNN in Keras for MNIST data
    9. Summary
  8. RNN for Time Series Data with TensorFlow and Keras
    1. Airline Passengers dataset
      1. Loading the airpass dataset
      2. Visualizing the airpass dataset
    2. Preprocessing the dataset for RNN models with TensorFlow
    3. Simple RNN in TensorFlow
    4. LSTM in TensorFlow
    5. GRU in TensorFlow
    6. Preprocessing the dataset for RNN models with Keras
    7. Simple RNN with Keras
    8. LSTM with Keras
    9. GRU with Keras
    10. Summary
  9. RNN for Text Data with TensorFlow and Keras
    1. Word vector representations
    2. Preparing the data for word2vec models
      1. Loading and preparing the PTB dataset
      2. Loading and preparing the text8 dataset
      3. Preparing the small validation set
    3. skip-gram model with TensorFlow
    4. Visualize the word embeddings using t-SNE
    5. skip-gram model with Keras
    6. Text generation with RNN models in TensorFlow and Keras
      1. Text generation LSTM in TensorFlow
      2. Text generation LSTM in Keras
    7. Summary
  10. CNN with TensorFlow and Keras
    1. Understanding convolution
    2. Understanding pooling
    3. CNN architecture pattern - LeNet
    4. LeNet for MNIST data
      1. LeNet CNN for MNIST with TensorFlow
      2. LeNet CNN for MNIST with Keras
    5. LeNet for CIFAR10 Data
      1. ConvNets for CIFAR10 with TensorFlow
      2. ConvNets for CIFAR10 with Keras
    6. Summary
  11. Autoencoder with TensorFlow and Keras
    1. Autoencoder types
    2. Stacked autoencoder in TensorFlow
    3. Stacked autoencoder in Keras
    4. Denoising autoencoder in TensorFlow
    5. Denoising autoencoder in Keras
    6. Variational autoencoder in TensorFlow
    7. Variational autoencoder in Keras
    8. Summary
  12. TensorFlow Models in Production with TF Serving
    1. Saving and Restoring models in TensorFlow
      1. Saving and restoring all graph variables with the saver class
      2. Saving and restoring selected  variables with the saver class
    2. Saving and restoring Keras models
    3. TensorFlow Serving
      1. Installing TF Serving
      2. Saving models for TF Serving
      3. Serving models with TF Serving
    4. TF Serving in the Docker containers
      1. Installing Docker
      2. Building a Docker image for TF serving
      3. Serving the model in the Docker container
    5. TensorFlow Serving on Kubernetes
      1. Installing Kubernetes
      2. Uploading the Docker image to the dockerhub
      3. Deploying in Kubernetes
    6. Summary
  13. Transfer Learning and Pre-Trained Models
    1. ImageNet dataset
    2. Retraining or fine-tuning models
    3. COCO animals dataset and pre-processing images
    4. VGG16 in TensorFlow
      1. Image classification using pre-trained VGG16 in TensorFlow
    5. Image preprocessing in TensorFlow for pre-trained VGG16
      1. Image classification using retrained  VGG16 in TensorFlow
    6. VGG16 in Keras
      1. Image classification using pre-trained VGG16 in Keras
      2. Image classification using retrained VGG16 in Keras
    7. Inception v3 in TensorFlow
      1. Image classification using Inception v3 in TensorFlow
      2. Image classification using retrained Inception v3 in TensorFlow
    8. Summary
  14. Deep Reinforcement Learning
    1. OpenAI Gym 101
    2. Applying simple policies to a cartpole game
    3. Reinforcement learning 101
      1. Q function (learning to optimize when the model is not available)
      2. Exploration and exploitation in the RL algorithms
      3. V function (learning to optimize when the model is available)
      4. Reinforcement learning techniques
    4. Naive Neural Network policy for Reinforcement Learning
    5. Implementing Q-Learning
      1. Initializing and discretizing for Q-Learning
      2. Q-Learning with Q-Table
      3. Q-Learning with Q-Network  or Deep Q Network (DQN) 
    6. Summary
  15. Generative Adversarial Networks
    1. Generative Adversarial Networks 101
    2. Best practices for building and training GANs
    3. Simple GAN with TensorFlow
    4. Simple GAN with Keras
    5. Deep Convolutional GAN with TensorFlow and Keras
    6. Summary
  16. Distributed Models with TensorFlow Clusters
    1. Strategies for distributed execution
    2. TensorFlow clusters
      1. Defining cluster specification
      2. Create the server instances
      3. Define the parameter and operations across servers and devices
      4. Define and train the graph for asynchronous updates
      5. Define and train the graph for synchronous updates
    3. Summary
  17. TensorFlow Models on Mobile and Embedded Platforms
    1. TensorFlow on mobile platforms
    2. TF Mobile in Android apps
    3. TF Mobile demo on Android
    4. TF Mobile in iOS apps
    5. TF Mobile demo on iOS
    6. TensorFlow Lite
    7. TF Lite Demo on Android
    8. TF Lite demo on iOS
    9. Summary
  18. TensorFlow and Keras in R
    1. Installing TensorFlow and Keras packages in R
    2. TF core API in R
    3. TF estimator API in R
    4. Keras API in R
    5. TensorBoard in R
    6. The tfruns package in R
    7. Summary
  19. Debugging TensorFlow Models
    1. Fetching tensor values with tf.Session.run()
    2. Printing tensor values with tf.Print()
    3. Asserting on conditions with tf.Assert()
    4. Debugging with the TensorFlow debugger (tfdbg)
    5. Summary
  20. Tensor Processing Units
  21. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think