Book Image

Hands-On Convolutional Neural Networks with TensorFlow

By : Iffat Zafar, Giounona Tzanidou, Richard Burton, Nimesh Patel, Leonardo Araujo
Book Image

Hands-On Convolutional Neural Networks with TensorFlow

By: Iffat Zafar, Giounona Tzanidou, Richard Burton, Nimesh Patel, Leonardo Araujo

Overview of this book

Convolutional Neural Networks (CNN) are one of the most popular architectures used in computer vision apps. This book is an introduction to CNNs through solving real-world problems in deep learning while teaching you their implementation in popular Python library - TensorFlow. By the end of the book, you will be training CNNs in no time! We start with an overview of popular machine learning and deep learning models, and then get you set up with a TensorFlow development environment. This environment is the basis for implementing and training deep learning models in later chapters. Then, you will use Convolutional Neural Networks to work on problems such as image classification, object detection, and semantic segmentation. After that, you will use transfer learning to see how these models can solve other deep learning problems. You will also get a taste of implementing generative models such as autoencoders and generative adversarial networks. Later on, you will see useful tips on machine learning best practices and troubleshooting. Finally, you will learn how to apply your models on large datasets of millions of images.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Packt Upsell


This book is all about giving a practical, hands-on introduction to machine learning with the aim of enabling anyone to start working in the field. We'll focus mainly on deep learning methods and how they can be used to solve important computer vision problems, but the knowledge acquired here can be transferred to many different domains. Along the way, the reader will also get a grip of how to use the popular deep learning library, TensorFlow.

Who this book is for

Anyone interested in a practical guide to machine learning, specifically deep learning and computer vision, will particularly benefit from reading this book. In addition, the following people will also benefit:

  • Machine learning engineers
  • Data scientists
  • Developers interested in learning about the deep learning and computer vision fields
  • Students studying machine learning

What this book covers

Chapter 1, Setup and Introduction to Tensorflow, covers the setting up and installation of TensorFlow along with writing a simple Tensorflow model for machine learning.

Chapter 2, Deep Learning and Convolutional Neural Networks, introduces you to machine learning, and artificial intelligence as well as artificial neural networks and how to train them. It also covers CNNs and how to use TensorFlow to train your own CNN.

Chapter 3, Image Classification in Tensorflow, talks about building CNN models and how to train them for classifying the CIFAR10 dataset. It also looks at ways to help improve the quality of our trained model by talking about different methods of initialization and regularization.


Chapter 4, Object Detection and Segmentation, teaches the basics of object localization, detection and segmentation and the most famous algorithms related to those topics.

Chapter 5, VGG, Inception Modules, Residuals, and MobileNets, introduces you to different convolutional neural network designs like VGGNet, GoggLeNet, and MobileNet.

Chapter 6, AutoEncoders, Variational Autoencoders, and Generative Adversarial Networks, introduces you to generative models, generative adversarial network, and different types of encoders. 

Chapter 7, Transfer Learning, covers the usage of transfer learning and implementing it in our own tasks.

Chapter 8, Machine Learning Best Practices and Troubleshooting, introduces us to preparing and splitting a dataset into subsets and performing meaningful tests. The chapter also talks about underfitting and overfitting along with the best practices for addressing them.

Chapter 9, Training at Scale, teaches you how to train TensorFlow models across multiple GPUs and machines. It also covers best practices for storing your data and feeding it to your model.

To get the most out of this book

To get the most of the book, the reader should have some knowledge of the Python programming language and how to install some required packages. All the rest will be covered by the book with an easy language approach. Installation instructions will be given in the book and in the repository.

Download the example code files

You can download the example code files for this book from your account at If you purchased this book elsewhere, you can visit and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.


Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

import tensorflow as tf 
# XOR dataset 
XOR_X = [[0, 0], [0, 1], [1, 0], [1, 1]] 
XOR_Y = [[0], [1], [1], [0]] 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

import tensorflow as tf 
# XOR dataset 
XOR_X = [[0, 0], [0, 1], [1, 0], [1, 1]] 
XOR_Y = [[0], [1], [1], [0]] 

Any command-line input or output is written as follows:

$ pip install numpy
$ pip install scipy


Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."


Warnings or important notes appear like this.


Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit




Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit