Project 3: Keras Installation Notes
Compute Facilities
Using the CS account that was created for you, you should be able to ssh to power1.cs.virginia.edu
through power5.cs.virginia.edu
, or using the CSLAB CS account, you should be able to ssh to labunix01.cs.virginia.edu
through labunix03.cs.virginia.edu
. There is also the Rice 340 lab, and AWS educate. These may have more compute than your laptop especially if you have an older model.
Installing with TensorFlow Backend (CPU Mode) as Root/Superuser
Run the following from the command-line:
pip install tensorflow (on Mac/Linux, sudo pip)
pip install keras (on Mac/Linux, sudo pip)
For GPU installation you will have to see the TensorFlow/Theano installation instructions.
Installing with Theano Backend (CPU Mode) as Root/Superuser
Run the following from the command-line:
pip install --no-deps git+git://github.com/Theano/Theano.git (on Mac/Linux, sudo pip)
pip install keras (on Mac/Linux, sudo pip)
The first line installs Theano (a version of >= 0.9 is needed for keras, which is why the git repo is used). If you have an existing Theano to upgrade you can supply the --upgrade flag to the first line.
Try to import keras from Python. It complains about no TensorFlow because the default backend is TensowFlow. Edit in your home/user directory the .keras/keras.json to change the backend from TensorFlow to Theano as described here.
Installing Keras on Linux Machines as an Ordinary User
If you have root (superuser) access then you can run the commands at the top of this page to install Keras. However, in multi-user systems you may not have root access. Thus, you can use this alternative install process to place the libraries in your user directory:
$ pip install --install-option="--prefix=`pwd`/project3_libs" keras theano
$ echo `pwd`/project3_libs
(Prints out PROJECT3_LIB_DIR, the directory where your project 3 libraries are)
- Use
pico .bash_profile
(or nano
, or another editor you prefer) to edit .bash_profile
as follows (replace PROJECT3_LIB_DIR with the appropriately printed path from the previous step):
PYTHONPATH="${PYTHONPATH}:PROJECT3_LIB_DIR"
export PYTHONPATH
Use Ctrl+W to write, Ctrl+X to exit.
For the Labunix systems, also add the following additional line to .bash_profile, to tell it where the linear algebra library is:
export THEANO_FLAGS='blas.ldflags=-lblas -lgfortran'
- Import your newly modified
.bash_profile
file to gain access to your installed Keras library (when you log in for future sessions, it will automatically be sourced):
$ source .bash_profile
$ python
>>> import keras
The above import should complain about the TensorFlow backend not being able to be found.
- Edit
.keras/keras.json
to change the backend to theano.
$ python
>>> import keras
The above import should succeed now.
Running Examples
Clone the keras repo into some local directory on your machine.
Go to the examples directory and try running python mnist_cnn.py
, which trains a convolutional neural network on the MNIST dataset.