Using GPU for deep learning has seen a tremendous performance. It has been reported that execution time using GPU is 10x -50x times faster than CPU-based deep learning and It is also a lot cheaper than CPU-based system. You can see this below in the picture.
I was curious to check deep learning performance on my laptop which has GeForce GT 940M GPU.
Today I will walk you through how to set up GPU based deep learning machine to make use of GPUs. I have used Tensorflow for deep learning on a windows system. Using GPU in windows system is really a pain. You can’t get it to work if you don’t follow correct steps. But if you follow the steps it will be very easy to set up Tensorflow with GPU for windows.
- Python 3.5 – Currently Tensorflow on windows doesn’t support python 2.7.
- nvidia cuda GPU
- CUDA toolkit
Use this link to install cuda- https://developer.nvidia.com/cuda-downloads
According to your windows version, you can install this toolkit.
Recommended version: Cuda Toolkit 8.0
Use this link to install cuDNN -https://developer.nvidia.com/cudnn
You need to register to install this. You need to choose cuDNN v5.1. I have tried latest version but it didn’t work out.After downloading, You need to copy and replace these files
into this location C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0
Now you also need to set path for environment variables. Check below snapshots and make the required changes. If they are not there you have to do it manually.
Install using anaconda . Use whatever anaconda python 2.7 or 3.5 you want to use for your daily tasks because we will create a separate environment for python 3.5 .
- Tensorflow with GPU
Create a virtual environment for tensorflow
conda create --name tensorflow-gpu python=3.5
Then activate this virtual environment:
And finally, install TensorFlow with GPU support:
pip install tensorflow-gpu
Test the TensorFlow installation
python ... >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow!
If you run into any error check below link-
Any other link might lead you to different problems.
- Let’s play with Tensorflow GPU
Let’s check performance on MNIST data using convolution neural network.
download the code- https://github.com/tensorflow/models/blob/master/tutorials/image/mnist/convolutional.pyNow lets run it and check its performance
- GPU based Tensorflow
We can see each step is taking roughly around ~40 ms. Now we want to see if this gpu performanvce worth or not.
- CPU Tensorflow
Let’s take a look at CPU performance. Really? Each step is taking ~370 ms . Wow what a performance!! Tensorflow with GPU is 10x faster than Tensorflow with CPU.
Further, You can install Keras library to do more advance things in deep learning. Keras is a high-level neural networks API, written in Python and capable of running on top of either TensorFlow or Theano. It was developed with a focus on enabling fast experimentation.Keras uses Tensorflow as backend. Keras also work seamlessly on CPU and GPU. Follow below commands. Install jupyter notebook too if you love working with notebooks.
conda install jupyter conda install scipy pandas conda install mingw libpython (theano dependencies) conda install theano pip install keras
In case of any trouble, leave comments and let me know your thoughts about this articles.
Happy hunting with deep learning !!