Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Deep Learning Cookbook

You're reading from  Python Deep Learning Cookbook

Product type Book
Published in Oct 2017
Publisher Packt
ISBN-13 9781787125193
Pages 330 pages
Edition 1st Edition
Languages
Author (1):
Indra den Bakker Indra den Bakker
Profile icon Indra den Bakker
Toc

Table of Contents (21) Chapters close

Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Programming Environments, GPU Computing, Cloud Solutions, and Deep Learning Frameworks 2. Feed-Forward Neural Networks 3. Convolutional Neural Networks 4. Recurrent Neural Networks 5. Reinforcement Learning 6. Generative Adversarial Networks 7. Computer Vision 8. Natural Language Processing 9. Speech Recognition and Video Analysis 10. Time Series and Structured Data 11. Game Playing Agents and Robotics 12. Hyperparameter Selection, Tuning, and Neural Network Learning 13. Network Internals 14. Pretrained Models

Installing CUDA and cuDNN


This part is if you want to leverage GPUs for deep learning. The CUDA toolkit is specially designed for GPU-accelerated applications, where the compiler is optimized for using math operations. In addition, the cuDNN library—short for CUDA Deep Neural Network library—is a library that accelerates deep learning routines such as convolutions, pooling, and activation on GPUs.

Getting ready

Make sure you've registered for Nvidia's Accelerated Computing Developer Program at https://developer.nvidia.com/cudnn before starting with this recipe. Only after will you have access to the files needed to install the cuDNN library. 

How to do it...

  1. We start by downloading NVIDIA with the following command in the terminal (adjust the download link accordingly if needed; make sure you use 8 and not 9 for now):
curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  1. Next, we unpack the file and update all all packages in the package lists. Afterwards, we remove the downloaded file:
sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
sudo apt-get update
rm cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  1. Now, we're ready to install CUDA with the following command:
sudo apt-get install cuda-8-0
  1. Next, we need to set the environment variables and add them to the shell script .bashrc:
echo 'export CUDA_HOME=/usr/local/cuda' >> ~/.bashrc
echo 'export PATH=$PATH:$CUDA_HOME/bin' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_HOME/lib64' >> ~/.bashrc
  1. Make sure to reload the shell script afterwards with the following command:
source ~/.bashrc
  1. You can check whether the 8.0 driver and toolkit are correctly using the following commands in your terminal:
nvcc --version
nvidia-smi

The output of the last command should look something like this:

Figure 1.2: Example output of nvidia-smi showing the connected GPU

  1. Here, we can see that an NVIDIA P100 GPU with 16 GB of memory is correctly connected and ready to use. 
  1. We are now ready to install cuDNN. Make sure the NVIDIA cuDNN file is available on the machine, for example, by copying from your local machine to the server if needed. For Google cloud compute engine (make sure you've set up gcloud and the project and zone are set up correctly), you can use the following command (replace local-directory and instance-name with your own settings):
gcloud compute scp local-directory/cudnn-8.0-linux-x64-v6.0.tgz instance-name
  1. First we the file before copying to the right as root:
cd
tar xzvf cudnn-8.0-linux-x64-v6.0.tgz
sudo cp cuda/lib64/* /usr/local/cuda/lib64/
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
  1. To clean up our space, we can remove the files we've used for installation, as follows:
rm -rf ~/cuda
rm cudnn-8.0-linux-x64-v5.1.tgz
You have been reading a chapter from
Python Deep Learning Cookbook
Published in: Oct 2017 Publisher: Packt ISBN-13: 9781787125193
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 $15.99/month. Cancel anytime