Installation

TensorLayer has some prerequisites that need to be installed first, including TensorFlow , numpy and matplotlib. For GPU support CUDA and cuDNN are required.

If you run into any trouble, please check the TensorFlow installation instructions which cover installing the TensorFlow for a range of operating systems including Mac OX and Linux, or ask for help on hao.dong11@imperial.ac.uk.

Step 1 : numpy and matplotlib

TensorLayer is build on the top of Python-version TensorFlow, so please install Python first.

Note

We highly recommend python3 instead of python2 for the sake of future.

Python includes pip command for installing additional modules is recommended. Besides, a virtual environment via virtualenv can help you to manage python packages.

Take Python3 on Ubuntu for example, to install Python includes pip, run the following commands:

sudo apt-get install python3
sudo apt-get install python3-pip
sudo pip3 install virtualenv

To build a virtual environment and install matplotlib and numpy into it, run the following commands: (Alternatively, go to Step 3, automatically install the prerequisites by TensorLayer)

virtualenv env
env/bin/pip install matplotlib
env/bin/pip install numpy

Check the installed packages, run the following command:

env/bin/pip list

After that, you can run python script by using the virtual python as follow.

env/bin/python *.py

Step 2 : TensorFlow

The installation instructions of TensorFlow are written to be very detailed on TensorFlow website. However, there are something need to be considered. For example, TensorFlow only officially supports GPU acceleration for Linux and Mac OX at present.

Warning

For ARM processor architecture, you need to install TensorFlow from source.

Step 3 : TensorLayer

The simplest way to install TensorLayer is as follow, it will also install the numpy and matplotlib automatically.

pip install tensorlayer
or
pip install git+https://github.com/zsdonghao/tensorlayer.git

However, if you want to modify or extend TensorLayer, you can download the repository from Github and install it as follow.

cd to the root of the git tree
pip install . -e

This command will run the setup.py to install TensorLayer. The -e reflects editable, then you can edit the source code in tensorlayer folder, and import the edited TensorLayer.

Step 4 : GPU support

Thanks to NVIDIA supports, training a fully connected network on a GPU, which may be 10 to 20 times faster than training them on a CPU. For convolutional network, may have 50 times faster. This requires an NVIDIA GPU with CUDA and cuDNN support.

CUDA

The TensorFlow website also teach how to install the CUDA and cuDNN, please see TensorFlow GPU Support.

Download and install the latest CUDA is available from NVIDIA website:

If CUDA is set up correctly, the following command should print some GPU information on the terminal:

python -c "import tensorflow"

cuDNN

Apart from CUDA, NVIDIA also provides a library for common neural network operations that especially speeds up Convolutional Neural Networks (CNNs). Again, it can be obtained from NVIDIA after registering as a developer (it take a while):

Download and install the latest cuDNN is available from NVIDIA website:

To install it, copy the *.h files to /usr/local/cuda/include and the lib* files to /usr/local/cuda/lib64.