Keras and TensorFlow 1.3 with CUDA 8 and cuDNN on Windows 10

This is an update of my previous article, which was about TensorFlow 1.0.

Here's a quick walkthrough on how to install CUDA, CUDA-powered TensorFlow, and Keras on Windows 10:

Procedure

  1. Install the CUDA 8.0 toolkit from Nvidia -- this will also add CUDA's bin directory to Windows' PATH variable.
  2. Download cuDNN 6.0 from Nvidia. TensorFlow 1.3 requires cuDNN 6.0.
  3. Extract the cuDNN DLL from the downloaded cuDNN zip file, and put it in CUDA's bin directory, which by default is C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin.
  4. Download and install Python 3.5.x from Python.org. TensorFlow only supports 3.5.x on Windows, be sure to grab the 64bit version.
  5. On a elevated admin cmd, run
    python -m pip install --upgrade pip to upgrade to the latest pip version. If you do not upgrade pip, it might not be able to find the TensorFlow packages.
  6. In the same cmd, run pip install --upgrade tensorflow-gpu to install the cuDNN-enabled version of TensorFlow.
  7. Download the latest scipy wheel file from Christoph Gohlke's homepage -- this is the least painful way (apart from Anaconda) to get scipy with LAPACK, etc. Be sure to grab the right version for Python 3.5.x, indicated by cp35 in the filename. As with Python, be sure to grab the 64bit version. Then install it with pip install scipy‑0.19.1‑cp35‑cp35m‑win_amd64.whl.
  8. Install Keras by running pip install --upgrade keras. If you would like to have the latest version from the Github repository, run pip install git+https://github.com/fchollet/keras.git instead.
  9. Log out and in again, to be sure all environment variables set during installation are picked up correctly.

With that, the installation should be done.

To verify both TensorFlow and Keras were installed successfully, run

import tensorflow as tf
import keras
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

from a Python prompt. There should not be any errors, but a merry

b'Hello, TensorFlow!'

as output.

If TensorFlow has trouble finding CUDA or cuDNN, check that CUDA's bin is really in Windows' PATH (see Settings > System > Advanced System Settings > Advanced > Environment Variables), and make sure that the cuDNN DLL is also there.

Troubleshooting

If import tensorflow already fails with a Python exception upon loading _pywrap_tensorflow.pyd, you have either not copied the cuDNN 6.0 DLL to CUDA's bin/ directory, or you are missing the Microsoft Visual C++ 2015 Redistributable Update 3 package.

Sources