The below instructions should have you set up with both Keras 1.2.2 and theano 0.9 on Windows 8.1 in 30 minutes or less, depending on the speed of your internet connection. I can confirm that this set up is suitable for all the lessons in the fantastic Practical Deep Learning For Coders, Part 1, course.
The only requirements are:
- A suitable Nvidia GPU.
- Installation of Visual Studio Community 2013.
- Installation of the CUDA 8.0 Toolkit.
- Anaconda2, Python 2.7 version.
- Nvidia cuDNN v5.1.
Providing you have a suitable Nvidia GPU and you have installed both Visual Studio Community 2013 and the CUDA 8.0 Toolkit you are ready to proceed onto the next steps.
Install Anaconda 2 and bcolz
- Install Anaconda 2 to your user directory. If you have spaces in your user directory name, then I would suggest installing it somewhere with no spaces in the path, for example C:\Anaconda2\
- Start the Anaconda Prompt, install bcolz (for use in the fast.ai course) and then update all packages.
conda install -y bcolz
conda upgrade -y --all
Install Nvidia cuDNN
- Extract the contents of the cudnn-8.0-windows7-x64-v5.1.zip archive to its current directory.
- This should extract to a cudnn-8.0-windows7-x64-v5.1 directory inside the current directory. Copy the contents (bin, include and lib directories) from
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\.
This will copy all the required cuDNN files into the bin, include and lib directories, inside your CUDA 8.0 install.
Install theano 0.9 and verify that it is using the GPU
- Install dependencies
conda install -y numpy scipy mkl-service libpython m2w64-toolchain nose nose-parameterized sphinx pydot-ng
- Install theano and pygpu
conda install -y theano pygpu
- Create a .theanorc file in your user directory (e.g. C:\Users\USER_FOLDER_WITHOUT_SPACES\.thanorc) and add the following to
device = gpu
floatX = float32
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
enabled = True
include_path=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include
library_path=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64
The easiest way to do this, because windows explorer won’t let you create a .theanorc file, is to open up notepad, copy the above text and save with “Save as type” set to “All Files (*.*)”, alternatively you can download from here.
- Test your install is using the GPU by running the code provided by the theano team. The output when run through the anaconda prompt should resemble the below, to verify that theano is using the GPU you want to see the text “Used the gpu”.
Install and test Keras 1.2.2
The instructions below will install an older version of Keras, the current version at present is 2.0.6. 1.2.2 is the version which the fast.ai course was constructed to use, and hence the most widely tested. If you want to install the latest version instead then skip this section and go to Installing the current version of Keras.
- Install Keras 1.2.2
pip install keras==1.2.2
- Create a .keras directory inside your user directory (e.g. C:\Users\USER_FOLDER_WITHOUT_SPACES\.keras). The easiest way to do this, because windows explorer won’t let you create a folder starting with a “.” is from the command prompt:
- Press the windows key + r and type in cmd.
- This will land you in your user directory so all you need to do is create the directory by typing
- Press the windows key + r and type in cmd.
- Create a keras.json file inside the newly created .keras folder and add the following.
Alternatively you can download the .keras folder from here.
- Test your Keras install with the training example shown below.
from keras.models import Sequential
from keras.layers import Dense, Activation
import numpy as np# For a single-input model with 2 classes (binary classification):
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
# Generate dummy data
data = np.random.random((1000, 100))
labels = np.random.randint(2, size=(1000, 1))
# Train the model, iterating on the data in batches of 32 samples
model.fit(data, labels, epochs=10, batch_size=32)
If everything is installed correctly the output from the above code should be similar to the below.
Start the Practical Deep Learning For Coders, Part 1 course
- Download or clone the course material to your user directory.
jupyter notebookin the Anaconda prompt and enjoy the course.
Installing the current version of Keras
The latest version of Keras is not guaranteed to work with all the lessons from the Practical Deep Learning For Coders, Part 1 course, however with the changes below I have not had any errors, only warnings regarding API changes.
- Install the latest version of Keras.
pip install keras
- Change the following in utils.py
from keras.regularizers import l2, activity_l2, l1, activity_l1
from keras.regularizers import l2, l1
from keras.utils.layer_utils import layer_from_config
from keras.layers import deserialize as layer_from_config
return np.concatenate([batches.next() for i in range(batches.nb_sample)])
return np.concatenate([batches.next() for i in range(batches.n)])
- Change the below in your keras.json file
- The number of steps in calls to fit_generator, predict_generator and evaluate_generator has changed from the number of images to the number of batches. For example in lesson 3 where you previously had
trn_features = conv_model.predict_generator(batches, batches.nb_sample)
you would now put
trn_features = conv_model.predict_generator(batches, batches.n/batches.batch_size)
If you have any comments and/or problems then please let me know.