Contents
  1. Anaconda
  2. CUDA
  3. cnDNN
  4. Installing TensorFlow
  5. Keras

Anaconda

Anaconda is a tool for managing various Python packages. Here, we mainly use NumPy and some other commonly used packages.

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

You can directly download and install the Anaconda installer for your operating system. For instructions on how to use it, refer to this article.

CUDA

  1. First, check the CUDA version supported by your computer’s GPU. As shown in the figure, open NVIDIA Control Panel -> Help -> System Information -> Components (you can open it from Control Panel or the notification area in the lower-right corner). The CUDA version supported by my GPU is 11.6.106, so the CUDA version I install cannot exceed this version.

CUDA

Alternatively, enter nvidia-smi in cmd to check the CUDA version.

  1. Go to the CUDA Toolkit Archive and select a CUDA Toolkit version lower than the version you just found. This article uses CUDA Toolkit 11.0 Update 3. Download the installer, which is about 2.7G.

Note: The CUDA version selected here determines the cuDNN and tensorflow-gpu versions installed later. These three versions are related, and they will not work if the versions do not match. For specific compatible versions, refer to https://tensorflow.google.cn/install/source_windows. The table below is an excerpt.

VersionPython VersionCompilerBuild ToolcuDNNCUDA
tensorflow_gpu-2.6.03.6-3.9MSVC 2019Bazel 3.7.28.111.2
tensorflow_gpu-2.5.03.6-3.9MSVC 2019Bazel 3.7.28.111.2
tensorflow_gpu-2.4.03.6-3.8MSVC 2019Bazel 3.1.08.011.0
tensorflow_gpu-2.3.03.5-3.8MSVC 2019Bazel 3.1.07.610.1
tensorflow_gpu-2.2.03.5-3.8MSVC 2019Bazel 2.0.07.610.1
tensorflow_gpu-2.1.03.5-3.7MSVC 2019Bazel 0.27.1-0.29.17.610.1
tensorflow_gpu-2.0.03.5-3.7MSVC 2017Bazel 0.26.17.410
tensorflow_gpu-1.15.03.5-3.7MSVC 2017Bazel 0.26.17.410
tensorflow_gpu-1.14.03.5-3.7MSVC 2017Bazel 0.24.1-0.25.27.410
tensorflow_gpu-1.13.03.5-3.7MSVC 2015 update 3Bazel 0.19.0-0.21.07.410

CUDA (2)

  1. Double-click the downloaded exe installer, select a location for temporary extraction, and then click ok. Extraction takes about two minutes.

CUDA (3)

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

CUDA (4)

CUDA (5)

  1. Select the driver components. Be sure to check CUDA, and then click Next.

CUDA (6)

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

CUDA (7)

  1. Wait for the installation to finish. On this ‘18 laptop with a mechanical hard drive, the installation took about 5 minutes.

  2. Check the environment variables. They are generally configured automatically after installation. Open Settings - System - System Information - Advanced System Settings - Environment Variables to check them. If they are not present, you need to add them yourself (remember to change them to your own installation path when adding them).

  • Check whether the system variables contain the two environment-variable groups CUDA and NVCUDASAMPLES.

CUDA (8)

  • Open Path under system variables and check whether it contains the following environment variables.

CUDA (9)

  1. CUDA installation is complete.

cnDNN

  1. Open the official cuDNN website, and use the table above to determine which cuDNN version you should download. My CUDA version is 11.0, and the corresponding cuDNN version is 8.0. Pay attention to the corresponding CUDA version shown after cuDNN. One cuDNN version may support multiple CUDA versions. You will need to register an NVIDIA account before downloading.

cnDNN

  1. Extract the files and move the extracted files to the corresponding CUDA installation directory.

cnDNN (2)

  1. cuDNN installation is complete.

Installing TensorFlow

  1. Open cmd (running it as administrator is recommended), and switch pip to the opentuna mirror.
pip config set global.index-url https://opentuna.cn/pypi/web/simple
  1. Create a virtual environment. The value at the end is the Python version installed on the computer. Check whether it matches
conda create -n tensorflow2 python=3.8
  1. Activate the virtual environment.
conda activate tensorflow2
  1. Install tensorflow. Select the exact version according to the table above.
pip install tensorflow-gpu==2.3.0

Installing TensorFlow

  1. Verify that the installation succeeded. Open cmd, enter the following commands, and check whether the output says Successfly.
python
import tensorflow as tf
tf.config.list_physical_devices('GPU')

Installing TensorFlow (2)

If Could not load dynamic library 'cudart64_110.dll' appears, do not panic. It means the computer was not restarted after the installation. Restart it and run the commands again.

Keras

  1. Refer to the table below for the corresponding TensorFlow and Keras versions.
TensorflowKeras
TensorFlow 2.0.0Keras 2.3.1
TensorFlow 2.1.0Keras 2.3.1
TensorFlow 2.2.0Keras 2.3.1
TensorFlow 2.4.0Keras 2.4.3
TensorFlow 2.6.0Keras 2.6.0
  1. Still using Anaconda, run the command below in the tensorflow2 environment.
pip install keras==2.4.3

Keras