Deep learning environment configuration TensorFlow2+Keras

Anaconda

Anaconda is a tool for managing various python packages. Here we mainly use numpy and other commonly used packages.

Anaconda official website link: https://www.anaconda.com/

The Anaconda installation program of each system version can be downloaded and installed directly. For related usage methods, please refer to this article

CUDA

  1. First check the cuda version corresponding to the GPU of your computer , open the NVIDIA Control Panel -> Help -> System Information -> Components (can be opened in the control center or the notification bar in the lower right corner) as shown in the figure , the cuda version corresponding to my GPU here is 11.6 .106, so the installed cuda cannot exceed this version.

Or you can check the CUDA version by entering it on the cmd command line nvidia-smi.

  1. Enter the CUDA Toolkit Archive website and select a version of cudatoolkit that is lower than the version you just found. This article selects CUDA Toolkit 11.0 Update 3, and downloads an installation package of about 2.7G.

Note: The cuda version selected here will determine the version of cudnn and tensorflow-gpu installed later. The three are related. If the version does not match, it will not work. For the specific matching version, refer to https://tensorflow.google.cn/install/source_windows , the table below is an excerpt.

Version Python version translater build tool cuDNN CUDA
tensorflow_gpu-2.6.0 3.6-3.9 MSVC 2019 Basel 3.7.2 8.1 11.2
tensorflow_gpu-2.5.0 3.6-3.9 MSVC 2019 Basel 3.7.2 8.1 11.2
tensorflow_gpu-2.4.0 3.6-3.8 MSVC 2019 Basel 3.1.0 8.0 11.0
tensorflow_gpu-2.3.0 3.5-3.8 MSVC 2019 Basel 3.1.0 7.6 10.1
tensorflow_gpu-2.2.0 3.5-3.8 MSVC 2019 Basel 2.0.0 7.6 10.1
tensorflow_gpu-2.1.0 3.5-3.7 MSVC 2019 Basel 0.27.1-0.29.1 7.6 10.1
tensorflow_gpu-2.0.0 3.5-3.7 MSVC 2017 Basel 0.26.1 7.4 10
tensorflow_gpu-1.15.0 3.5-3.7 MSVC 2017 Basel 0.26.1 7.4 10
tensorflow_gpu-1.14.0 3.5-3.7 MSVC 2017 Basel 0.24.1-0.25.2 7.4 10
tensorflow_gpu-1.13.0 3.5-3.7 MSVC 2015 update 3 Basel 0.19.0-0.21.0 7.4 10

  1. Double-click the downloaded exe installation package , select the temporary decompression location, and then click ok. The decompression takes about two minutes.

  1. Agree to the license agreement , then select the custom installation option, and click Next

  1. Select the driver component, be sure to check CUDA , and then click Next .

  1. Choose an installation location on your computer and start the installation .

  1. Waiting for the installation to end , the computer's 18-year notebook mechanical hard drive installation takes about 5 minutes

  2. Check the environment variables . Generally, the environment variables will be automatically configured after the installation is completed. Open Settings-System-System Information-Advanced System Settings-Environment Variables to check. If not, you need to add them yourself (note that you need to modify it to your own installation path when adding)

  • Whether there are CUDA and NVCUDASAMPLES two sets of environment variables in the system variables .

  • Open the Path of the system variable and check whether the following environment variables exist.

  1. CUDA installation complete

cnDNN

  1. Open the cudnn official website , and check the cuDNN version you should download according to the above table. My CUDA version is 11.0, and the corresponding cuDNN version is 8.0. Pay attention to see that there is a corresponding CUDA version behind cuDNN. One cuDNN may correspond to multiple versions of CUDA. When downloading, you will be required to register an NVIDIA account first.

  1. Unzip the file and move the decompressed file to the installation directory corresponding to CUDA

  1. cuDNN installation complete

Install TensorFlow

  1. Open the cmd command line interface (it is recommended to open it as an administrator), and switch the pip mirror source of opentuna
pip config set global.index-url https://opentuna.cn/pypi/web/simple
  1. Create a virtual environment, followed by the python version installed on the computer, pay attention to whether it is compatible with
conda create -n tensorflow2 python=3.8
  1. Activate the virtual environment
conda activate tensorflow2
  1. Install tensorflow, and the specific version number corresponds to the table above.
pip install tensorflow-gpu==2.3.0

  1. Verify that the installation is successful, open the cmd interface, enter the following command, and check whether the output is Successfly
python
import tensorflow as tf
tf.config.list_physical_devices('GPU')

Don’t panic if it appears Could not load dynamic library 'cudart64_110.dll', it means that the computer has not been restarted after the installation is complete, just restart and run again.

Hard

  1. The corresponding version of TensorFlow and Keras refers to the following table
Tensorflow Hard
TensorFlow 2.0.0 Hard 2.3.1
TensorFlow 2.1.0 Hard 2.3.1
TensorFlow 2.2.0 Hard 2.3.1
TensorFlow 2.4.0 Loud 2.4.3
TensorFlow 2.6.0 Keras 2.6.0
  1. Run still run the following command in Anaconda's tensorflow2 environment
pip install keras==2.4.3

This blog post was first published on the personal blog website: https://www.mahaofei.com/ , welcome to visit.

Guess you like

Origin blog.csdn.net/weixin_44543463/article/details/125627906