Deep Learning Library packages Theano, Lasagne, and TensorFlow support GPU installation in Ubuntu

Source: Internet
Author: User
Tags theano gtx

Deep Learning Library packages Theano, Lasagne, and TensorFlow support GPU installation in Ubuntu

With the popularity of deep learning, more and more people begin to use deep learning to train their own models. GPU training is much faster than the CPU, allowing models that require one week of training to be completed within one day. This post explains how to install Theano, Lasagne, TensorFlow trained with GPU on Ubuntu14.04.

  • Anaconda
    • Install
    • Use
  • GPU Configuration
    • Install CUDA
    • Install cuDNN
  • Theano
    • Install
    • GPU environment variable settings
    • GPU running test
  • Lasagne
    • Install
    • Tutorial
  • TensorFlow
    • Install
      • CPU only
      • GPU enabled
    • GPU environment variable settings
    • Simple Test
    • TensorBoard
      • Tracking Data
      • Analysis Model
    • Tutorial
Anaconda

Since many python library packages will be used, it is very convenient to install Anaconda.

Install

After the download is complete, run the command and install it in the directory you want to install as prompted.
>sudo bash Anaconda2-2.5.0-Linux-x86_64.sh

If you encounterError: Missing write permissions in: */anaconda2
You don't appear to have the necessary permissions to update packages
into the install area */anaconda2

Run the following command to change the group to solve the problem (replace usr and */with your own content)
>sudo chown -R usr */anaconda2

Use

All commands can be found in Using conda.
Several Common commands are listed here.

  • Update conda
    >conda update conda
  • Show available packages
    >conda list
  • Install package from conda
    >conda install package-name
  • If no conda exists, search for it from anaconda.org and enter the displayed command.
    >conda install -c channel package-name
  • Delete a package
    >conda remove package-name
  • Update package
    >conda update package-name
GPU configuration and installation of CUDA

CUDA download (network installation will be selected in this article)

Run
>sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
>sudo apt-get update
>sudo apt-get install cuda(Time consumed)
The parallel computing module with cuda can use GPU to train Theano's model.

Install cuDNN

Theano also supports cuDNN (optional), while Tensorflow requires cuDNN

CuDNN download (registration required). After the download is complete, run
>tar xvzf cudnn-7.0-linux-x64-v4.0-prod.tgz
>sudo cp cuda/include/cudnn.h /usr/local/cuda/include
>sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
>sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

Theano

Theano has a high degree of control over the model and is favored by researchers.

Install

>sudo apt-get install g++ libopenblas-dev
>conda install git
>pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git

You can also search from anaconda.org

GPU environment variable settings

>export CUDA_ROOT=/usr/local/cuda-7.5/
>export PATH=$PATH:$CUDA_ROOT/bin
>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_ROOT/lib64
>export THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32,allow_gc=False
>export CUDA_LAUNCH_BLOCKING=1

Note that the GPU only supports float32 data. To increase the speed, you must convert the data type to float32.

GPU running test
from theano import function, config, shared, tensor, sandboximport numpyimport timevlen = 10 * 30 * 768  # 10 x #cores x # threads per coreiters = 1000rng = numpy.random.RandomState(22)x = shared(numpy.asarray(rng.rand(vlen), config.floatX))f = function([], tensor.exp(x))print(f.maker.fgraph.toposort())t0 = time.time()for i in range(iters):    r = f()t1 = time.time()print("Looping %d times took %f seconds" % (iters, t1 - t0))print("Result is %s" % (r,))if numpy.any([isinstance(x.op, tensor.Elemwise) and              ('Gpu' not in type(x.op).__name__)              for x in f.maker.fgraph.toposort()]):    print('Used the cpu')else:    print('Used the gpu')

CPU result:

[Elemwise{exp,no_inplace}(<TensorType(float64, vector)>)]Looping 1000 times took 3.060987 secondsResult is [ 1.23178032  1.61879341  1.52278065 ...,  2.20771815  2.29967753  1.62323285]Used the cpu

GPU results:

Using gpu device 0: GeForce GTX 980 Ti (CNMeM is disabled, CuDNN 4007)[GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>), HostFromGpu(GpuElemwise{exp,no_inplace}.0)]Looping 1000 times took 0.208453 secondsResult is [ 1.23178029  1.61879349  1.52278066 ...,  2.20771813  2.29967761  1.62323296]Used the gpu
Lasagne Installation

Lasagne is a library package written on Theano, which makes it easier for users to use deep learning training.
The version Lasagne 0.2.dev1 will be installed here.
>conda install -c http://conda.anaconda.org/toli lasagne

Tutorial

Here are simple ipython tutorials for Lasagne tutorial and Lasagne tutorial.

TensorFlow

TensorFlow is a deep learning package open-source by Google. It is similar in concept to Theano, which generates computational graph and can be automatically derived. Although TensorFlow is more concise than Theano, however, the model structure cannot be controlled as well as Theano. The current GPU version is still in memory usage. In general, it is very "young ". However, it has a strong background. This makes people very much look forward to coming versions.

Install CPU only

>pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl

GPU enabled

>pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl

When you encounter the following problems:
Cannot remove entries from nonexistent file /usr/local/bin/anaconda2/lib/python2.7/site-packages/easy-install.pth
Run the command. After deletion, setuptools will run again.
>conda remove setuptools

GPU environment variable settings

>export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64
>export CUDA_HOME=/usr/local/cuda

Simple Test
import tensorflow as tfhello = 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

During this period, you will see similar information

Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 980 Ti, pci bus id: 0000:01:00.0)

TensorBoard

The user-friendly feature is that TensorBoard can automatically generate the following interactive interface, allowing users to better track data and analyze their own models.

Tracking Data

Analysis Model

Tutorial

There are also many tutorials available on the official website.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.