Ubuntu18.04下GPUバージョンTensorflow 2.0+CUDA10.0/Tensorflow2.1+CUDA10.1仮想環境構成


バージョンマッチングの問題に注意してください.Tensorflow 2を測定します.0+CUDA10.0とTensorflow 2.1+CUDA10.1この2つの組み合わせのGPUバージョンは問題ありません.私はインストール中、CUDA 10がインストールされているためです.1、Tensorflow 2をインストールします.0以降テストエラーGPUは使用できません.2.0バージョンをアンインストールした後、2.1バージョンを再インストールしました.Anacondaのインストールは便利ですが、Ubuntuシステムではシステム環境変数と競合しやすく、以前の使用中に体験が悪かったのでvirtualenvを選択して隔離インストールを行います.
注:デュアルシステムでドライバがインストールされていない場合は、次のチュートリアルに従ってドライバをインストールすることをお勧めします.ドライバが既にインストールされていて、正常に電源を入れることができる場合は、スキップしてください.デュアルシステムシステムシステムのカード死防止インストールグラフィックスドライブ
以下参照:How to install TensorFlow 2.0 on Ubuntu
## 1.依存ライブラリ1.1更新システムのインストール
sudo apt-get update
sudo apt-get upgrade

1.2コンパイルツールのインストール
sudo apt-get install build-essential cmake unzip pkg-config
sudo apt-get install gcc-6 g++-6

1.3 screenをインストールし、同じウィンドウで複数の端末のツールを使用し、リモートSSH接続に使用できます.
sudo apt-get install screen

1.4 install X windows libraries and OpenGL libraries:
sudo apt-get install libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev

1.5 Along with image and video I/O libraries:
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev

1.6 install optimization libraries:
sudo apt-get install libopenblas-dev libatlas-base-dev liblapack-dev gfortran

1.7 HDF5 for working with large datasets:
sudo apt-get install libhdf5-serial-dev

1.8 Python 3 development libraries including TK and GTK GUI support:
sudo apt-get install python3-dev python3-tk python-imaging-tk
sudo apt-get install libgtk-3-dev

2グラフィックスドライブとCUDAのインストール

        

グラフィックスドライブがインストールされている場合は、最初の2.1~2.5をスキップできます.2.1 add an apt-get repository so that we can install NVIDIA GPU drivers.
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update

2.2 install your NVIDIA graphics driver:
sudo apt-get install nvidia-driver-418

2.3 reboot command and wait for your system to restart:
sudo reboot now

2.4 both download and install CUDA 10.0 right from your terminal
cd ~
mkdir installers
cd installers/
wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux
mv cuda_10.0.130_410.48_linux cuda_10.0.130_410.48_linux.run
chmod +x cuda_10.0.130_410.48_linux.run
sudo ./cuda_10.0.130_410.48_linux.run --override

2.5 error process You will be prompted to accept the End User License Agreement (EULA). During the process, you may encounter the following error:
Please make sure that
PATH includes /usr/local/cuda-10.0/bin
LD_LIBRARY_PATH includes /usr/local/cuda-10.0/lib64, or, add /usr/local/cuda-10.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-10.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.0/doc/pdf for detailed information on setting up CUDA.
*WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 10.0 functionality to work.
To install the driver using this installer, run the following command, replacing  with the name of this run file:
sudo .run -silent -driver
Logfile is /tmp/cuda_install_25774.log

You may safely ignore this error message. 2.6 update bash profile
nano ~/.bashrc

Insert the following lines at the bottom of the profile:
# NVIDIA CUDA Toolkit
export PATH=/usr/local/cuda-10.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64

ここでは自分のCUDAバージョンを修正することに注意します.
source ~/.bashrc

2.7 query CUDA to ensure that it is successfully installed:
nvcc -V

2.8 cuDNN Library for Linux cuDNN v7.6.4 for CUDA 10.0 from the following link: https://developer.nvidia.com/rdp/cudnn-archive
バージョンマッチングの問題に注意
scp ~/Downloads/cudnn-10.0-linux-x64-v7.6.4.24.tgz \
    username@your_ip_address:~/installers
cd ~/installers
tar -zxf cudnn-10.0-linux-x64-v7.6.4.38.tgz
cd cuda
sudo cp -P lib64/* /usr/local/cuda/lib64/
sudo cp -P include/* /usr/local/cuda/include/
cd ~

3.仮想環境のインストール


3.1 download pip3
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

3.2 install virtual environment tools:
pip3 install virtualenv virtualenvwrapper

3.3 update bash profile
nano ~/.bashrc

insert the following lines at the end of the file:
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

ここで間違っているかもしれません.virtualenvwrapperのためです.shパスのインストールが間違っています.エラーが発生した場合は、/usr/local/bin/virtualenvwrapperを参照してください.sh:そのファイルやディレクトリの解決策はありません
source ~/.bashrc

3.4 create Python 3 deep learning virtual environment named dl4cv:
mkvirtualenv dl4cv -p python3

4. Install TensorFlow 2.0 into your dl4cv virtual environment

      CUDA10.1,   tensorflow-gpu2.1

4.1 activate the environment and install
workon dl4cv
pip install numpy
pip install tensorflow-gpu==2.0.0 # or tensorflow-gpu==2.1.0

4.2 nstalling standard image processing libraries including OpenCV:
pip install opencv-contrib-python
pip install scikit-image
pip install pillow
pip install imutils

4.3 install machine learning libraries and support libraries
pip install scikit-learn
pip install matplotlib
pip install progressbar2
pip install beautifulsoup4
pip install pandas

4.4 test
workon dl4cv
python
>>> import tensorflow as tf
>>> tf.__version__
2.0.0
>>> import tensorflow.keras
>>> import cv2
>>> cv2.__version__
4.1.2

4.5 check if TensorFlow 2.0’s installation is able to take advantage of your GPU:
workon dl4cv
python
>>> import tensorflow as tf
>>> tf.test.is_gpu_available()
True

4.6 deactivate the current virtual environment:
deactivate