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
Arrow up icon
GO TO TOP
Keras Deep Learning Cookbook

You're reading from   Keras Deep Learning Cookbook Over 30 recipes for implementing deep neural networks in Python

Arrow left icon
Product type Paperback
Published in Oct 2018
Publisher Packt
ISBN-13 9781788621755
Length 252 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Sujit Pal Sujit Pal
Author Profile Icon Sujit Pal
Sujit Pal
Manpreet Singh Ghotra Manpreet Singh Ghotra
Author Profile Icon Manpreet Singh Ghotra
Manpreet Singh Ghotra
Rajdeep Dua Rajdeep Dua
Author Profile Icon Rajdeep Dua
Rajdeep Dua
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Keras Installation FREE CHAPTER 2. Working with Keras Datasets and Models 3. Data Preprocessing, Optimization, and Visualization 4. Classification Using Different Keras Layers 5. Implementing Convolutional Neural Networks 6. Generative Adversarial Networks 7. Recurrent Neural Networks 8. Natural Language Processing Using Keras Models 9. Text Summarization Using Keras Models 10. Reinforcement Learning 11. Other Books You May Enjoy

Installing Keras on Ubuntu 16.04 with GPU enabled

In this recipe, we will install Keras on Ubuntu 16.04 with NVIDIA GPU enabled.

Getting ready

We are going to launch a GPU-enabled AWS EC2 instance and prepare it for the installed TensorFlow with the GPU and Keras. Launch the following AMI: Ubuntu Server 16.04 LTS (HVM), SSD Volume Type - ami-aa2ea6d0:

This is an AMI with Ubuntu 16.04 64 bit pre-installed, and it has the SSD volume type.

Choose the appropriate instance type: g3.4xlarge:

Once the VM is launched, assign the appropriate key that you will use to SSH into it. In our case, we used a pre-existing key:

SSH into the instance:

ssh -i aws/rd_app.pem [email protected]

How to do it...

  1. Run the following commands to update and upgrade the OS:
sudo apt-get update
sudo apt-get upgrade
  1. Install the gcc compiler and make the tool:
sudo apt install gcc
sudo apt install make

Installing cuda

  1. Execute the following command to execute cuda:
sudo apt-get install -y cuda
  1. Check that cuda is installed and run a basic program:
ls /usr/local/cuda-8.0
bin extras lib64 libnvvp nvml README share targets version.txt
doc include libnsight LICENSE nvvm samples src tools
  1. Let's run one of the cuda samples after compiling it locally:
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
cd /usr/local/cuda-8.0/samples/5_Simulations/nbody
  1. Compile the sample and run it as follows:
sudo make

./nbody

You will see output similar to the following listing:

Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance.
-fullscreen (run n-body simulation in fullscreen mode)
-fp64 (use double precision floating point values for simulation)
-hostmem (stores simulation data in host memory)
-benchmark (run benchmark to measure performance)
-numbodies=<N> (number of bodies (>= 1) to run in simulation)
-device=<d> (where d=0,1,2.... for the CUDA device to use)
-numdevices=<i> (where i=(number of CUDA devices > 0) to use for simulation)
-compare (compares simulation results running once on the default GPU and once on the CPU)
-cpu (run n-body simulation on the CPU)
-tipsy=<file.bin> (load a tipsy model file for simulation)
  1. Next we install cudnn, which is a deep learning library from NVIDIA. You can find more information at https://developer.nvidia.com/cudnn.

Installing cudnn

  1. Download cudnn from the NVIDIA site (https://developer.nvidia.com/rdp/assets/cudnn-8.0-linux-x64-v5.0-ga-tgz) and decompress the binary:
Please note, you will need an NVIDIA developer account.
tar xvf cudnn-8.0-linux-x64-v5.1.tgz

We obtain the following output after decompressing the .tgz file:

cuda/include/cudnn.h
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.5
cuda/lib64/libcudnn.so.5.1.10
cuda/lib64/libcudnn_static.a
  1. Copy these files to the /usr/local folder, as follows:
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64

sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Installing NVIDIA CUDA profiler tools interface development files

Install the NVIDIA CUDA profiler tools interface development files that are needed for TensorFlow GPU installation with the following code:

sudo apt-get install libcupti-dev

Installing the TensorFlow GPU version

Execute the following command to install the TensorFlow GPU version:

sudo pip install tensorflow-gpu

Installing Keras

For Keras, use the sample command, as used for the installation with GPUs:

sudo pip install keras

In this recipe, we learned how to install Keras on top of the TensorFlow GPU hooked to cuDNN and CUDA.

You have been reading a chapter from
Keras Deep Learning Cookbook
Published in: Oct 2018
Publisher: Packt
ISBN-13: 9781788621755
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image