How to install Tensorflow GPU on Windows ?

Tensorflow offers two versions: cpu-version and gpu-version. Basically, GPUs are better than CPUs for  any kind of machine learning tasks. Its because GPUs are good for mathematical computations than CPUs. Its not that GPU is always better than CPU instead it depends upon the GPU card on your machine.

Requirements

First of all, you need to make sure that you have NVIDIA's Graphics card on your machine which has Compute Capability of 3.5 or higher. You can verify whether your GPU card is compatible by going through this list of CUDA-enabled GPUs.

Note: Before installing any of the packages below, don't forget to check the requirements section in GPU Support page on Tensorflow's website as the version requirements may have been changed from the day this tutorial was published. The installation process is similar but the versions may differ.

The following software packages need to be installed:
  • CUDA (10.0)
  • CuDNN  (>= 7.4.1)
  • Tensorflow gpu-version

Step 1: Install CUDA toolkit

You can download the required version of CUDA toolkit from here and install by following the given instructions.

Step 2: Install CuDNN sdk

To be able to download the CuDNN sdk you need a developer account. Don't worry, you can create one easily with free of cost. Go to this link and click download, you'll be redirected to login/signup page. After you have logged in, you will be able to download the required version of CuDNN.

After you've downloaded the CuDNN package, you need to extract it and copy all the folders to the version directory(e.g. v9.0) where the CUDA was installed. For example, in my case I copied and pasted the folders inside this directory: "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0".

Step 3: Install Tensorflow GPU Version

You can simply install the stable version of Tensorflow GPU by using PIP command as follows:
pip install tensorflow-gpu

If you have already installed Tensorflow CPU version, you need to first uninstall the CPU version (pip uninstall tensorflow) to overwrite or you can run Tensorflow GPU version in Virtual Environment.

Step 4: Verify the Installation

To verify that Tensorflow is using GPU device, you can try running the following code in the command prompt and output should display the GPU card on your machine as follows:
import tensorflow as tf
session = tf.Session(config=tf.ConfigProto(log_device_placement=True))
Output:

If following the above steps didn't work for you, you can still try the following things:
  1. Update GPU Driver
  2. Set the environment variables for CUDA and other packages
  3. Follow the updated gpu installation guide in Tensorflow's website.

Comments