Welcome to my GitHub

https://github.com/zq2599/blog_demos

Content: All original articles are categorized and summarized and supporting source code, involving Java, Docker, Kubernetes, DevOPS, etc.;

Overview of this article

  • This article records the process of setting up the TensorFlow2 development environment on the Ubuntu 16.04.7 LTS system for reference when reinstalling in the future
  • The hardware is the 3rd generation of HP Dark Wizard purchased in 2018, the graphics card GTX1060, and the Ubuntu16 LTS desktop version has been installed
  • Before performing this operation, you need to install the Nvidia driver. For details, please refer to "Ubuntu16 Install Nvidia Driver (GTX1060 Graphics Card)"
  • View the driver information, as shown in the figure below, it can be seen that the CUDA version is <font color="red">10.1</font>

在这里插入图片描述

version match

在这里插入图片描述

Install

  • Note: All subsequent operations <font color="red"> do not use the </font>root account
  • Download anaconda3, address: https://www.anaconda.com/products/individual , as shown in the figure below, it can be seen that the Python version corresponding to the latest official version is 3.8, which matches the Python version in the previous TensorFlow version matching table, so just download it The latest version (now it is the <font color="blue">2021.05</font> version)

在这里插入图片描述

  • Due to personal habits, all my operations are remotely SSHed to the Ubuntu16 computer on the MacBook, which is no different from executing the command line locally. You can do whatever you want.
  • Increase executable permissions:
chmod a+x Anaconda3-2021.05-Linux-x86_64.sh
  • run:
bash Anaconda3-2021.05-Linux-x86_64.sh
  • Enter Enter as prompted:

在这里插入图片描述

  • Go through the documentation and enter <font color="blue">yes</font> as required:

在这里插入图片描述

  • Whether to initialize, enter <font color="blue">yes</font>:

在这里插入图片描述

  • The installation is complete:

在这里插入图片描述

  • Log out of ssh and log in again, enter python to enter python in the anaconda environment:
(base) will@ubuntu-hp:~$ python
Python 3.8.8 (default, Apr 13 2021, 19:58:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
  • Create a new conda environment named <font color="blue">py38</font>:
conda create -n py38 python=3.8.8
  • Activate py38:
conda activate py38
  • Install the specified version of tensorflow and specify the domestic source to speed up the download:
pip install tensorflow-gpu==2.3.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
  • Install CUDA:
conda install cudatoolkit=10.1 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/
  • Install cudnn:
conda install cudnn=7.6.5
  • The installation is complete, then verify whether the GPU version of TensorFlow is successfully installed

verify

  • log out of ssh and log in again
  • To see which conda environments are available and which ones are being used, enter the command <font color="blue">conda info --e</font>, as follows, the line where the asterisk is located indicates that the base environment is being used, not that we use py38:
(base) will@ubuntu-hp:~$ conda info --e
# conda environments:
#
base                  *  /home/will/anaconda3
py38                     /home/will/anaconda3/envs/py38
  • Execute <font color="blue">source activate py38</font> to switch to the py38 environment
  • Enter <font color="blue">python</font> directly to enter python interactive mode
  • Import tensorflow:
import tensorflow as tf
  • Shows that the import was successful:
2021-10-08 23:08:55.391471: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
  • The following code means to check whether tensorflow is supported by CUDA, and the support will return True, otherwise it will return false:
tf.test.is_built_with_cuda()
  • The following code means to check whether tensorflow can get the GPU:
tf.test.is_gpu_available()
  • If it can be obtained, it will return to True, and some of the output log information is as follows, which shows that the graphics card information has been successfully obtained:
2021-10-08 23:09:34.367795: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:982] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-08 23:09:34.368110: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1402] Created TensorFlow device (/device:GPU:0 with 5088 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
True
  • As a comparison, the following figure is the execution result of the CPU version of TensorFlow on MabBook:

在这里插入图片描述

  • At this point, the installation is complete.

You are not alone, Xinchen Original is with you all the way

  1. Java series
  2. Spring Collection
  3. Docker series
  4. kubernetes series
  5. database + middleware series
  6. DevOps Series

Welcome to the public number: Programmer Xin Chen

Search "Programmer Xinchen" on WeChat, I am Xinchen, I look forward to traveling the Java world with you...
https://github.com/zq2599/blog_demos

程序员欣宸
147 声望24 粉丝

热爱Java和Docker