文栏 - 信息技术 - 浏览文章 - Installing cuDNN 5.x, Theano, Keras and TensorFlow on CentOS (Tested on 6.6, 7.2)
Installing cuDNN 5.x, Theano, Keras and TensorFlow on CentOS (Tested on 6.6, 7.2)
发布时间: 2016/5/22 11:14:46 作者: 素素 出处: 本站发布

Updated Time: Oct 7, 2016

Install Anaconda

Better login with the user of running our services and give it sudo permission for installation.

Go to this page https://www.continuum.io/downloads. Download the latest version of Anaconda Installation.

Tested Version: Anaconda2-4.2.0-Linux-x86_64.sh Link: https://repo.continuum.io/archive/Anaconda2-4.2.0-Linux-x86_64.sh

Create ml-items folder, download Anaconda2 and run it.

# mkdir /opt/ml-items
# cd /opt/ml-items/
# wget https://repo.continuum.io/archive/Anaconda2-4.2.0-Linux-x86_64.sh
# bash Anaconda2-4.2.0-Linux-x86_64.sh

Options

Do you approve the license terms? [yes|no] yes

Anaconda2 will now be installed into this location: /root/anaconda2

  • Press ENTER to confirm the location
  • Press CTRL-C to abort the installation
  • Or specify a different location below

[/root/anaconda2] >>> /opt/anaconda2

Do you wish the installer to prepend the Anaconda2 install location to PATH in your /root/.bashrc ? [yes|no] no

end Options

Login in with the user of running our services.

# vi ~/.bashrc

Add the following line to the end of the file has not this line. This line ensures using Anaconda to replace the system Python.

export PATH="/opt/anaconda2/bin:$PATH"

Check points

Relogin, enter:

# python

You should see something like:

Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jul 2 2016, 17:42:40)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

Anaconda is brought to you by Continuum Analytics.

Please check out: http://continuum.io/thanks and https://anaconda.org

end Check points

Install Theanno

Go to this page https://github.com/Theano/Theano/releases. Download the lasest version of release.

Tested Version: rel-0.8.2 Link: https://github.com/Theano/Theano/archive/rel-0.8.2.zip

Download the file to /opt/ml-items, unzip it and install it using develop mode. Develop mode can be uninstalled easily.

# wget https://github.com/Theano/Theano/archive/rel-0.8.2.zip
# unzip rel-0.8.2
# cd Theano-rel-0.8.2
# python setup.py develop        // python setup.py develop --uninstall

Create a new file $HOME/.theanorc , copy the following content into the file.

[global]
floatX = float32
device = gpu

[lib]
cnmem = 0.2

Check points, run the following code. It should not print error messages and show gpu is using.

# python
# import theano
# print theano.config.blas.ldflags
# print theano.config.device

end Check points

Install cuDNN

Go to this page https://developer.nvidia.com/rdp/cudnn-download. Register a account and wait for one or two days. Download cudnn-7.5-linux-x64-v5.1.tgz

# cd /opt/cuda-items

Transfer the cudnn-7.5-linux-x64-v5.1.tgz to /opt/cuda-items , unzip the file.

# tar zxvf cudnn-7.5-linux-x64-v5.1.tgz

Move all files in include subfolder and lib64 subfolder to the /opt/cuda-items/cuda folder.

# cd cuda
# mv ./include/*.* ./
# mv ./lib64//*.* ./

Add the following content to end of ~/.bashrc .

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/cuda-items/cuda:
export LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/cuda-items/cuda:
export CPATH=$CPATH:/opt/cuda-items/cuda:

Check Points, relogin, run the folowing commands, above paths should be seen.

# echo $CPATH
# echo $LD_LIBRARY_PATH
# echo $LIBRARY_PATH

Check cuDNN available, run the following commands, you should see something like Using gpu device 0: GeForce GTX TITAN X (CNMeM is enabled with initial size: 20.0% of memory, cuDNN 5103) . Some warnings about the version might be seen. It does not matter.

# python
# import theano

end Check Points

Install Keras

Go to this page https://github.com/fchollet/keras/releases. Download the lasest version release. Tested Version: 1.0.5 Link: https://github.com/fchollet/keras/archive/1.0.5.zip

Download the file to /opt/ml-items, unzip it and install it using develop mode. Develop mode can be uninstalled easily.

# cd /opt/ml-items/
# wget https://github.com/fchollet/keras/archive/1.0.5.zip
# unzip 1.0.5.zip
# cd keras-1.0.5
# python setup.py develop

Switching to use Theano backend. Open Keras configuration file.

# vi ~/.keras/keras.json

Change "backend": "tensorflow" to "backend": "theano".

Check points, run Keras examples

# cd /opt/ml-items/keras-1.0.5/examples
# python mnist_cnn.py

end Check points

Install pydot

Pydot is used to plotting model. It may be invoked by Caffe, etc.

# conda install pydot

Anaconda will automatically downgrade pyparsing version. In your python code, it should not show error messages.

import pydot

Install TensorFlow

Tested Version: 0.10.0

Installation Steps

Create a conda environment called tensorflow. The Anaconda environment installation of TensorFlow will not override pre-existing version of the Python packages needed by TensorFlow.

# conda create -n tensorflow python=2.7

Activate tensorflow environment.

$ source activate tensorflow
(tensorflow)$  # Your prompt should change

Select the correct binary to install. Ubuntu/Linux 64-bit, GPU enabled, Python 2.7, Requires CUDA toolkit 7.5 and cuDNN v5. cuDNN v5 is support offically and cuDNN v5.1 is also OK by our test.

(tensorflow) # export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl

Install using pip

# pip install --ignore-installed --upgrade $TF_BINARY_URL

Usage

With the conda environment activated, you can now test your installation.

When you are done using TensorFlow, deactivate the environment.

(tensorflow)$ source deactivate

$  # Your prompt should change back

To use TensorFlow later you will have to activate the conda environment again:

$ source activate tensorflow
(tensorflow)$  # Your prompt should change.

# Run Python programs that use TensorFlow.
...
# When you are done using TensorFlow, deactivate the environment.
(tensorflow)$ source deactivate

Install IPython and other packages

To use tensorflow with IPython it may be necessary to install IPython into the tensorflow environment:

$ source activate tensorflow
(tensorflow)$ conda install ipython

Similarly, other Python packages like pandas may need to get installed into the tensorflow environment before they can be used together with tensorflow.

Test the installation

Open a terminal and type the following:

$ python
...
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>>

Run a TensorFlow demo model. Use -m to find the program in the python search path. The program will download the MNIST dataset at the first time without showing progress. Be patient.

(tensorflow)$ python -m tensorflow.models.image.mnist.convolutional
所属分类: 信息技术   所属专题: 原创
共有 42699 人次浏览

相关文章
    icon icon
    朋友2018/2/10 5:43:10 认为:
    https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl should be

    Python 2.7

    CPU only:

    https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.5.0-cp27-none-linux_x86_64.whl

    GPU support:

    https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.5.0-cp27-none-linux_x86_64.whl
    评论作者:
    电子邮件:
    评论内容:
    投票评价:
    验 证 码:
    图片包含4个随机字符,点击刷新
    请输入上面图片中的随机字符