This worked for me:
- Install Visual Studio 15 Community Edition. If you can enable Python during installation, do so. Otherwise fire it up post install, and use NuGet to install Python Tools for Visual Studio.
- Install CUDA 8.0 or higher (follow all defaults)
- Install CuDNN… by this, I mean download it… it’s just a zip with bin, lib, and include directories. Extract the contents of each of these to the corresponding bin, lib, and include folders under your CUDA’s install folder. (CUDA’s “official” install will have added these to various paths; placing the CuDNN stuff in these locations ensures they will be found by whatever CUDA-enabled process may be looking for them later on).
- Install Anaconda 64 bit 3.5 version… (that’s right… not 2.7… reason: TensorFlow requries 3.5… all other dependencies are OK on 2.7; if TensorFlow ever comes along on 2.7, then we’ll be OK there.)
- Fire up Visual Studio… create a Python project… it should find Anaconda and display it under your Solution Explorer…
- In Visual Studio, right-click on the “Python 64-bit 3.5” python environment, and select “Open Command Prompt Here…” (this basically gives you the Anaconda command prompt).
- On the command prompt:
- run conda update conda
- run conda update –all
- run conda install mingw libpython
- run pip install git+git://github.com/Theano/Theano.git
- run pip install git+git://github.com/fchollet/keras.git
- run pip install tensorflow (optional)
- Exit the command prompt.
- In the Anaconda3 root directory, create a .theanorc.txt file, containing:
device = gpu
floatX = float32
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
10. In your Visual Studio project, create a simple “gputest.py” file, containing (see also: this tutorial):
from theano import function, config, shared, sandbox import theano.tensor as T import numpy import time vlen = 10 * 30 * 768 # 10 x #cores x # threads per core iters = 1000 rng = numpy.random.RandomState(22) x = shared(numpy.asarray(rng.rand(vlen), config.floatX)) f = function(, T.exp(x)) print(f.maker.fgraph.toposort()) t0 = time.time() for i in range(iters): r = f() t1 = time.time() print("Looping %d times took %f seconds" % (iters, t1 - t0)) print("Result is %s" % (r,)) if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]): print('Used the cpu') else: print('Used the gpu')
11. Theano might be defaulted to use tensorflow, which can generate some inexplicable errors. To disable this, edit your keras.json file to change the “backend” to “theano”.