Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
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

Arrow left icon
Profile Icon Hua Profile Icon Ahmed Profile Icon Ul Azeem
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (8 Ratings)
Paperback Nov 2017 304 pages 1st Edition
eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Hua Profile Icon Ahmed Profile Icon Ul Azeem
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (8 Ratings)
Paperback Nov 2017 304 pages 1st Edition
eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781786462961
Vendor :
Google
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 115.97
TensorFlow 1.x Deep Learning Cookbook
€36.99
Machine Learning with TensorFlow 1.x
€32.99
TensorFlow Machine Learning Cookbook
€45.99
Total 115.97 Stars icon

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.