I know, trying to set up a deep learning environment on Windows isn’t exactly the first thought you have when trying to get GPU options working for Keras and Theano any time you have a machine learning or data science problem. Setting up something like this on Ubuntu would be easier, no doubt, but if you prefer Windows or don’t feel like dual booting every time you need to do some number crunching, then the following instructions will help you to install and configure Keras, Theano, pygpu, and cuDNN on Windows 10.

  1. Install Visual Studio Community (it’s free)
  2. Install C++ compiler within Visual Studio Community
  3. Install Anaconda Python 3.6 then run the following commands:
    • conda update conda -y
    • conda update --all -y
    • conda install mingw libpython m2w64-toolchain theano keras pygpu -y
    • conda uninstall pillow -y
    • conda install pillow=4.0.0
  4. Add the following to the Path variable in Windows 10:
    • C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64
    • C:\Users\[username]\Anaconda3\Library\mingw-w64\bin
    • C:\Users\[username]\Anaconda3\Scripts
    • C:\Users\[username]\Anaconda3\Library\bin
  5. Download the Windows 10 SDK
  6. Make new system variable called “INCLUDE” and add the following paths:
    • C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um
    • C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt
  7. Make new system variable called “LIB” and add the following paths:
    • C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\ucrt\x64
    • C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64
  8. Install cuDNN (make sure to install cuDNN v5 for CUDA 8.0 for Windows 10)
    • Extract the archive and copy the 3 directories (bin, include and lib) in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5 or C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0. If you’re unsure which version of CUDA Theano uses, check your CUDA_PATH environment variable.
  9. Copy C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\cublas64_80.dll to C:\Users\[username]\Anaconda3\Library\bin

Now that you have everything installed and Windows 10 knows where everything is at, we need to create/edit some configuration files for Keras and Theano.

Keras Config

Edit or create ~/.keras/keras.json (~ means your home directory) with the contents below.

"image_data_ordering": "channels_first",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "theano"

Theano Config

Edit or create ~/.theanorc with the contents below.

[global]
floatX = float32
cxx = C:\Users\[username]\Anaconda3\Library\mingw-w64\bin\g++.exe
mode = FAST_RUN
device = gpu

[blas]
ldflags = -LC:\Users\[username]\Anaconda3\Library\bin -lcublas64_80

[gcc]
cxxflags = -LC:\Users\[username]\Anaconda3\Library\mingw-w64\include -LC:\Users\[username]\Anaconda3\Library\mingw-w64\lib

[nvcc]
fastmath = True
flags=-LC:\Users\[username]\Anaconda3\libs
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin

[dnn]
enabled=True

[lib]
cnmem=0.70

Might need to replace [nvcc] line with

[nvcc]
flags=--cl-version=2015 -D_FORCE_INLINES

although I haven’t needed to do this.

Hope this helps! If it does, feel free to let me know in the comments below.

[Edit] For a more detailed walkthrough, Phil Ferriere has generously provided a GitHub repo as reference.