Tensorflow: Installing GPU accelerated on Windows Anaconda Python

While “The Chaos Rift” isn’t well known for being techy, this is my true profession. Professionally speaking, I’m in the Data Sciences field and have been mucking around with AI for years. My forrays into AI have mostly been for hobbyist Game development. Lately I’ve expanded the hobby to real world applications. With the release of Tensorflow in 2015, that was the major push. I dropped PERL scripting and learned Python development.

But there are pitfalls to running a Windows OS. A lot of the Deep learning libraries do not like to run on it. Torch* (see bottom) for instance require some special nudges and undocumented commands to get working. Originally Tensorflow was not on PC, though times have changed. Now installing Tensorflow with CPU acceleration is a no brain “pip install tensorflow” and useful for most people starting out. However for serious computing, GPU acceleration is highly recommended. A small dataset of 10,000 images (yeah that’s small) took 3 hours to complete a single epoch. With GPU each epoch (total 25) took 20 minutes. Needless to say the benefits outweigh the setup cost.

But there were pitfalls to the setup, and documentation is a bit sparse. So here it is:

Requirements

Anaconda Python While not “technically” required, Anaconda is the defacto standard for Data Science installations of Python. It’s one I use exclusively at work, despite it not being “standard” software.

Nvidia CUDA GPU. You can check here if your GPU is CUDA compatible. I know finally a non game use for an Nvidia card since ATI has nailed the Crypto Currency market.

Download and install CUDA Toolkit

Download and install cuDNN

cuDNN version 5.1 library for Windows 10: https://developer.nvidia.com/cudnn
You need to signup at Nvidia in order to download these files. Now open “cudnn-8.0-windows10-x64-v5.1.zip” and extract the files into your Toolkit directory. Make sure you open cuda directory first then extract the lib, include, bin directories.

Environmental variables

The Toolkit install sets most of them up. But you’ll need to add “CUDA_HOME“. This is found by typing “View Advanced System Settings” in the Cortana bar. Then click “Environment Variables” button on the bottom.

You’ll have to add these two lines to the user PATH.

Install Anaconda

This is the Easy part. Install Anaconda as it helps us to easily manage separate environments for specific distributions of Python, without disturbing the version of python installed on your system.

Create conda environment

This is really optional. I find managing environments on my PC a nightmare. Granted if I’m doing web development with Django, or you want to freeze a package with Pyinstaller, then yeah, environments are important. Create new environment, with the name tensorflow-gpu.

conda create -n tensorflow-gpu

Activate environment we created

activate tensorflow-gpu

Install tensorFlow

There’s a lot to install. As you can see, I’ve already got the packages installed.

Done. You have successfully installed TensorFlow with GPU on your Windows machine.
Now lets test if it is using GPU…

Test GPU

Enter into python shell

python

import tensorflow as tf

Now run this command and check if it identifies your GPU.

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

The Beauty of GPU Accelerated AI

We’re done! You now have Tensorflow installed on your evil Windows PC and area ready to create self aware algorithms. Here’s an image of it working in the Spyder IDE processing through 8000 pictures of dogs and cats.

Bonus Material

Installing pyTorch on Windows 10 with GPU support is really easy thanks to Github’s peterjc123.