Skip to content
Sandeep Krishnamurthy edited this page Jul 13, 2017 · 22 revisions

Table of Contents

  1. Install Keras with MXNet backend
    1. Install Keras Dependencies
    2. Install CUDA and cuDNN
    3. Install Keras
    4. Install MXNet
  2. Configure Keras backend
  3. Validate the Installation

1 Install Keras with MXNet backend

Warning Keras with MXNet backend is still in experimental Alpha phase. You can view the detailed list of known issues and unsupported functionalities in the release notes here.

Steps involved

  1. Install Keras dependencies - Numpy, Nose, TensorFlow and Theano (TensorFlow and Theano are required for running tests)
  2. Install CUDA and cuDNN - This is required only if you are installing on a GPU machine.
  3. Install Keras from source - https://github.com/dmlc/keras
  4. Install MXNet from source - https://github.com/dmlc/mxnet

Note: The following installation instructions are tested on Ubuntu 14.04/16.04 and Mac OS EL Capitan and Sierra.

1.1 Install Keras Dependencies

You need to install pip if not already installed. Then, follow the below installation commands to install Keras dependencies.

    $ pip install numpy
    $ pip install nose
    $ pip install nose-parameterized
    $ pip install Theano

    # Refer https://www.tensorflow.org/install/ for more detailed Tensorflow installation instructions. 
    $ pip install tensorflow  # For CPU machines
OR
    $ pip install tensorflow-gpu # For GPU machines

1.2 Install CUDA and cuDNN

Note: Skip to step 1.3 if you are setting up a CPU machine.

Install the following NVIDIA libraries to setup with GPU support:

  1. Install CUDA 8.0 following the NVIDIA's installation guide.
  2. Install cuDNN 5 for CUDA 8.0 following the NVIDIA's installation guide. You may need to register with NVIDIA for downloading the cuDNN library.

Note: Make sure to add CUDA install path to LD_LIBRARY_PATH.

For Example on Ubuntu machine, if you have downloaded CUDA debian package (cuda-repo-ubuntu1604_8.0.61-1_amd64.deb) and cuDNN 5.1 library (cudnn-8.0-linux-x64-v5.1.tgz), below are set of commands you run to setup CUDA and cuDNN.

#  Setup CUDA 8.0.
$  sudo apt-get update
$  sudo apt-get install build-essential
$  sudo apt-get install linux-headers-$(uname -r)
#  Assuming you have downloaded CUDA deb package from https://developer.nvidia.com/cuda-downloads
$  sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
$  sudo apt-get update
$  sudo apt-get install cuda

$  export CUDA_HOME=/usr/local/cuda-8.0
$  PATH=${CUDA_HOME}/bin:${PATH}
$  export PATH
$  export LD_LIBRARY_PATH=/usr/local/cuda/lib64/:$LD_LIBRARY_PATH

#  Setup cuDNN 5.1 for CUDA 8.0.
#  Assuming you have registered with NVIDA and downloaded cuDNN 5.1 for CUDA 8 from https://developer.nvidia.com/cudnn
$  tar -xvzf cudnn-8.0-linux-x64-v5.1.tgz
$  sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
$  sudo cp cuda/lib64/* /usr/local/cuda/lib64/

You can verify your CUDA setup with following commands.

$  nvcc --version
$  nvidia-smi

1.3 Install Keras from source

    # Clone keras repo to ~/keras directory
    $ git clone https://github.com/dmlc/keras.git ~/keras --recursive
    # Install Keras
    $ cd ~/keras
    $ sudo python setup.py install

1.4 Install MXNet from source

Note You need to install MXNet from latest source code to get Keras working with MXNet backend.

Go to MXNet Installation guide, choose "Linux or MacOS", choose "Python", choose "CPU or GPU", choose "Build from Source" and follow the installation guide to build and install MXNet with Python bindings.

2 Configure Keras backend

You should set Keras backend to 'mxnet' to run your Keras code with MXNet backend. You can either set the environment variable or edit the keras config file.

Option 1 Set the environment variable

    $ export KERAS_BACKEND=mxnet

Option 2 Edit the keras config file

Open "~/.keras/keras.json" file and set "backend=mxnet".

3 Validate the Installation

You can validate the installation by trying to import Keras in Python terminal and verifying that Keras is using mxnet backend.

    $ python
    >>> import keras as k
        Using mxnet backend
Clone this wiki locally