28,14 €
Perform supervised and unsupervised machine learning and learn advanced techniques such as training neural networks.
Key Features
Book Description
TensorFlow is one of the most popular machine learning frameworks in Python. With this book, you will improve your knowledge of some of the latest TensorFlow features and will be able to perform supervised and unsupervised machine learning and also train neural networks.
After giving you an overview of what's new in TensorFlow 2.0 Alpha, the book moves on to setting up your machine learning environment using the TensorFlow library. You will perform popular supervised machine learning tasks using techniques such as linear regression, logistic regression, and clustering.
You will get familiar with unsupervised learning for autoencoder applications. The book will also show you how to train effective neural networks using straightforward examples in a variety of different domains.
By the end of the book, you will have been exposed to a large variety of machine learning and neural network TensorFlow techniques.
What you will learn
Who this book is for
Data scientists, machine learning developers, and deep learning enthusiasts looking to quickly get started with TensorFlow 2 will find this book useful. Some Python programming experience with version 3.6 or later, along with a familiarity with Jupyter notebooks will be an added advantage. Exposure to machine learning and neural network techniques would also be helpful.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 190
Veröffentlichungsjahr: 2019
Copyright © 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Amey VarangoankarAcquisition Editor: Shweta PantContent Development Editor: Kirk D'souzaTechnical Editor: Sneha HanchateCopy Editor: Safis EditingProject Coordinator: Namrata SwettaProofreader: Safis EditingIndexer: Priyanka DhadkeGraphics: Alishon MendonsaProduction Coordinator: Aparna Bhagat
First published: March 2019
Production reference: 1280319
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78953-075-9
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Tony Holdroyd's first degree, from Durham University, was in maths and physics. He also has technical qualifications, including MCSD, MCSD.net, and SCJP. He holds an MSc in computer science from London University. He was a senior lecturer in computer science and maths in further education, designing and delivering programming courses in many languages, including C, C+, Java, C#, and SQL. His passion for neural networks stems from research he did for his MSc thesis. He has developed numerous machine learning, neural network, and deep learning applications, and has advised in the media industry on deep learning as applied to image and music processing. Tony lives in Gravesend, Kent, UK, with his wife, Sue McCreeth, who is a renowned musician.
Sujit Pal is a technology research director at Elsevier Labs, an advanced technology group within the Reed-Elsevier Group of companies. His areas of interests include semantic research, Natural Language Processing (NLP), machine learning, and deep learning. At Elsevier, he has worked on several machine learning initiatives involving large image and text corpora, and other initiatives concerning recommendation systems and knowledge graph development. He has co-authored a book called Deep Learning with Keras with Antonio Gulli, and writes about technology on his blog, Salmon Run.
Narotam Singhrecently took voluntary retirement from his post ofmeteorologist withtheIndian MeteorologicalDepartment, Ministry of Earth Sciences, to pursue his dream of learning and helping society. He has been actively involved with various technical programs and the training of GOI officers in the field of IT and communication. He did his master's in the field of electronics, having graduated with a degree in physics. He also holds a diploma and a postgraduate diploma in the field of computer engineering. Presently, he works as a freelancer. He has many research publications to his name and has also served as a technical reviewer for numerous books. His present research interests involve AI, ML, DL, robotics, and spirituality.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
TensorFlow 2.0 Quick Start Guide
Dedication
About Packt
Why subscribe?
Packt.com
Contributors
About the author
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Section 1: Introduction to TensorFlow 2.00 Alpha
Introducing TensorFlow 2
Looking at the modern TensorFlow ecosystem
Installing TensorFlow
Housekeeping and eager operations
Importing TensorFlow
Coding style convention for TensorFlow
Using eager execution
Declaring eager variables
Declaring TensorFlow constants
Shaping a tensor
Ranking (dimensions) of a tensor
Specifying an element of a tensor
Casting a tensor to a NumPy/Python variable
Finding the size (number of elements) of a tensor
Finding the datatype of a tensor
Specifying element-wise primitive tensor operations
Broadcasting
Transposing TensorFlow and matrix multiplication
Casting a tensor to another (tensor) datatype
Declaring ragged tensors
Providing useful TensorFlow operations
Finding the squared difference between two tensors
Finding a mean
Finding the mean across all axes
Finding the mean across columns
Finding the mean across rows 
Generating tensors filled with random values
Using tf.random.normal()
Using tf.random.uniform()
Using a practical example of random values
Finding the indices of the largest and smallest element
Saving and restoring tensor values using a checkpoint
Using tf.function
Summary
Keras, a High-Level API for TensorFlow 2
The adoption and advantages of Keras
The features of Keras
The default Keras configuration file
The Keras backend
Keras data types
Keras models
The Keras Sequential model
The first way to create a Sequential model
The second way to create a Sequential model
The Keras functional API
Subclassing the Keras Model class
Using data pipelines
Saving and loading Keras models
Keras datasets
Summary
ANN Technologies Using TensorFlow 2
Presenting data to an ANN
Using NumPy arrays with datasets
Using comma-separated value (CSV) files with datasets
CSV example 1
CSV example 2
CSV example 3
TFRecords
TFRecord example 1
TFRecord example 2
One-hot encoding
OHE example 1
OHE example 2
Layers
Dense (fully connected) layer
Convolutional layer
Max pooling layer
Batch normalization layer and dropout layer
Softmax layer
Activation functions
Creating the model
Gradient calculations for gradient descent algorithms
Loss functions
Summary
Section 2: Supervised and Unsupervised Learning in TensorFlow 2.00 Alpha
Supervised Machine Learning Using TensorFlow 2
Supervised learning
Linear regression
Our first linear regression example
The Boston housing dataset
Logistic regression (classification)
k-Nearest Neighbors (KNN)
Summary
Unsupervised Learning Using TensorFlow 2
Autoencoders
A simple autoencoder
Preprocessing the data
Training
Displaying the results
An autoencoder application – denoising
Setup
Preprocessing the data
The noisy images
Creating the encoding layers
Creating the decoding layers
Model summary
Model instantiation, compiling, and training
Denoised images
TensorBoard output
Summary
Section 3: Neural Network Applications of TensorFlow 2.00 Alpha
Recognizing Images with TensorFlow 2
Quick Draw – image classification using TensorFlow
Acquiring the data
Setting up our environment
Preprocessing the data
Creating the model
Training and testing the model
TensorBoard callback
Saving, loading, and retesting the model
Saving and loading NumPy image data using the .h5 format
Loading and inference with a pre-trained model
CIFAR 10 image classification using TensorFlow
Introduction
The application
Summary
Neural Style Transfer Using TensorFlow 2
Setting up the imports
Preprocessing the images
Viewing the original images
Using the VGG19 architecture
Creating the model
Calculating the losses
Performing the style transfer
Final displays
Summary
Recurrent Neural Networks Using TensorFlow 2
Neural network processing modes
Recurrent architectures
An application of RNNs
The code for our RNN example
Building and instantiating our model
Using our model to get predictions
Summary
TensorFlow Estimators and TensorFlow Hub
TensorFlow Estimators
The code
TensorFlow Hub
IMDb (database of movie reviews)
The dataset
The code
Summary
Converting from tf1.12 to tf2
Other Books You May Enjoy
Leave a review - let other readers know what you think
TensorFlow is one of the most popular machine learning frameworks in Python. With this book, you will improve your knowledge of the latest features of TensorFlow, and will be able to perform supervised and unsupervised machine learning using Python.
As its title suggests, this book has been written to introduce readers to TensorFlow and many of its latest features, up to and including version 2.0.0 alpha, including eager execution, tf.data, tf.keras, TensorFlow Hub, machine learning, and neural network applications.
This book is intended to be useful for anyone with some exposure to machine learning and its applications: data scientists, machine learning engineers, computer scientists, computer science students, and hobbyists.
Chapter 1, Introducing TensorFlow 2, introduces TensorFlow by looking at a number of snippets of code, illustrating some basic operations. We will have an overview of the modern TensorFlow ecosystem and will see how to install TensorFlow.
Chapter 2, Keras, a High-Level API for TensorFlow 2, takes a look at the Keras API, including some general comments and insights, followed by a basic architecture expressed in four different ways, for training with the MNIST dataset.
Chapter 3, ANN Technologies Using TensorFlow 2, examines a number of technologies that support the creation and use of neural networks. This chapter will cover data presentation to an ANN, layers of an ANN, creating the model, gradient calculations for gradient descent algorithms, loss functions, and saving and restoring models.
Chapter 4, Supervised Machine Learning Using TensorFlow 2, describes examples of the use of TensorFlow for two situations involving linear regression where features are mapped to known labels that have continuous values, allowing predictions on unseen features to be made.
Chapter 5, Unsupervised Learning Using TensorFlow 2, looks at two applications of autoencoders in unsupervised learning: firstly for compressing data; and secondly, for denoising, in other words, removing noise from images.
Chapter 6, Recognizing Images with TensorFlow 2, firstly looks at the Google Quick Draw 1 image dataset, and secondly, at the CIFAR 10 image dataset.
Chapter 7, Neural Style Transfer Using TensorFlow 2, explains how to take a content image and a style image and then produce a hybrid image. We will use layers from the trained VGG19 model to accomplish this.
Chapter 8, Recurrent Neural Networks Using TensorFlow 2, initially discusses the general principles of RNNs and then looks at how to acquire and prepare some text for use by a model.
Chapter 9, TensorFlow Estimators and TensorFlow Hub, firstly looks at an estimator for training the fashion dataset. We will see how estimators provide a simple, intuitive API for TensorFlow. We will also look at a neural network for analyzing the film feedback database, IMDb.
Appendix, Converting from tf1.12 to tf2, contains some tips for converting your tf1.12 files to tf2.
Working knowledge of Python 3.6 is assumed, as is familiarity with the use of Jupyter Notebooks.
The book is written assuming that readers are happier with explanations given in the form of code snippets and complete programs than long textual explanations, which, of course, have their place in different styles of book.
Some familiarity with machine learning concepts and techniques is highly recommended, although not absolutely essential if the reader is willing to do a little reading around on the subjects.
You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packt.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
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 https://github.com/PacktPublishing/Tensorflow-2.0-Quick-Start-Guide. 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 catalogue of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/9781789530759_ColorImages.pdf.
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and 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 www.packt.com/submit-errata, 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 authors.packtpub.com.
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 packt.com.
In this section, we will introduce TensorFlow 2.00 alpha. We will begin with an overview of the major features of this machine learning ecosystem and see some examples of its use. We will then introduce TensorFlow's high-level Keras API. We will end the section with an investigation of artificial neural network technologies and techniques.
This section contains the following chapters:
Chapter 1
,
Introducing TensorFlow 2
Chapter 2
,
Keras, a High-Level API for TensorFlow 2
Chapter 3
,
ANN Technologies Using TensorFlow 2
Let's discuss eager execution. The first incarnation of TensorFlow involved constructing a computational graph made up of operations and tensors, which had to be subsequently evaluated in what Google termed as session(this is known asdeclarativeprogramming). This is still a common way to write TensorFlow programs. However, eager execution, available from release 1.5 onward in research form and baked into TensorFlow proper from release 1.7, involves the immediate evaluation of operations, with the consequence that tensors can be treated like NumPy arrays (this is known asimperativeprogramming).
Google says that eager execution is the preferred method for research and development but that computational graphs are to be preferred for serving TensorFlow production applications.
tf.data is an API that allows you to build complicated data input pipelines from simpler, reusable parts. The highest level abstraction is Dataset, which comprises both elements of nested structures of tensors and a plan of transformations that are to act on those elements. There are classes for the following:
There's
Dataset
consisting of fixed length record sets from at least one binary file (
FixedLengthRecordDataset
)
There's
Dataset
consisting of records from at least one TFRecord file (
TFRecordDataset
)
There's
Dataset
consisting of records that are lines from at least one text file
(
TFRecordDataset
)
There is also a class that represents the state of iterating through
Dataset
(
tf.data.Iterator
)
Let's move on to the estimator, which is a high-level API that allows you to build greatly simplified machine learning programs. Estimators take care of training, evaluation, prediction, and exports for serving.
TensorFlow.js is a collection of APIs that allow you to build and train models using either the low-level JavaScript linear algebra library or the high-level layers API. Hence, models can be trained and run in a browser.
TensorFlow Lite is a lightweight version of TensorFlow for mobile and embedded devices. It consists of a runtime interpreter and a set of utilities. The idea is that you train a model on a higher-powered machine and then convert your model into the .tflite
