The GPU version of tensorflow2 is installed

1. Install Anaconda and Python

For details, refer directly to my article Anaconda installation and configuration

2. Install CUDA

1. First check the cuda version corresponding to the local GPU , as shown in the figure below, the local cuda version is 11.6, and the cuda version selected later should not exceed the version here.

Operation: Right-click -> NVIDIA Control Panel -> Help -> System Information -> Components

 2. After checking cuda, go to https://developer.nvidia.com/cuda-toolkit-archive and select the corresponding cudatoolkit version to download from this website. As shown in the figure, the version you choose to download on this machine is 10.1, and select the version here Be sure to pay attention, because the cuda version will determine the cudnn and tensorflow-gpu versions you download. If they are inconsistent, there will be problems such as version mismatch and cannot be used.

 

  3. After downloading cuda
 ① Open the installation package, a prompt box will appear, allowing you to choose a temporary decompression location (the content of this location will be automatically deleted after you install cuda), here is the default, click ok.

 

  ② After completing the previous step, select Custom, and then click Next.


  ③Complete the previous step, CUDA must be checked here, the following options can be unchecked, and it will have no effect on the follow-up. 

 ④ Then go to the next step and wait for the end of the installation (when you choose the installation location in the middle, you can change the directory, it is best to only change the drive letter in the front, and keep the folders in the back consistent, which is convenient for future management).
⑤ After the installation is complete, check whether the environment variables exist. Generally, the environment variables will be automatically configured after the installation is completed. If not, you need to configure them manually. The specific process is as follows.
      a. Open computer properties, find advanced system settings, and select environment variables to open.

     b. Check whether there are the following environment variables. If not, you need to add them yourself. Corresponding to the name and value on the picture, configure the location where your computer CUDA is installed.

 The installation of CUDA is over, and then download and decompress the cuDNN file.

3. Install cuDNN

 Open this URL https://developer.nvidia.com/rdp/cudnn-archive, when you click download for the first time, you will be asked to register and log in first, and then download, it is no problem to fill in the content carefully during the registration process, here Skip it, and then enter the download link.
 ① First, download the corresponding cuDNN version according to the installed CUDA version, and check the corresponding tensoflow-gpu version and python version from here. For detailed information, see the website https://tensorflow.google.cn/install/source_windows.

Because of the CUDA10.1 version installed on this machine, choose cuDNN7.6 to download, and you can choose all the ones in the red box below.


② After the download is complete, unzip the file, and move the corresponding file in the cudnn file to the corresponding installation directory of cuda, and be careful not to move to the wrong location.

 The installation of cuDNN is over here, and the long-awaited tensorflow-gpu will be installed next.

 4. Install tensorflow-gpu

Use Anaconda (if you choose this step, you don’t need to download python and various common toolkits, it will be packaged and downloaded)

Use pip to install directly (this machine adopts this method).
      First, open the cmd command line interface. Here it is recommended to open it as an administrator.

      Then, you can enter the following command on the command line to install:

pip install tensorflow-gpu==2.3.0 --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple

 So far, using pip to install tensorflow-gpu is over, and then you can test whether it can run normally, create a new python file, enter the following command, you can run this code in any way (pycharm is used here, if there is no Then go directly to the official website to download, which is very convenient), when the red content in the figure below appears, it means that the tensorflow-gpu version has been successfully run.

import tensorflow as tf
tf.autograph.set_verbosity(0)
physical_devices = tf.config.experimental.list_physical_devices('GPU')
print(physical_devices)

 The following information appears to indicate that the installation is successful!

 

 

 

     

 

 

 

Guess you like

Origin blog.csdn.net/linxi4165/article/details/124765941