Install Cuda 8/CuDNN 6, Tensorflow and Keras on Windows 10

[Windows 10 安装 Cuda 8 + CuDNN 6, Tensorflow 和 keras,附CPU/GPU切换小技巧]

Updated: Dec 29, 2017

Originally published on Amblizer.xyz, reblogged in case of blocking

I’ve tried months ago to install the GPU-based Machine learning framework, namely keras with tensorflow, but get stuck following the official indication of the latter, and the issue remained unresolved until yesterday because of loads of patients in summer vocation, and I finally managed to get m1000m working.

I basically followed instructions written in Chinese in http://blog.csdn.net/u012898521/article/details/69611800, with a few modifications according to keras documentation in Chinese HERE, and actually I did a combination of both.

Step 1 - Python with Anaconda

By far tensorflow only support python 3 but no newer than major version of 3.5, and last time I got a lot of trouble tried to install the dependencies especially scipy. I didn’t use anaconda because it starts rather slow and Google said you could install tensorflow without it, and it was later I found scipy itself WILL encounter problems when installed on windows.

Just download and intall Anaconda 5.0 with python 3,

Simply install Anaconda with python 3.5 (I installed Anaconda 4.2.0 with python 3.5.2) 3.6, and it will save you all the troubles.

Step 2 — CUDA and CuDNN

NVIDIA had buried download links to older version of CUDA and CuDNN, so I list the links chart first.

Package Compatible with Link
CUDA 9.1 self-compiled Tensor Flow Click to download
CUDA 8.0.61 & prior TensorFlow Click to download
CuDNN 6 TensorFlow Click to download
CuDNN 5 & prior Theano, etc Click to download

CUDA is toolkit enables you to all the fun programming with NVIDIA GPU, you’re welcomed unless your GPU is prior to GTX 500 series.

You’re encouraged to download CUDA 8.0.61 and CuDNN 6 in order to drive TensorFlow 1.4, and you’ll find it somewhat time consuming.

Installation is simple a series of ‘Next’s.

And now you can install CuDNN, an acceleration library for CUDA. You’ll require to signed a developer account in order to get it HERE, and then unzip the folders and overwrite folders at

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\8.0

with same names.

Step 3 — Ananconda Environment & Tensorflow

Simply use pip with installation.

Create an Ananconda environment named “tf” using:

>conda create -n tf

And activate the envirionmant by:

>activate tf

Then the command shows:

(tf) C:\Users\username>_

which indicates that you have entered the newly create environment. By using the environment, we can capsule our manuvours within the very space, without influencing that global configuration of the whole system. This is especally useful when you’re testing different versions of same software packages, say, using python 3.5 & 3.6 samultanously.

To install CPU version(required):

(tf) C:\Users\username>conda install tensorflow

Test the CPU version tensorflow:

(tf) C:\Users\username>python
>>>import tensorflow as tf

To install GPU version(optional)

(tf) C:\Users\username>conda install tensorflow-gpu

Restart first and then test the GPU version tensorflow:

(tf) C:\Users\username>python
>>>import tensorflow as tf

Step 4 — Keras

A line of code will do

(tf) C:\Users\username>conda install keras

Keras will be installed with theano by default, but it will use tensorflow as the back-end, so don’t panic, and test if keras is installed correctly by

(tf) C:\Users\username>python
>>>import keras

Now we could run the MNIST example in Keras with either CPU or GPU

Step 5 — Run and switch between CPU and GPU

Download keras testing data sets HERE, or if you have git run

1
git clone https://github.com/fchollet/keras.git

Locate at keras/examples/, and run mnist_mlp.py, if you installed CUDA and CuDNN correctly, it will run on GPU by default, and here’s my running on GPU:

Sadly I only have a M1000M on the laptop, of which the performance is compromised.

 上一篇

python save