Tensorflow GPU Installation Made Easy: Use conda instead of pip [Update-2] | by Harveen Singh Chadha | Towards Data Science

Want to Install Tensorflow on your GPU machine and run those GPU eating Deep Learning Algorithms? Well you are at the right place. I have a good configuration GPU on which I used to play FIFA. Switching to AI, I wanted to use GPU for Deep Learning instead of playing games. But..... I was scared of Tensorflow installations with incompatible CUDA Versions. In this article I will explain the conventional approach and the new optimized approach and why we should dump pip and use conda instead.
medium.com
To install Tensorflow for GPU I had to follow the steps(Steps are for windows) :
First find if the GPU is compatible with Tensorflow GPU or not! (From Here)Download and Install Cuda Toolkit from here.Download cuDNN by signing up on Nvidia Developer WebsiteInstall cuDNN by extracting the contents of cuDNN into the Toolkit path installed in Step 2. There will be files that you have to replace in CUDA Toolkit Directory.Is that it? No, then you need to check your path variables if CUDA_HOME is present or not. If not, please add it manually.Then check the path variables if your toolkit paths are available or not.Then finally install Anaconda or MinicondaCreating an Environment with Python and Pip packages installed.Then finally ‘pip install tensorflow-gpu’.Test your installation.
First find if the GPU is compatible with Tensorflow GPU or not! (From Here)
Download and Install Cuda Toolkit from here.
Download cuDNN by signing up on Nvidia Developer Website
Install cuDNN by extracting the contents of cuDNN into the Toolkit path installed in Step 2. There will be files that you have to replace in CUDA Toolkit Directory.
Is that it? No, then you need to check your path variables if CUDA_HOME is present or not. If not, please add it manually.
Then check the path variables if your toolkit paths are available or not.
Then finally install Anaconda or Miniconda
Creating an Environment with Python and Pip packages installed.
Then finally ‘pip install tensorflow-gpu’.
Test your installation.
Well you will say that’s easy right? Why not go ahead and try it. Remember I am not giving visuals for any of the steps above because these are just for your knowledge and to explain the problem we had with this process.
Why?
Because of the version numbering
Different Versions of Tensorflow support different cuDNN and CUDA Verisons (In this table CUDA has an integer value but when you go to download it is actually a float which makes numbering and compatibility more difficult). Also cuDNN and conda were not a part of conda.
Install Miniconda or Anaconda and then run this command.
conda create --name tf_gpu tensorflow-gpu 
Well is that it? YES.
This command will create an environment first named with ‘tf_gpu’ and will install all the packages required by tensorflow-gpu including the cuda and cuDNN compatible verisons.
And also it will not interfere with your current environment all ready set up.
If you have a hard time visualizing the command I will break this command into three commands.
conda create --name tf_gpuactivate tf_gpuconda install tensorflow-gpu
Note: This works for Ubuntu users as well. No more long scripts to get the DL running on GPU.
To test your tensorflow installation follow these steps:
Open Terminal and activate environment using ‘activate tf_gpu’.Go to python console using ‘python’
Open Terminal and activate environment using ‘activate tf_gpu’.
Go to python console using ‘python’
import tensorflow as tfsess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
Read my other Articles On Medium:
My first Data Science InterviewMachine Learning: What, When and How?Kalman Filter Interview
My first Data Science Interview
Machine Learning: What, When and How?
Kalman Filter Interview
About Me: I work as a Self Driving Car Engineer focused on providing Intelligence to Vehicles using Deep Learning. Please reach out to me on LinkedIn, if you are facing any difficulties.
This Information was published here originally. This article also talks about some improvements in Tensorflow computation which I don’t bother about right now because that’s not my priority :D
Update 1: Some users complained it is not working on Ubuntu, I found out you need to install drivers manually on Ubuntu which are compatible with the card. Also if you have any other environment already set up then its a mess and this might not help you.
Update 2: This article has been read more than 50k times now and even Aurélien Géron recommends installing Tensorflow using this trick.