Installing TensorFlow on Ubuntu 18.04

Source: Internet
Author: User
Tags git clone pytorch

We will go through several stages of installing the CUDA-9.0,CUDNN and TensorFlow CPUs as well as the TensorFlow GPU version. Finally we will install Pytorch with cuda-9.0. In the Marvel movie The Black Widow's "I fight this war, so you don't have to".

Last night, April 29, 2018, I successfully installed the TensorFlow on Ubuntu 18.04. However, the key to installing TensorFlow is to properly install Cuda and Cudnn Libray, because the run file TensorFlow compiled last night only supports cuda-9.0. Check if this post is outdated. Before we install Cuda-9.0, you may need to change the Ubuntu image source site to the latest version for you. I changed it to mirro.ustc.edu.cn because I was in Hefei, Anhui Province, China. Unlike ubuntu16.04, you need to display the application page to search for software and updates. Then, change the GPU driver to the 390 version that was tested by NVIDIA.

Installing Cuda-9.0

After reading the TensorFlow website, we know we must first install cuda9.0. First Baidu CUDA-9.0,. Then choose Linux, then ubuntu-16.04, and finally download Runfile, which is 1.6 GB, but can be downloaded very quickly.

Before we install runfile, we need to install some dependencies, otherwise you will get a warning like "Missing recommended Libary".

Libray Warning

Install a dependency like this.

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

Next, let's install cuda-9.0 like this.

sudo chmod 777 *.runfile    # give permission to run all the runfile filessudo ./cuda_9.0.176_384.81_linux.run -toolkit -samples -silent -override #

The cuda-9.0 installation path is "/usr/local/cuda-9.0". To avoid missing libray errors, we created a symbolic link "cuda" in this directory in cuda-9.0.

cd /usr/localsudo ln -s /usr/local/cuda-9.0 cuda     # create the symbolic link

We will lower our GCC version before verifying that we install cuda-9.0, otherwise we will get "GCC later than 6 is not supported error".

GCC error

Checking the GCC version on this and Ubuntun 18.04, we decided to lower our GCC version.

--version   # check ubuntu 18.04 gcc version, you will find it‘s 7.3.0sudo apt install gcc-5 g++-5sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50 # you will find that message that tells you the gcc-5 is set to be automatic.sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50 # similiar message as gcc
Set CUDA to environment variable
export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64 ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}
Verifying cuda-9.0 Installation
cd NVIDIA_CUDA-9.0_Samples/5_Simulations/fluidsGLmake clean && make./fluidsGL

If the cuda-9.0 is properly installed, there should be no error message in our production process. Then we can get the fluid simulation.

Fluid Simulation Examples

Our cuda-9.0 has been successfully installed! Before we proceed, we can test the other sample.

Installing cuDNN7.0

Let's install the CUDNN library to speed up our deep learning algorithms. Register, click "Archived CuDNN releases". Then download CuDNN v7.0.5 (Dec 5), for CUDA 9.0 download three files ubuntu16.04 file runtime library. Developer Library, and code samples and user Guide.

sudo dpkg -i libcudnn7_7.0.5.11-1+cuda9.0_amd64.debsudo dpkg -i libcudnn7-dev_7.0.5.11-1+cuda9.0_amd64.debsudo dpkg -i libcudnn7-doc_7.0.5.11-1+cuda9.0_amd64.deb
Installing Freeimage

Before we validate the CUDNN, we must first install the Freeimage Lilbray as a dependency of the MINISTCUDNN sample code. Otherwise, we will be prompted to correctly set the Freeimage.

sudo apt-get install libfreeimage3 libfreeimage-dev
Verifying CUDNN Installation
-r /usr/src/cudnn_samples_v7/ $HOMEcd $HOME/cudnn_samples_v7/mnistCUDNNmake clean && make./mnistCUDNN

If everything is OK, we can get our results-"test pass!" ”

MINISTCUDNN Example

We can also compile other examples.

Installing TENSORLFOW

We will install using VIRUALENV. Install the Libcupti-dev library first.

sudo apt-get install libcupti-devexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64

Then we will install Virtualenv and create a tensorflow environment.

sudo apt-get install python3-pip python3-dev python-virtualenvvirtualenv --system-site-packages -p python3 tensorflow # create a enviroment named tensorflow

It will take a while, please wait patiently.

Installing the TensorFlow CPU version

When the environment is created, we must activate it every time we use TensorFlow. First install TensorFlow CPU version as recommended.

source ~/tensorflow/bin/activatepip3 install --upgrade tensorflow  # install the cpu version
Verifying the TensorFlow CPU version

In the same environment, this means that you will see it in your shell.

(tensorflow)$

Type Python and the following Python code.

python
# Pythonimport tensorflow as tfhello = tf.constant(‘Hello, TensorFlow!‘)sess = tf.Session()print(sess.run(hello))

This is my result. Although it differs from the official verification results, it should be fine.

# # #安装Tensorflow GPU Version First make sure we're in the same environment.

--upgrade tensorflow-gpu

However, the speed of downloading the WHL file is slow. So we can use our own "method" to the browser of the WHL file and the local PIP3 installation.

Verifying the TensorFlow GPU version

Still make sure you're in TensorFlow enviroment.

Type Python and the following Python code.

python
# Pythonimport tensorflow as tfhello = tf.constant(‘Hello, TensorFlow!‘)sess = tf.Session()print(sess.run(hello))

The result is the same. But we can see that our GPU device is working. You can see my GTX 1050 Ti in the test results below.

TensorFlow GPU Verification Installation

We successfully installed the TensorFlow on Ubuntu 18.04. You can test more models on the TensorFlow website, and the Git clone model library is very slow. Therefore, we can also use the "own method" in the browser to download the tensor Flow model library. This is my fisrt example.

Classification of Iris TensorFlow

# #安装Pytorch We will install it using the Package Manager Anaconda recommended by Pytorch. # # #安装Anaconda I'm in Hefei, so I chose the hkust image to download the anaconda installed. sh file. After we installed the Anaconda. We have to change the owner of the "Anaconda3", otherwise we cannot write the file to this directory. We check our user names and user groups.

groups

The first group is usually your current group. This is my result.

My Users group

Because my user group is Bryan, my user name is also Bryan. So I will change the following command to "Chown-r Bryan:brayn Anaconda3". "-R" means an iteration, and this parameter will change the owner of the entire Anacodna3 file.

-R YOUR_GROUp:YOUR_USER_name anaconda3
Change Anaconda Channel

Before installing Pytorch, we can set the Anaconda image source to reduce the wait time. Again, my image source is the hkust image.

--add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/conda config --set show_channel_urls yes

# # #安装Pytorch Then we can go to Pytorch website. Select the Linux,python version for the 3.6,cuda version of 9.0. Please do not execute this command. The latter pytorch means that we will download pytorch from its official website, which is very slow for me. Therefore, replace the last Pytorch with the one that is appropriate for your image source.

-c https://mirrors.ustc.edu.cn/anaconda/cloud/pytorch/
Verify Pytorch

You can try Pytoch the example on Webstie. This is my result.

Pytorch Importing Data

Congratulations on installation success! If you have any questions about this tutorial, please email me.

Original: https://blossomnoodles.github.io/cnBlogs/2018/04/30/Ubuntu18.04-Tensorlow-install.html

Installing TensorFlow on Ubuntu 18.04

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.