|
Published:
April 3, 2018

TensorFlow For Dummies

Overview

Become a machine learning pro!

Google TensorFlow has become the darling of financial firms and research organizations, but the technology can be intimidating and the learning curve is steep. Luckily, TensorFlow For Dummies is here to offer you a friendly, easy-to-follow book on the subject. Inside, you’ll find out how to write applications with TensorFlow, while also grasping the concepts underlying machine learning—all without ever losing your cool!

Machine learning has become ubiquitous in modern society, and its applications include language translation, robotics, handwriting analysis, financial prediction, and image recognition. TensorFlow is Google's preeminent toolset for

machine learning, and this hands-on guide makes it easy to understand, even for those without a background in artificial intelligence.

  • Install TensorFlow on your computer
  • Learn the fundamentals of statistical regression and neural networks
  • Visualize the machine learning process with TensorBoard
  • Perform image recognition with convolutional neural networks (CNNs)
  • Analyze sequential data with recurrent neural networks (RNNs)
  • Execute TensorFlow on mobile devices and the Google Cloud Platform (GCP)

If you’re a manager or software developer looking to use TensorFlow for machine learning, this is the book you’ll want to have close by.

Read More

About The Author

Matthew Scarpino has been a programmer and engineer for more than 20 years. He has worked extensively with machine learning applications, especially those involving financial analysis, cognitive modeling, and image recognition. Matthew is a Google Certified Data Engineer and blogs about TensorFlow at tfblog.com.

Sample Chapters

tensorflow for dummies

CHEAT SHEET

TensorFlow is Google’s premier framework for machine learning, and each new version brings a wide range of capabilities and features. After you’ve ascended the learning curve, you can write sophisticated machine-learning applications and execute them at high speed.But rising up the learning curve isn’t easy — with great power comes great complexity.

HAVE THIS BOOK?

Articles from
the book

In most software development efforts, an application will always do its job if you code it correctly. But when you work with neural networks, this isn’t the case. You can write flawless code and still end up with lousy results. No matter what the academics say, neural network development is not an exact science — there’s still a lot of art involved.
After you install TensorFlow, you have a directory named tensorflow that contains a wide variety of files and folders. Two top-level folders are particularly important. The core directory contains the TensorFlow's primary packages and modules. The contrib directory contains secondary packages that may later be merged into core TensorFlow.
The cat command in the gsutil utility directs an object's text to standard output. For example, the following command prints the text contained in gs://mybucket/a.txt: gsutil cat gs://mybucket/a.txt Despite its name, you can’t concatenate objects with cat, but you can concatenate objects with compose. That is, the following command concatenates the content of a.
When the machine learning (ML) Engine executes your application, it passes arguments that provide information about the operating environment. The table lists the possible arguments.Machine Learning Arguments Argument Operation --job-dir Location of the application’s data --train_batch_size Batch size for training --train_steps Number of steps for each training epoch --eval_batch_size Batch size for evaluation --eval_steps Number of steps to run evaluation at each checkpoint --eval_delay_secs Time to wait before first evaluation --min_eval_frequency Minimum number of training steps between evaluations --job-dir is particularly important because it tells the application where it should store its output files.
After you create a bucket with the gsutil utility on the Google Cloud Platform (GCP), you can upload files to it, thereby adding objects to the bucket. Similarly, you can download an object to your system as a file. Google makes these operations possible through the cp (copy) and mv (move) commands. Both commands transfer a source entity to a destination, but cp leaves the source entity in place while mv removes the source entity.
Machine learning applications are fundamentally mathematical, and TensorFlow provides a wealth of routines for performing mathematical operations on tensors. Each routine is represented by a function of the tf package, and each function returns a tensor. When it comes to TensorFlow operations, its best to start simple.
Before you upload data to Cloud Storage, you need to create one or more buckets. The command to know is mb: gsutil mb [-c class] [-l location] [-p project_id] url… The –c, –l, and –p flags are particularly important: -c: The bucket's storage class: multi_regional, regional, nearline, and coldline. (Default: multi_regional or regional).
Machine learning applications frequently need exponents and logarithms to compute errors and probability. To meet this need, TensorFlow provides many of the same functions available in NumPy. The following table lists 11 of them and provides a description of each.Exponential and Logarithmic Operations Function Description square(x, name=None) Returns the square of the argument squared_difference(x, y, name=None) Subtracts the first argument from the second and returns the square sqrt(x, name=None) Returns the square root of the argument rsqrt(x, name=None) Returns the reciprocal of the square root pow(x, y, name=None) Returns elements of the first tensor raised to the power of the elements of the second vector exp(x, name=None) Returns the exponential function of the argument expm1(x, name=None) Returns the exponential function of the argument minus one, exp(x) - 1 log(x, name=None) Returns the natural logarithm of the argument log1p(x, name=None) Returns the natural logarithm of the argument plus 1, log(x + 1) erf(x, name=None) Returns the error function of the argument erfc(x, name=None) Returns the complementary error function of the argument These functions are straightforward to use and understand.
Most of the mathematical routines accept floating-point values as input and return floating-point values as output. But many applications need to convert floating-point values into integer values. For this reason, TensorFlow provides the rounding operations listed in the following table.Rounding and Comparison Operations Function Description round(x, name=None) Rounds to the nearest integer, rounding up if there are two nearest integers rint(x, name=None) Rounds to the nearest integer, rounding to the nearest even integer if there are two nearest integers ceil(x, name=None) Returns the smallest integer greater than the value floor(x, name=None) Returns the greatest integer less than the value maximum(x, y, name=None) Returns a tensor containing the larger element of each input tensor minimum(x, y, name=None) Returns a tensor containing the smaller element of each input tensor argmax(x, axis=None, name=None, dimension=None) Returns the index of the greatest element in the tensor argmin(x, axis=None, name=None, dimension=None) Returns the index of the smallest element in the tensor The table also lists functions that perform comparisons.
Just as most programs start by declaring variables, most TensorFlow applications start by creating tensors. A tensor is an array with zero or more dimensions. A zero-dimensional tensor is called a scalar, a one-dimensional tensor is called a vector, and a two-dimensional tensor is called a matrix. Keep in mind these three points about tensors: Every tensor is an instance of the Tensor class.
Many TensorFlow applications require tensors that contain random values instead of predetermined values. The tf package provides many functions for creating random-valued tensors and the following table lists five of them.Creating Tensors with Random Values Function Description random_normal(shape, mean=0.
Machine learning applications store a great deal of data in vectors (one-dimensional tensors) and matrices (two-dimensional tensors). To process this data, TensorFlow provides many functions that operate on vectors and matrices. The following table lists these functions and provides a description of each.Vector and Matrix Operations Function Description tensordot(a, b, axes, name=None) Returns the sum of products for the elements in the given axes cross(a, b, name=None) Returns the element-wise cross product diag(diagonal, name=None) Returns a matrix with the given diagonal values, other values set to zero trace(x, name=None) Returns the sum of the diagonal elements transpose(x, perm=None,name='transpose') Switches rows and columns eye(num_rows, num_columns=None,batch_shape=None,dtype=tf.
If you succeeded in launching jobs locally, deploying your applications to the cloud shouldn't present any difficulty. But be mindful of two issues: You need to upload training/evaluation data to Cloud Storage. The ML Engine may not support the versions of the packages you need. Before you execute either of the applications in the ch13 directory of the TensorFlow For Dummies downloadable code, you’ll need to upload the mnist_test.
It may seem strange to use the Cloud SDK to launch jobs locally. But the ML Engine is neither simple nor free, so you should test your applications locally before deploying them to the cloud. Another reason to execute your code locally is that you can view printed text on the command line instead of having to download and read logs.
Google provides two methods for installing TensorFlow, and the simpler option involves installing precompiled packages. This discussion presents a three-step process for installing these packages: Install Python on your development system. Install the pip package manager. Use pip to install TensorFlow.
After you install TensorFlow, you're ready to start creating and executing applications. This section walks through the process of running an application that prints a simple message. Exploring the example code You can download this example code from the "Downloads" link on Wiley.com. The archive’s name is tf_dummies.
You can launch a training operation with the command gcloud ml-engine jobs submit training. When you execute this, you can identify your source code with the --package-path and --module-name flags. The --package-path flag identifies the directory that contains your code, and this directory must meet the following requirements: The directory must contain the module identified by --module-name.
The ls and stat commands of the gsutil utility provide information about buckets and objects in Cloud Storage. The simplest usage of ls is gsutil ls, which lists all of the buckets associated with the current GCP project.One interesting feature of ls is that it recognizes the virtual hierarchy of objects. For example, suppose that gs://mybucket contains /mydir/a.
An application must specify the shape of each tensor to be created. The tf package provides functions that update tensors and their shapes after creation. This table lists these transformation functions and provides a description of each.Functions for Transforming Tensors Function Description cast(tensor, dtype, name=None) Changes the tensor's data type to the given type reshape(tensor, shape, name=None) Returns a tensor with the same elements as the given tensor with the given shape squeeze(tensor, axis=None, name=None, squeeze_dims=None) Removes dimensions of size 1 reverse(tensor, axis, name=None) Reverses given dimensions of the tensor slice(tensor, begin, size, name=None) Extracts a portion of a tensor stack(tensors, axis=0, name='stack') Combines a list of tensors into a tensor of greater rank unstack(tensor, num=None, axis=0, name='unstack') Splits a tensor into a list of tensors of lesser rank Despite its name, reshape doesn't modify an existing tensor.
After you install the Software Development Kit (SDK), you can execute gcloud commands on a command line. All gcloud commands have the same format: gcloud [optional flags> <group | command> For example, you can check the version of gcloud by entering the following: gcloud version This command identifies the SDK's version and the versions of its components.
If you want to take advantage of the Google Cloud Platform (GCP)’s features, the first step is to create a project. This project serves as the central container of your development effort and includes all your metadata and configuration files. Before you can execute code or launch a web application, you need to upload the files to your project.
One of the most important advances in practical machine learning involved the creation of frameworks. Frameworks automate many aspects of developing machine learning applications, and they allow developers to re-use code and take advantage of best practices. This discussion introduces five of the most popular frameworks: Torch, Theano, Caffe, Keras, and TensorFlow.
Each piece of data in a Cloud Storage bucket is an object. A bucket may contain an unlimited number of objects, but each object must be 5 TB in size or less. Every object has data and metadata. When you upload a file to a bucket, the file’s content becomes the object’s data. An object’s metadata holds name-value pairs that describe the object.
TensorFlow is Google’s premier framework for machine learning, and each new version brings a wide range of capabilities and features. After you’ve ascended the learning curve, you can write sophisticated machine-learning applications and execute them at high speed.But rising up the learning curve isn’t easy — with great power comes great complexity.
The TensorFlow API is immense, comprising hundreds of packages and thousands of modules. Given its size, newcomers may find it hard to know which classes to study closely. To remedy this confusion, here are TensorFlow’s ten most important classes with explanations about what the class accomplishes and why it’s so important.
After you understand how to create a Google Cloud Platform (GCP) project and configure it to access the ML Engine, you’re ready to interact with your project. Google makes this possible through the Google SDK.You can download the SDK. Clicking the Install button opens a page that provides instructions for downloading the SDK installer on your development system.
Machine learning is the most exciting topic in modern software development, and TensorFlow is the best framework to use. To convince you of TensorFlow’s greatness, here are some of the developments that led to its creation. This figure presents an abbreviated timeline of machine learning and related software development.
The filesystem on your computer stores data in files and organizes files using directories. Cloud Storage stores data in objects and collects objects inside buckets. Buckets have a lot in common with directories, but there's one major difference: Buckets can’t be nested. That is, you can’t organize buckets into a hierarchy in the way that you can organize directories.
The gsutil utility lets you create, access, and modify buckets and objects. For the most part, gsutil commands have the same names and purposes as common <sup>*</sup>nix commands.This table lists 13 of gsutil's commands. For a more thorough discussion, visit Google's documentation.gsutil Commands Command Description mb [-c class] [-l location].
https://cdn.prod.website-files.com/6630d85d73068bc09c7c436c/69195ee32d5c606051d9f433_4.%20All%20For%20You.mp3

Frequently Asked Questions

No items found.