Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Machine Learning with TensorFlow 1.x
Machine Learning with TensorFlow 1.x

Machine Learning with TensorFlow 1.x: Second generation machine learning with Google's brainchild - TensorFlow 1.x

eBook
$9.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Machine Learning with TensorFlow 1.x

Getting Started with TensorFlow

The proliferation of large public datasets, inexpensive GPUs, and open-minded developer culture has revolutionized machine learning efforts in recent years. Training data, the lifeblood of machine learning, has become widely available and easily consumable in recent years. Computing power has made the required horsepower available to small businesses and even individuals. The current decade is incredibly exciting for data scientists.

Some of the top platforms used in the industry include Caffe, Theano, and Torch. While the underlying platforms are actively developed and openly shared, usage is limited largely to machine learning practitioners due to difficult installations, non-obvious configurations, and difficulty with productionizing solutions.

Late 2015 and 2016 brought additional platforms into the landscape—TensorFlow from Google, CNTK from Microsoft, and Veles from Samsung, among other options. Google's TensorFlow is the most exciting for several reasons.

TensorFlow has one of the easiest installations of any platform, bringing machine learning capabilities squarely into the realm of casual tinkerers and novice programmers. Meanwhile, high-performance features, such as—multiGPU support, make the platform exciting for experienced data scientists and industrial use as well. TensorFlow also provides a reimagined process and multiple user-friendly utilities, such as TensorBoard, to manage machine learning efforts. Finally, the platform has significant backing and community support from the world's largest machine learning powerhouse--Google. All this is before even considering the compelling underlying technical advantages, which we'll dive into later.

In this chapter, we will cover the following topics:

  • macOS X
  • Microsoft Windows and Linux, both the core software and all the dependencies
  • VM setup to enable Windows installation

Current use

Although TensorFlow has been public for just two years, numerous community efforts have already successfully ported over existing machine learning projects. Some examples include handwriting recognition, language translation, animal classification, medical image triage, and sentiment analysis. The wide applicability of machine learning to so many industries and problems always intrigues people. With TensorFlow, these problems are not only feasible but easily achievable. In fact, we will tackle and solve each of the preceding problems within the course of this book!

Installing TensorFlow

TensorFlow conveniently offers several types of installation and operates on multiple operating systems. The basic installation is CPU-only, while more advanced installations unleash serious horsepower by pushing calculations onto the graphics card, or even to multiple graphics cards. We recommend starting with a basic CPU installation at first. More complex GPU and CUDA installations will be discussed in Appendix, Advanced Installation.

Even with just a basic CPU installation, TensorFlow offers multiple options, which are as follows:

  • A basic Python pip installation
  • A segregated Python installation via Virtualenv
  • A fully segregated container-based installation via Docker

We recommend a Python installation via Virtualenv, but our examples will use a basic Python pip installation to help you focus on the crux of our task, that is, getting TensorFlow up and running. Again, more advanced installation types will be covered in Appendix, Advanced Installation.

TensorFlow can fully work on Linux and macOS with both Python 2.7 and 3.5. On Windows, we can only use TensorFlow with Python 3.5.x or 3.6.x. It can also be easily used on Windows by running a Linux virtual machine (VM). With an Ubuntu virtual machine, we can use TensorFlow with Python 2.7. However, we can't use TensorFlow with GPU support in a virtual machine. As of TensorFlow 1.2, TensorFlow doesn't provide GPU support on macOS. Therefore, if you want to use macOS with GPU-enabled TensorFlow, you will have to compile from sources, which is out of the scope of this chapter. Otherwise, you can still use TensorFlow 1.0 or 1.1, which provides GPU support out of the box on macOS. Linux and Windows users can use TensorFlow with both CPU and GPU support.

Ubuntu installation

Ubuntu is one of the best Linux distributions for working with Tensorflow. We highly recommend that you use an Ubuntu machine, especially if you want to work with GPU. We will do most of our work on the Ubuntu terminal. We will begin with installing python-pip and python-dev via the following command:

sudo apt-get install python-pip python-dev

A successful installation will appear as follows:

If you find missing packages, you can correct them via the following command:

sudo apt-get update --fix-missing

Then, you can continue the python and pip installation.

We are now ready to install TensorFlow. We will do a CPU-only installation, and if you wish to do an advanced GPU-enabled installation, we will cover that in Appendix, Advanced Installation.

The CPU installation is initiated via the following command:

sudo pip install tensorflow

A successful installation will appear as follows:

macOS installation

If you use Python, you will probably already have the Python package installer, pip. However, if not, you can easily install it using the easy_install pip command. You'll note that we actually executed sudo easy_install pip—the sudo prefix was required because the installation requires administrative rights.

We will make the fair assumption that you already have the basic package installer, easy_install, available; if not, you can install it from https://pypi.python.org/pypi/setuptools. A successful installation will appear as shown in the following screenshot:

Next, we will install the six package:

sudo easy_install --upgrade six

A successful installation will appear as shown in the following screenshot:

Surprisingly, those are the only two prerequisites for TensorFlow, and we can now install the core platform. We will use the pip package installer mentioned earlier and install TensorFlow directly from Google's site. The most recent version at the time of writing this book is v1.3, but you should change this to the latest version you wish to use:

sudo pip install tensorflow

The pip installer will automatically gather all the other required dependencies. You will see each individual download and installation until the software is fully installed.

A successful installation will appear as shown in the following screenshot:

That's it! If you were able to get to this point, you can start to train and run your first model. Skip to Chapter 2, Your First Classifier, to train your first model.

macOS X users wishing to completely segregate their installation can use a VM instead, as described in the Windows installation.

Windows installation

As we mentioned earlier, TensorFlow with Python 2.7 does not function natively on Windows. In this section, we will guide you through installing TensorFlow with Python 3.5 and set up a VM with Linux if you want to use TensorFlow with Python 2.7.

First, we need to install Python 3.5.x or 3.6.x 64-bit from the following links:

https://www.python.org/downloads/release/python-352/

https://www.python.org/downloads/release/python-362/

Make sure that you download the 64-bit version of Python where the name of the installation has amd64, such as python-3.6.2-amd64.exe. The Python 3.6.2 installation looks like this:

We will select Add Python 3.6 to PATH and click Install Now. The installation process will complete with the following screen:

We will click the Disable path length limit and then click Close to finish the Python installation. Now, let's open the Windows PowerShell application under the Windows menu. We will install the CPU-only version of Tensorflow with the following command:

pip3 install tensorflow

The result of the installation will look like this:

Congratulations, you can now use TensorFlow on Windows with Python 3.5.x or 3.6.x support. In the next section, we will show you how to set up a VM to use TensorFlow with Python 2.7. However, you can skip to the Test installation section of Chapter 2, Your First Classifier, if you don't need Python 2.7.

Now, we will show you how to set up a VM with Linux to use TensorFlow with Python 2.7. We recommend the free VirtualBox system available at https://www.virtualbox.org/wiki/Downloads. The latest stable version at the time of writing is v5.0.14, available at the following URL:

http://download.virtualbox.org/virtualbox/5.1.28/VirtualBox-5.1.28-117968-Win.exe

A successful installation will allow you to run the Oracle VM VirtualBox Manager dashboard, which looks like this:

Virtual machine setup

Linux comes in numerous flavors, but as the TensorFlow documentation mostly mentions Ubuntu, we'll be working with Ubuntu Linux. You are welcome to use any flavor of Linux, but you should be aware that there are subtle differences across flavors and versions of each flavor. Most differences are benign, but some may trip up the installation or even usage of TensorFlow.

Even after choosing Ubuntu, there are many versions and configurations; you can see some at http://cdimage.ubuntu.com/ubuntu-gnome/releases/14.04/release/.

We will install the most popular version, which is Ubuntu 14.04.4 LTS (make sure to download a version appropriate for your computer). Versions marked x86 are designed to run on 32-bit machines, while those marked with some variation of 64 are designed to run on 64-bit machines. Most modern machines are 64-bit, so if you are unsure, go with the latter.

Installations happen via an ISO file, which is, essentially, a file equivalent of an installation CD. The ISO for Ubuntu 14.04.4 LTS is ubuntu-gnome-14.04-desktop-amd64.iso.

Once you have downloaded the installation ISO, we will set up a VM and use the ISO file to install Ubuntu Linux on the VM.

Setting up the VM on Oracle VM VirtualBox Manager is relatively simple, but pay close attention as the default options are not sufficient for TensorFlow. You will go through the following seven screens, and at the end, it will prompt you for the installation file, which was just downloaded.

We will first set up the type of operating system and configure the random access memory (RAM) allocated to the VM:

  1. Note that we selected a 64-bit installation as that is the image we're using; you can choose to use a 32-bit image if you need:
  1. How much RAM you allocate depends on how much your machine has. In the following screenshot, we will allocate half our RAM(8 GB) to our VM. Remember that this is consumed only while we are running the VM, so we can be liberal with our allocations. We can allocate at least 4 GB:
  2. Our VM will need a hard disk. We'll create a Virtual Hard Disk (VHD), as shown in the following screenshot:
  3. Then, we will choose the type of hard drive for the VM, that is, VDI (VirtualBox Disk Image), as shown in the following screenshot:
  4. Next, we will choose how much space to allocate for the VHD. This is important to understand as we will soon work with extremely large datasets:
  5. We will allocate 12 GB because TensorFlow and typical TensorFlow applications have an array of dependencies, such as NumPy, SciPy, and Pandas. Our exercises will also be downloading large datasets, which are to be used for training:
  6. After setting up the VM, it will appear on the left side VM listing. Select it and click on Start. This is the equivalent of booting up the machine:
  1. As the machine boots for the first time, provide it the installation CD (in our case, the Ubuntu ISO we downloaded earlier):

Follow the installation instructions and you'll have a full Ubuntu Linux installation ready to use! After that, you can follow the Ubuntu installation at the beginning of this chapter.

Testing the installation

In this section, we will use TensorFlow to compute a simple math operation. First, open your terminal on Linux/macOS or Windows PowerShell in Windows.

Now, we need to run python to use TensorFlow with the following command:

python

Enter the following program in the Python shell:

import tensorflow as tf
a = tf.constant(1.0)
b = tf.constant(2.0)
c = a + b
sess = tf.Session()
print(sess.run(c))

The result will look like the following screen where 3.0 is printed at the end:

Summary

In this chapter, we covered TensorFlow installation on the three major operating systems, so all readers should be up and running with the platform. Windows users faced an extra challenge, as TensorFlow on Windows only supports Python 3.5.x or Python 3.6.x 64-bit version. However, even Windows users should now be up and running. Congratulations, now the fun begins!

You now have TensorFlow installed. The immediate next step is to test the installation with a sample built-in training effort. Next, we will write our first classifier from scratch—a handwriting recognizer.

In the upcoming chapters, we will review TensorFlow tools and use them on our projects. We will also review the major deep learning concepts, using each in the context of a project. You will have a chance to try projects in multiple industries, ranging from finance to medicine to language.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Enter the new era of second-generation machine learning with Python with this practical and insightful guide
  • Set up TensorFlow 1.x for actual industrial use, including high-performance setup aspects such as multi-GPU support
  • Create pipelines for training and using applying classifiers using raw real-world data

Description

Google's TensorFlow is a game changer in the world of machine learning. It has made machine learning faster, simpler, and more accessible than ever before. This book will teach you how to easily get started with machine learning using the power of Python and TensorFlow 1.x. Firstly, you’ll cover the basic installation procedure and explore the capabilities of TensorFlow 1.x. This is followed by training and running the first classifier, and coverage of the unique features of the library including data ?ow graphs, training, and the visualization of performance with TensorBoard—all within an example-rich context using problems from multiple industries. You’ll be able to further explore text and image analysis, and be introduced to CNN models and their setup in TensorFlow 1.x. Next, you’ll implement a complete real-life production system from training to serving a deep learning model. As you advance you’ll learn about Amazon Web Services (AWS) and create a deep neural network to solve a video action recognition problem. Lastly, you’ll convert the Caffe model to TensorFlow and be introduced to the high-level TensorFlow library, TensorFlow-Slim. By the end of this book, you will be geared up to take on any challenges of implementing TensorFlow 1.x in your machine learning environment.

Who is this book for?

This book is for data scientists and researchers who are looking to either migrate from an existing machine learning library or jump into a machine learning platform headfirst. The book is also for software developers who wish to learn deep learning by example. Particular focus is placed on solving commercial deep learning problems from several industries using TensorFlow’s unique features. No commercial domain knowledge is required, but familiarity with Python and matrix math is expected.

What you will learn

  • Explore how to use different machine learning models to ask different questions of your data
  • Learn how to build deep neural networks using TensorFlow 1.x
  • Cover key tasks such as clustering, sentiment analysis, and regression analysis using TensorFlow 1.x
  • Find out how to write clean and elegant Python code that will optimize the strength of your algorithms
  • Discover how to embed your machine learning model in a web application for increased accessibility
  • Learn how to use multiple GPUs for faster training using AWS

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 21, 2017
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781786461988
Vendor :
Google
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 21, 2017
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781786461988
Vendor :
Google
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 153.97
TensorFlow 1.x Deep Learning Cookbook
$48.99
Machine Learning with TensorFlow 1.x
$43.99
TensorFlow Machine Learning Cookbook
$60.99
Total $ 153.97 Stars icon
Banner background image

Table of Contents

12 Chapters
Getting Started with TensorFlow Chevron down icon Chevron up icon
Your First Classifier Chevron down icon Chevron up icon
The TensorFlow Toolbox Chevron down icon Chevron up icon
Cats and Dogs Chevron down icon Chevron up icon
Sequence to Sequence Models-Parlez-vous Français? Chevron down icon Chevron up icon
Finding Meaning Chevron down icon Chevron up icon
Making Money with Machine Learning Chevron down icon Chevron up icon
The Doctor Will See You Now Chevron down icon Chevron up icon
Cruise Control - Automation Chevron down icon Chevron up icon
Go Live and Go Big Chevron down icon Chevron up icon
Going Further - 21 Problems Chevron down icon Chevron up icon
Advanced Installation Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(8 Ratings)
5 star 62.5%
4 star 0%
3 star 12.5%
2 star 0%
1 star 25%
Filter icon Filter
Top Reviews

Filter reviews by




Igidok Dec 14, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This Book is very detailed and walks you through the Tensorflow library very well. I am fairly new to Machine Learning and I think this is a good step by guide.
Amazon Verified review Amazon
Amazon Customer Feb 28, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A very useful resource!
Amazon Verified review Amazon
K. Witek Feb 28, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Always interested in what technologies Google is using to run its systems and this is one of them. Machine Learning and AI are the next big thing and this is one of the enabling technologies that's "hot" right now; and for the right reasons. This book is a good way to learn and get established with this technology, although you do have to be fairly technical to make the most out of it. What is particularly interesting for me is how Machine Learning bridges the gap between how computer think and how people think - Machine learning is comprised of algorithms that teach computers to perform tasks that human beings do naturally on a daily basis. This book explores this very aspect and it is very eye opening.
Amazon Verified review Amazon
SRA Feb 28, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I’m brand new to using TensorFlow so this was a good Primer. It also features advanced chapters to take things forward if you’re already familiar with the basics. There were some simplistic examples which were perfect for a starter. All in all, I would recommend this book to new learners and advanced learners as both can benefit.
Amazon Verified review Amazon
Madeeha Husain Feb 28, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is great and has helped me immensely. I’m quite new to TensorFlow and this book has been so much help!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.