Let's Learn How to Install Tensorflow GPU Correctly!
Tensorflow is an Open Source Deep Learning Library by Google, This library allows us to Perform Machine Learning / Deep Learning without much of an effort using Python. Google has done a really good job at making Tensorflow Open Source, It allows students like me create Algorithms that will give a surprise to everyone. Earlier Deep Learning was kinda hard without these open source tools and not much people were able to do it, Now anyone who has High School Math Understanding and A Bit of Python experience can learn how to Deploy Deep Learning Models Easily.
Why Use GPU not CPU?
CPUs actually work with Tensorflow but they are slow while performing these Floating Point Operations that Tensorflow Demands, GPUs are more than 10-20x more Performant in these kind of Operations and that’s Why GPUs are mostly used while using Tensorflow but all those Mac Users will still “CRI” cause they can’t use GPUs Directly.
In this Tutorial, I’ll teach you How to Install Tensorflow-GPU On Your Windows Machine; So Let’s Jump over to the requirements for Installing Tensorflow-GPU -
- A Nvidia Graphics Card with Atleast CuDNN v5.1 Support (Here's a list of Supported Cards)
- A 64 Bit Computer (32Bit doesn't work with GPU)
- Nvidia Cuda Toolkit Installation (Download Toolkit Here)
- Nvidia CuDNN Installation (Download CuDNN Here)
- Anaconda 3.6 Installation (Download Anaconda Here)
Without Wasting Time Let's Start Now!
First I went to the Supported Nvidia Cards List and I noticed there were several options differed by the architecture of the GPUs, I had a Geforce GTX 750Ti (I’m upgrading to 1060 Soon) So, I just clicked on Geforce Cuda Enabled Products and Found out that My card was listed there with a Compute Capability of 5.0.
If you have a compute capability lower than 3.0 then Tensorflow Wouldn’t Work as Listed on Tensorflow.org. Once you’ve identified your Compute Capability go ahead and Download Cuda Toolkit, In the Operating System Option Choose “Windows” (as if that was helpful XD) > then select the x86_64 (64bit) Architecture > Finally Select the Version of your OS, Mine is Windows 10. Once It has been downloaded, Install it.
Now It’s time to Install CuDNN, Unfortunately you’ve to Sign-Up to Download CuDNN from Nvidia’s Website which is very painful, They ask a ton of questions and you might not know answer of some, if you’re a beginner. But We’ve to bear that, So download CuDNN From Nvidia’s Website and After Downloading Use the Run Command on Windows and type this
%Cuda_Path% and that will open a New Explorer Window. Now Do me a favor and extract the files from CuDNN to this Folder, And Replace Some files if it prompts.
Now, It’s our time to Download Anaconda, Please Download the Python 3.6 64Bit Version and Install it as It has a friendly and an Easy Installer which will take care of most of the things for you.
When Anaconda (Conda) is finished Installing, It’s Time To Open CMD and Hack (Just Kidding)
Open CMD from the cute little Windows button in your Taskbar and With the following commands below We’ll create an Anaconda Virtual Python Environment with Python 3.5 -
C:\>conda create --name tf python=3.5
This would create an Anaconda Environment code-named “tf” with a python version of 3.5, Now We’ll switch to the conda environment with the activate command -
Now, We’ll Install our Libraries which are required to run Tensorflow -
conda install jupyter
conda install scipy
pip install tensorflow-gpu
Now, Just wait a few minutes maybe watch a video, read more of my posts et-cetera and It would automatically install tensorflow on your Machine, If an error occurs you should post in the comments below or Just Stack Overflow!
Once, It has been Successfully Installed; We’ll test our tensorflow Installation -
import tensorflow as tf
hello = tf.constant('Hello, Daksh!')
sess = tf.Session()
After Running this, if the output is
b'Hello, Daksh!' then Congratulations and Celebrations because tensorflow is Finally Installed On Your Windows Machine, Now Go Ahead and Make the Skynet (Just Kidding)
Thanks for Reading it till here, If you liked this humorous tutorial Consider following me on my Social Media, Maybe talking with me or Just ask any question related to programming in general with me :)