[Tensorflow-2.x-gpu] python3 configure tensorflow-2.x gpu environment (2)

1. Background

Refer to the previous blog:
[tensorflow-2.x-gpu] python3 configuration tensorflow-2.x gpu environment (1)
https://blog.csdn.net/jn10010537/article/details/108917295

Use Anaconda3 to install tensorflow-2.x gpu.
After reinstalling the system recently, I followed the blog implementation and found that GPU could not be used because the computer I reinstalled did not install NVIDIA's cuda.

I lent my laptop to my colleague for a few weeks before, and he should have installed cuda on my computer. So after installing tensorflow-2.x gpu, I can directly use gpu for training and inference.

This blog demonstrates the new windows10 system after flashing:
install tensorflow-2.x gpu, configure cuda, cuDnn, and finally successfully use your GPU for acceleration.

Description:
CUDA (Compute Unified Device Architecture) is a parallel computing platform and programming model for general GPU computing. It is based on the C language and has been extended with multiple C languages, which can execute programs on the graphics chip.
CUDA provides a deep neural network GPU acceleration library cuDNN (CUDA Deep Neural Network), which completes the rapid implementation of standard operations such as convolution, pooling, normalization, and activation function layers.

2. GPU support on TF official website

Check tensorflow official website about GPU support:
https://tensorflow.google.cn/install/gpu

The description of GPU support is summarized as follows:
For Ubuntu and Windows, you need to install a graphics card that supports CUDA® to achieve GPU support.
That is, you need to check whether your graphics card is supported by the CUDA framework, then install CUDA software, configure cudnn (deep learning acceleration library), and install tensorflow-gpu to use GPU for deep learning acceleration training and inference.
Note: The graphics card involved here is an N card, that is, Nvidia’s GPU.

The following is the configuration of cuda environment variables on the TF official website:
Insert picture description here

3. Check the computing power of the graphics card

For example, mine is GeForce RTX2060. The
corresponding computing power is 7.5.
The GPU supports the CUDA framework and supports deep learning acceleration!

Refer to Nvidia's official website link:
https://developer.nvidia.com/zh-cn/cuda-gpus
Insert picture description here

4. View the tested build configuration on the TF official website

https://tensorflow.google.cn/install/source#gpu

The Linux-GPU build configuration is as follows:
Insert picture description here

The Windows-GPU build configuration is as follows:
Insert picture description here
My operating system is windows10
. I may use both versions 1.x and 2.0 of tensorflow-gpu. The tensorflow-gpu version of the area selected below: tensorflow-gpu
1.13.0~2.0.0, I will use it most frequently:
Insert picture description here
The combination of my selection group is:

Serial number Software package version
1 python 3.6.8
2 tensorflow-gpu 1.14.0
3 MIRACLES 10.0
4 cuDNN 7.4

5. Install tensorflow-gpu

It is recommended that after downloading whl, use the Tsinghua mirror source for pip installation.
As follows, first download tensorflow_gpu-1.14.0-cp36-cp36m-win_amd64.whl, and then install:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow_gpu-1.14.0-cp36-cp36m-win_amd64.whl

If you fail to install it multiple times, it is likely that the network you are using is poor. Please change to a network with a larger download bandwidth, or choose to install it when there are few people off work.

注意:下载tensorflow的whl时,你可能遇到RC标志,下面解释一下:
RC->Release Candidate 预发行版
一般出了预发行版后,正式版就要出了。

Before installation, check the python package:

C:\Users\Administrator>pip list
Package    Version
---------- -------
pip        21.0.1
setuptools 40.6.2

After installation, check the python package:

E:\E05_project\packages>pip list
Package              Version
-------------------- -------
absl-py              0.11.0
astor                0.8.1
cached-property      1.5.2
gast                 0.4.0
google-pasta         0.2.0
grpcio               1.35.0
h5py                 3.1.0
importlib-metadata   3.4.0
Keras-Applications   1.0.8
Keras-Preprocessing  1.1.2
Markdown             3.3.3
numpy                1.19.5
pip                  21.0.1
protobuf             3.14.0
setuptools           53.0.0
six                  1.15.0
tensorboard          1.14.0
tensorflow-estimator 1.14.0
tensorflow-gpu       1.14.0
termcolor            1.1.0
typing-extensions    3.7.4.3
Werkzeug             1.0.1
wheel                0.36.2
wrapt                1.12.1
zipp                 3.4.0

Note:
Importing tensorflow will report an error at this time, the error is as follows:

C:\Users\Administrator>python
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "D:\D02_pythonDevelop\D02_01_Python3\install_python3.6.8\lib\site-packages\tensorflow\python\platform\self_check.py", line 75, in preload_check
    ctypes.WinDLL(build_info.cudart_dll_name)
  File "D:\D02_pythonDevelop\D02_01_Python3\install_python3.6.8\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模块。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\D02_pythonDevelop\D02_01_Python3\install_python3.6.8\lib\site-packages\tensorflow\__init__.py", line 28, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "D:\D02_pythonDevelop\D02_01_Python3\install_python3.6.8\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\D02_pythonDevelop\D02_01_Python3\install_python3.6.8\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
    self_check.preload_check()
  File "D:\D02_pythonDevelop\D02_01_Python3\install_python3.6.8\lib\site-packages\tensorflow\python\platform\self_check.py", line 82, in preload_check
    % (build_info.cudart_dll_name, build_info.cuda_version_number))
ImportError: Could not find 'cudart64_100.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 10.0 from this URL: https://developer.nvidia.com/cuda-90-download-archive
>>> print(tf.__version__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'tf' is not defined
>>>

Import import the above tensorflow version 1.14.0 error report (my notebook graphics card is GeForce RTX2060, the corresponding computing power is 7.5, support CUDA framework!)
In the cmd terminal, enter nvcc --version to view the cuda version:
Insert picture description here
you can see that my computer has not Install cuda! Need to continue to install cuda

6. Install cuda

6.1 Download the CUDA toolkit:
I downloaded cuda_10.0.130_411.31_win10.exe, by the
way: Visual Studio Community 2019 is installed on the laptop.

Download link :
https://developer.nvidia.com/zh-cn/cuda-downloads
But now 11.1 is downloaded through this link, I will upload the resource of cuda_10.0.130_411.31_win10.exe after the blog post.
Insert picture description here

6.2 Install NVIDIA CUDA 10.0 to
avoid installing cuda to the system disk (my system disk is C drive)!

Click to agree and continue (A)
Insert picture description here

When installing, choose a custom (advanced) installation:Insert picture description here

Select installation components:Insert picture description here

Install outside the system disk. as follows
Insert picture description here

Install CUDA Documentation, Samples, and CUDA Development separately from the system disk.
The installation directory is customized as follows:

CUDA Development D:\D03_GeneralDevelop\D03_01_cuda\install\cuda_development
CUDA Documentation D:\D03_GeneralDevelop\D03_01_cuda\install\cuda_documentation
Samples D:\D03_GeneralDevelop\D03_01_cuda\install\cuda_samples

Insert picture description here
Here you need to check the msvs2017 version, this machine is 2019, this problem has no effect temporarily.
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
6.3 Configure cuda environment variables
Add the bin folder under the custom installation directory, namely
D:\D03_GeneralDevelop\D03_01_cuda\install\cuda_development\bin
into the system environment variables.

Enter nvcc --version in the cmd terminal again to view the cuda version:Insert picture description here

Import tensorflow again, and continue to report the error as follows:
Insert picture description here
According to the appeal prompt, cuDNN 7 needs to be installed (according to the above configuration table, select 7.4)

7. Download and configure cuDNN

-7.1 Download cudnn-10.0-windows10-x64-v7.4.2.24.zip and copy the decompressed bin, include and lib folders to the cuDNN folder;

-7.2 Cut the cuDNN folder to the installation directory: D:\D03_GeneralDevelop\D03_01_cuda\install\cuda_development

-7.3 Add:
D:\D03_GeneralDevelop\D03_01_cuda\install\cuda_development\cuDNN\bin
D:\D03_GeneralDevelop\D03_01_cuda\install\cuda_development\libnvvp
D:\D03_GeneralDevelop\D03_01_cuda\install\cuda_development\extras\CUPTI\libx64
to the system environment Among the variables.
Insert picture description here
Import again, ok
Insert picture description here

8. Verify the use of tensorflow's gpu

import tensorflow as tf
hello = tf.constant("hello, world!")
sess = tf.Session()
sess.run(hello)

Run as follows:
Insert picture description here

9. Resources

Guess you like

Origin blog.csdn.net/jn10010537/article/details/113791239