Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Deep Learning with Keras
Deep Learning with Keras

Deep Learning with Keras: Implementing deep learning models and neural networks with the power of Python

Arrow left icon
Profile Icon Antonio Gulli Profile Icon Sujit Pal
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (20 Ratings)
Paperback Apr 2017 318 pages 1st Edition
eBook
Mex$179.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial
Arrow left icon
Profile Icon Antonio Gulli Profile Icon Sujit Pal
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (20 Ratings)
Paperback Apr 2017 318 pages 1st Edition
eBook
Mex$179.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial
eBook
Mex$179.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial

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

Deep Learning with Keras

Keras Installation and API

In the previous chapter, we discussed the basic principles of neural networks and provided a few examples of nets that are able to recognize MNIST handwritten numbers.

This chapter explains how to install Keras, Theano, and TensorFlow. Step by step, we will look at how to get the environment working and move from intuition to working nets in very little time. Then we will discuss how to install on a dockerized infrastructure based on containers, and in the cloud with Google GCP, Amazon AWS, and Microsoft Azure. In addition to that, we will present an overview of Keras APIs, and some commonly useful operations such as loading and saving neural networks' architectures and weights, early stopping, history saving, checkpointing, and interactions with TensorBoard and Quiver. Let us start.

By the end of this chapter, we will have covered the following topics:

  • Installing and configuring...

Installing Keras

In the sections to follow, we will show how to install Keras on multiple platforms.

Step 1 — install some useful dependencies

First, we install the numpy package, which provides support for large, multidimensional arrays and matrices as well as high-level mathematical functions. Then we install scipy, a library used for scientific computation. After that, it might be appropriate to install scikit-learn, a package considered the Python Swiss army knife for machine learning. In this case, we will use it for data exploration. Optionally, it could be useful to install pillow, a library useful for image processing, and h5py, a library useful for data serialization used by Keras for model saving. A single command line is enough for installing...

Configuring Keras

Keras has a very minimalist configuration file. Let's load it with a vi session. The parameters are very simple:

Parameters Values
image_dim_ordering Can be either tf for the TensorFlow image ordering or th for Theano image ordering
epsilon The epsilon value used during computation
floatx Can be either float32 or float64
backend Can be either tensorflow or theano

The image_dim_ordering of th value gives you a somewhat non-intuitive dimension ordering for images (depth, width, and height), instead of (width, height, and depth), for tf. The following are the default parameters in my machine:

If you install a GPU-enabled TensorFlow version, then Keras will automatically use your configured GPU when TensorFlow is selected as the backend.

Installing Keras on Docker

One of the easiest ways to get started with TensorFlow and Keras is running in a Docker container. A convenient solution is to use a predefined Docker image for deep learning created by the community that contains all the popular DL frameworks (TensorFlow, Theano, Torch, Caffe, and so on). Refer to the GitHub repository at https://github.com/saiprashanths/dl-docker for the code files. Assuming that you already have Docker up and running (for more information, refer to https://www.docker.com/products/overview), installing it is pretty simple and is shown as follows:

The following screenshot, says something like, after getting the image from Git, we build the Docker image:

In this screenshot, we see how to run it:

From within the container, it is possible to activate support for Jupyter Notebooks (for more information, refer to http://jupyter.org/):

Access it directly...

Installing Keras on Google Cloud ML

Installing Keras on Google Cloud is very simple. First, we can install Google Cloud (for the downloadable file, refer to https://cloud.google.com/sdk/), a command-line interface for Google Cloud Platform; then we can use CloudML, a managed service that enables us to easily build machine, learning models with TensorFlow. Before using Keras, let's use Google Cloud with TensorFlow to train an MNIST example available on GitHub. The code is local and training happens in the cloud:

In the following screenshot, you can see how to run a training session:

We can use TensorBoard to show how cross-entropy decreases across iterations:

In the next screenshot, we see the graph of cross-entropy:

Now, if we want to use Keras on the top of TensorFlow, we simply download the Keras source from PyPI (for the downloadable file, refer to https://pypi.Python.org/pypi...

Installing Keras on Amazon AWS

Installing TensorFlow and Keras on Amazon is very simple. Indeed, it is possible to use a prebuilt AMI named TFAMI.v3 that is open and free (for more information, refer to https://github.com/ritchieng/tensorflow-aws-ami), shown as follows:

This AMI runs TensorFlow in less than five minutes and supports TensorFlow, Keras, OpenAI Gym, and all dependencies. As of January 2017, it supports the following:

  • TensorFlow 0.12
  • Keras 1.1.0
  • TensorLayer 1.2.7
  • CUDA 8.0
  • CuDNN 5.1
  • Python 2.7
  • Ubuntu 16.04

In addition, TFAMI.v3 works on P2 computing instances (for more information, refer to https://aws.amazon.com/ec2/instance-types/#p2), as shown in the following screenshot:

Some features of P2 instances are as follows:

  • Intel Xeon E5-2686v4 (Broadwell) processors
  • NVIDIA K80 GPUs, each with 2,496 parallel cores and 12 GB of GPU memory
  • Supports peer-to-peer GPU communication
  • Provides...

Installing Keras on Microsoft Azure

One way to install Keras on Azure is to install the support for Docker and then get a containerized version of TensorFlow plus Keras. Online, it is also possible to find a detailed set of instructions on how to install Keras and TensorFlow with Docker, but this is essentially what we have seen already in a previous section (for more information, refer to https://blogs.msdn.microsoft.com/uk_faculty_connection/2016/09/26/tensorflow-on-docker-with-microsoft-azure/).

If you use Theano as the only backend, then Keras can run with just a click by loading a pre-built package available on Cortana Intelligence Gallery (for more information, refer to https://gallery.cortanaintelligence.com/Experiment/Theano-Keras-1).
The following sample shows how to import Theano and Keras into Azure ML directly as a ZIP file and use them in the Execute Python Script module. This example is due to...

Installing Keras


In the sections to follow, we will show how to install Keras on multiple platforms.

Step 1 — install some useful dependencies

First, we install the numpy package, which provides support for large, multidimensional arrays and matrices as well as high-level mathematical functions. Then we install scipy, a library used for scientific computation. After that, it might be appropriate to install scikit-learn, a package considered the Python Swiss army knife for machine learning. In this case, we will use it for data exploration. Optionally, it could be useful to install pillow, a library useful for image processing, and h5py, a library useful for data serialization used by Keras for model saving. A single command line is enough for installing what is needed. Alternatively, one can install Anaconda Python, which will automatically install numpy, scipy, scikit-learn, h5py, pillow, and a lot of other libraries that are needed for scientific computing (for more information, refer to...

Configuring Keras


Keras has a very minimalist configuration file. Let's load it with a vi session. The parameters are very simple:

Parameters

Values

image_dim_ordering

Can be either tf for the TensorFlow image ordering or th for Theano image ordering

epsilon

The epsilon value used during computation

floatx

Can be either float32 or float64

backend

Can be either tensorflow or theano

The image_dim_ordering of th value gives you a somewhat non-intuitive dimension ordering for images (depth, width, and height), instead of (width, height, and depth), for tf. The following are the default parameters in my machine:

Note

If you install a GPU-enabled TensorFlow version, then Keras will automatically use your configured GPU when TensorFlow is selected as the backend.

Installing Keras on Docker


One of the easiest ways to get started with TensorFlow and Keras is running in a Docker container. A convenient solution is to use a predefined Docker image for deep learning created by the community that contains all the popular DL frameworks (TensorFlow, Theano, Torch, Caffe, and so on). Refer to the GitHub repository at https://github.com/saiprashanths/dl-docker for the code files. Assuming that you already have Docker up and running (for more information, refer to https://www.docker.com/products/overview), installing it is pretty simple and is shown as follows:

The following screenshot, says something like, after getting the image from Git, we build the Docker image:

In this screenshot, we see how to run it:

From within the container, it is possible to activate support for Jupyter Notebooks (for more information, refer to http://jupyter.org/):

Access it directly from the host machine on port:

It is also possible to access TensorBoard (for more information, refer...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Implement various deep learning algorithms in Keras and see how deep learning can be used in games
  • See how various deep learning models and practical use-cases can be implemented using Keras
  • A practical, hands-on guide with real-world examples to give you a strong foundation in Keras

Description

This book starts by introducing you to supervised learning algorithms such as simple linear regression, the classical multilayer perceptron and more sophisticated deep convolutional networks. You will also explore image processing with recognition of handwritten digit images, classification of images into different categories, and advanced objects recognition with related image annotations. An example of identification of salient points for face detection is also provided. Next you will be introduced to Recurrent Networks, which are optimized for processing sequence data such as text, audio or time series. Following that, you will learn about unsupervised learning algorithms such as Autoencoders and the very popular Generative Adversarial Networks (GANs). You will also explore non-traditional uses of neural networks as Style Transfer. Finally, you will look at reinforcement learning and its application to AI game playing, another popular direction of research and application of neural networks.

Who is this book for?

If you are a data scientist with experience in machine learning or an AI programmer with some exposure to neural networks, you will find this book a useful entry point to deep-learning with Keras. A knowledge of Python is required for this book.

What you will learn

  • Optimize step-by-step functions on a large neural network using the Backpropagation algorithm
  • Fine-tune a neural network to improve the quality of results
  • Use deep learning for image and audio processing
  • Use Recursive Neural Tensor Networks (RNTNs) to outperform standard word embedding in special cases
  • Identify problems for which Recurrent Neural Network (RNN) solutions are suitable
  • Explore the process required to implement Autoencoders
  • Evolve a deep neural network using reinforcement learning

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 26, 2017
Length: 318 pages
Edition : 1st
Language : English
ISBN-13 : 9781787128422
Category :
Languages :
Concepts :
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 : Apr 26, 2017
Length: 318 pages
Edition : 1st
Language : English
ISBN-13 : 9781787128422
Category :
Languages :
Concepts :
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 Mex$85 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 Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 3,509.97
TensorFlow Machine Learning Cookbook
Mex$1251.99
Deep Learning with TensorFlow
Mex$1128.99
Deep Learning with Keras
Mex$1128.99
Total Mex$ 3,509.97 Stars icon
Banner background image

Table of Contents

9 Chapters
Neural Networks Foundations Chevron down icon Chevron up icon
Keras Installation and API Chevron down icon Chevron up icon
Deep Learning with ConvNets Chevron down icon Chevron up icon
Generative Adversarial Networks and WaveNet Chevron down icon Chevron up icon
Word Embeddings Chevron down icon Chevron up icon
Recurrent Neural Network — RNN Chevron down icon Chevron up icon
Additional Deep Learning Models Chevron down icon Chevron up icon
AI Game Playing Chevron down icon Chevron up icon
Conclusion 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.5
(20 Ratings)
5 star 25%
4 star 20%
3 star 35%
2 star 15%
1 star 5%
Filter icon Filter
Top Reviews

Filter reviews by




Kyle Mar 07, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Fast and convenient, no surprises.
Amazon Verified review Amazon
Amazon Customer Sep 07, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is definitely one of the best resources if you want to learn Keras.
Amazon Verified review Amazon
Arbaaz Qureshi Jun 23, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good book, for readers who are familiar with deep learning concepts and Keras and wish to improve them further. Correct the errors of the code section, in the next version.
Amazon Verified review Amazon
Tae S. Shin Dec 09, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I needed a reference book to use Keras that is a user-oriented library for easy modeling of neural networks in Python. Unlike some low reviews on the book, it turned out to be exactly what I expected and what its title said, Implementing deep learning models and neural networks with Keras in Python.If you want to know more about theory of deep learning, you should refer to other deep learning books. If you want to know how Keras API internally works, you may want to look at other books on Tensorflow or Theano that was low level API for Keras and with which you can define neural networks in node-level. But if you want to flexibly and easily build a NN model with fewer lines of code, this book might be good for you.
Amazon Verified review Amazon
Melvin Dec 30, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I felt compelled to write a review because I really think this is an exceptionally good book under the circumstances. When I say "under the circumstances", I mean given the fact that deep learning is a challenging topic to explain and requires both a theoretic and practical approach to be appreciated. The author clearly avoids getting bogged down with the theoretical aspects and I can appreciate why since a thorough theoretical understanding would require a separate book in it's own right.This book will not help you understand the theory or underlying mathematics. However, if you already understand the theory and want to learn to use a package like Keras then this is the book for you.This book stands out because it gives details about the implementation aspects of coding many different deep learning models that you will hear about in the literature and in the field. For example, LeNet, ResNet, etc. among many others are demonstrated through out the book.Generally speaking, topics in deep learning are not easy to explain to the average reader and I think the author recognizes this difficulty and chooses to place his focus on demonstrating how to implement deep learning methods and being careful to explain what the different modules do and their respective parameters.In my view, this book is very suitable for Data Scientists who already know the spectrum of machine learning models and techniques and want to get their hands dirty as fast as possible with deep learning. This book is a much better practical book for deep learning than the popular book by Aurélien Géron called "Hands-On Machine Learning with Scikit-Learn and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems". I have looked at many deep learning books and in my view this one did the best job is getting me comfortable with implementing deep learning models on my own.The one thing that I found the book was lacking is that it's final chapter on AI and reinforcement learning did not seem as thorough and detailed as the other chapters in the book. Having reviewed many books in the area of deep learning, I can honestly say this is probably the best book I have come across so far. However, I came to this book already having a solid understand of deep learning theory.
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.