深入理解tensorflow人工智能与机器学习TensorFlow技术帖

Install tensorflow-1.8 in ubuntu

2018-05-05  本文已影响240人  璟的简书

Introduction

According to the tensorflow website(www.tensorflow.org), you can install tensorflow step by step.

If you can not go to the tensorflow website, you can download the lantern VPN.

After download lantern-installer-64-bit.deb by link, you can run the command below for installation:

$ cd ~/Downloads
$ sudo dpkg -i lantern-installer-64-bit.deb

Content

Install tensorflow has 7 steps:

  1. install CUDA
  2. install cnDNN
  3. install Anaconda
  4. set environment variables
  5. create virtual environment of Python
  6. install Tensorflow
  7. validate the installation

1. install CUDA 9.0

  • CUDA Toolkit 9.0. For details, see NVIDIA's documentation. Ensure that you append the relevant CUDA pathnames to the LD_LIBRARY_PATH environment variable as described in the NVIDIA documentation.

Steps:
Download website --> legacy releases --> CUDA Toolkit 9.0 --> linux --> x86_64 --> ubuntu --> 16.04 --> runfile(local) --> install Base Installer --> install Patch 1 --> install Patch 2

Details:
(a) install Base Installer: sudo sh cuda_9.0.176_384.81_linux.run
(b) install Patch 1: sudo sh cuda_9.0.176.1_linux.run
(c) install Patch 2: sudo sh cuda_9.0.176.2_linux.run

Validation:

$ cd /usr/local/cuda-9.0/samples/5_Simulations/nbody 
$ sudo make
$ ./nbody

If you can see a new window popped up with animation, you install CUDA 9.0 success!

We add the environment variable after cuDNN installed.

2. install cuDNN

Steps:
Download website --> register an new account --> cudnn-download
--> Download cuDNN v7.1.3 (April 17, 2018), for CUDA 9.0
--> cuDNN v7.1.3 Runtime Library for Ubuntu16.04 (Deb)
--> install cuDNN deb package

Details:
(a) install cuDNN deb package: sudo dpkg -i libcudnn7_7.1.3.16-1+cuda9.0_amd64.deb

3. install Anaconda

Anaconda is the python environment. We can install tensorflow in Anaconda virtual environment as it is install and uninstall easliy. Besides, Anaconda contains most common python packages, so that we need not install by ourselves.

Download website --> Select Python 2.7
--> download package Anaconda2-5.1.0-Linux-x86_64.sh
--> install by command: $ sudo sh Anaconda2-5.1.0-Linux-x86_64.sh

4. set environment variables

We should put the cuda, cudnn and anaconda path to the environment variables.

Steps:
(1) open the environment variable file.

$ sudo gedit ~/.bashrc

(2) copy the below 4 lines to the end of .bashrc file (Please replace the your_name in the path).

. /home/your_name/anaconda2/etc/profile.d/conda.sh
export CUDA_HOME=/usr/local/cuda
export PATH="$PATH:/usr/local/cuda-9.0/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64:/usr/local/cuda/extras/CUPTI/lib64"

5. create virtual environment of Python

Create a conda environment named "xxx" (e.g. tensorflow) to run a version of Python by invoking the following command:

$ conda create -n tensorflow python=2.7[or python=3.3, etc.]

Then you can go into the virtual environment by commands below:

# Activate the conda environment by issuing the following command:
$ source activate tensorflow 
(tensorflow)$  

# If you want go out of current prompt
$ source deactivate

6. install Tensorflow

Issue a command of the following format to install TensorFlow inside your conda environment:

(tensorflow)$ pip install --ignore-installed --upgrade [tfBinaryURL]

My [tfBinaryURL] is:
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp27-none-linux_x86_64.whl

You also can choose one tfBinaryURL from the website below:
https://www.tensorflow.org/install/install_linux#the_url_of_the_tensorflow_python_package

7. validate the installation

Run a short TensorFlow program

Invoke python from your shell as follows:

$ python

Enter the following short program inside the python interactive shell:

# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

If the system outputs the following, then you are ready to begin writing TensorFlow programs:

Hello, TensorFlow!

If the system outputs an error message instead of a greeting, see Common installation problems.

Tensorflow installation end

上一篇下一篇

猜你喜欢

热点阅读