Ubuntu 16.04 LTS tensorflow-cpu/cuda9.0 + Cudnn7.0 + tensorflow1.5-gpu_ environment configuration

Source: Internet
Author: User
Tags virtualenv cuda toolkit
Before outlining this tutorial for Ubuntu 16.04 Tensorflow-gpu or a CPU version installation, be sure to perform a 1.1.1 operation to verify that your video card is Nividia and supports GPU computing. If you do not support GPU operations, you can only install the TENSORFLOW-CPU version, skipping the 1, 2, 3 headings directly, from 4. Virtualenv + Tensorflow1.5, and choose to install CPU version Note ... When installing Cuda and CUDNN, do not install the latest version, all in accordance with the version of this article installed.

1. NVIDIA CUDA Toolkit 9.0 1.1 Pre-installation Actions 1.1.1 Verify The system has a cuda-capable GPU.

Type the following at the command line to get the information of your graphics card

$ LSPCI | Grep-i nvidia

If your graphics card are from NVIDIA and it are listed in, your The GPU is cuda-capable.

1.1.2 Verify The system is running a supported version of Linux.

The CUDA Development Tools are only supported on some specific distributions of Linux. These are listed in the CUDA Toolkit release notes.

To determine which distribution and release number for your ' re running, type the following at the command line:

$ uname-m && cat/etc/*release

You are should the similar to the following, modified for your particular system:

x86_64
Red Hat Enterprise Linux Workstation Release 6.0 (Santiago)

The x86_64 line indicates your are running on a 64-bit system. The remainder gives information about your distribution.

1.1.3 Verify The system has GCC installed.

To verify the version of GCC installed on your system, type the following on the command line:

$ gcc--version

If An error message displays, your need to install the development tools from your Linux distribution or obtain a version O F GCC and its accompanying toolchain from the Web.

1.1.4 Verify The system has the correct kernel headers and development packages.

The kernel headers and development packages for the currently running kernel can is installed with:

$ sudo apt-get install linux-headers-$ (uname-r)



1.2 Install 1.2.1 Download CUDA Toolkit 9.0

CUDA Toolkit 9.0 Downloads



1.2.2 Install the CUDA Toolkit 9.0

$ cd ~/downloads
$ sudo dpkg-i cuda-repo-ubuntu1604_9.0.176-1_amd64.deb
$ sudo apt-key adv--fetch-keys http://d Eveloper.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install Cuda


1.3 post-installation Actions

$ export Path=/usr/local/cuda-9.0/bin${path:+:${path}}
$ export ld_library_path=/usr/local/cuda-9.0/lib64\
                         ${ld_library_path:+:${ld_library_path}}
Reboot to update environment variables


2. CUDNN v7.0 2.1 Download

To download the CUDNN, click here

The download of CUDNN requires membership of the NVIDIA Developer program,so you need to create your account I N Login.

Do not choose the latest version

Choose the v7.0.5 for CUDA 9.0

Download Runtime, Developer, Code Samples


2.2 Install

$ cd ~/downloads 
$ sudo dpkg-i libcudnn7_7.0.5.15-1+cuda9.0_amd64.deb
$ sudo dpkg-i libcudnn7-dev_7.0.5.15-1+ Cuda9.0_amd64.deb
$ sudo dpkg-i libcudnn7-doc_7.0.5.15-1+cuda9.0_amd64.deb


2.3 Verifying

To verify so CUDNN is installed and are running properly, compile the MNISTCUDNN Copy the CUDNN sample to a writable path .

$ cp-r/usr/src/cudnn_samples_v7/$HOME
Go to the writable path.
$ cd $HOME/CUDNN_SAMPLES_V7/MNISTCUDNN
Compile the MNISTCUDNN sample.
$ make clean && make
Run the MNISTCUDNN sample.
$./mnistcudnn

If Cudnn is properly installed and running in your Linux system, you'll have a
Message similar to the following:

Test passed!


3. Virtualenv + Tensorflow1.5 3.1 Install The virtualenv issue one of the following commands to install Pip and virtualenv:

$ sudo apt-get install Python3-pip python3-dev python-virtualenv
Issue one of the following commands to create a virtualenv environment:

TargetDirectory is used to specify the top-level directory for the virtualenv tree. Our instructions assume that TargetDirectory is ~/tensorflow, but you can select any directory.

3.2 Source The virtualenv in order to avoid each activation of the input Long command, we use TensorFlow to replace the "source ~/tensorflow/bin/activate." Open ~/.BASHRC File

$ sudo gedit ~/.BASHRC
Append a row to the last line of the file, and then save and close the file
Alias tensorflow= "Source ~/tensorflow/bin/activate"
Methods of updating environment variables without restarting
$ source ~/.BASHRC
Issue one of the following commands to activate the VIRTUALENV environment:
$ tensorflow
After you execute the source command above, your prompt should change to the following to indicate success


3.3 Install The TensorFlow

Issue one of the following commands to install in an active virtualenv environment

TENSORFLOW-CPU version (without installing Cuda and CUDNN)

(tensorflow) $ sudo pip3 install--upgrade tensorflow
Tensorflow-gpu version (need to install Cuda and CUDNN)
(tensorflow) $ sudo pip3 install--upgrade Tensorflow-gpu


4.3 Verifying the TensorFlow

$ tensorflow
(tensorflow) $ Python3
>> import tensorflow as tf
>> hello = tf.constant (' Hello, tensorflow! ')
>> sess = tf. Session ()
>> print (Sess.run (hello))

If the system outputs the following, you can start writing the TensorFlow program:

Hello, tensorflow!.

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.