Deep learning environment configuration: tensorflow-gpu + keras

Deep learning environment configuration: tensorflow-gpu + keras

  • Environment: Windows10 + GTX1060 + cuda10.1 + cudnn7.6.5 + tensorflow-gpu2.3.1 + keras2.4.3
  • Use miniconda to configure this set of environments, use Anaconda to configure the same steps
  • The following problems should be solved below:

(1) There are many versions of cuda, so which version should we choose to download?

(2) There are many versions of cudnn, how to choose?

(3) Which version of tensorflow-gpu should we choose to install?

(4) Which version of keras should we choose to install?

Step 1: Configure the graphics card GPU operating environment

  • If we want our computer to be able to run deep learning programs on the graphics card (my computer is a NVIDIA graphics card, I have not configured a graphics card for AMD), you must install CUDA on your computer (CUDA is a universal parallel launched by NVIDIA Computing architecture, which enables GPU to solve complex computing problems) and cudnn (cudnn is a GPU acceleration library for deep neural networks). Installation sequence: install cuda first, then cudnn.

  • To download cuda and cudnn, go to NVIDIA's official website to download, and the premise is to register an NVIDIA account. cuda download address of each version , cudnn download address

  • There are many versions of cuda, so which version should we choose to download? This is related to the version of our graphics card driver.

Insert picture description here

(1) The first step: Check the version of our graphics card driver, there are two ways.

Method 1: View through the NVIDIA control panel

Insert picture description here

Method 2: Via cmd command line

nvidia-smi

Insert picture description here

(2) According to the graphics card version driver, go to the following website to find the cuda version that can be installed: the cuda version corresponding to the graphics card . The following is the correspondence table (screenshot time: February 2, 2021).

Insert picture description here

(3) Download CUDA on the official website ( download address of each version of cuda ) and install it. After installation, enter the following command in cmd to check whether the installation is successful

nvcc -V

Insert picture description here

In addition, it is noted that the default installation location of cuda is:, C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1this location will be used when installing cudnn immediately.

(4) Up to now, we have installed cuda, but we can't run the deep learning library on the GPU. Next, we will install the library cudnn specially developed by NVIDIA for deep learning. First download cudnn on the official website ( cudnn download address ), here is another question involved: There are many versions of cudnn, how to choose? The version of cudnn depends on the version of CUDA just installed. We can go to the following website to find the version of cudnn that can be installed: Correspondence between cudnn and CUDA . The following is the corresponding relationship (screenshot time: February 2, 2021).

Insert picture description here

(5) After downloading cudnn, this is a compressed package. After decompression, you will get a folder, enter the folder, select all the contents inside, and copy. The following figure shows the content that needs to be copied after decompression:

Insert picture description here

(6) Open the CUDA installation location (default location: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1), and copy the content copied in section (5) to the CUDA installation location. If there is a file conflict, choose to overwrite the original file. So far, the graphics card GPU operating environment is configured.

Step 2: Configure tensorflow-gpu and keras

  • Here we use miniconda (or Anaconda) command line tool to configure a set of virtual environment. For how to configure the use of this command line, please refer to: Anaconda software installation and use .

  • The installation of the tensorflow-gpu version (you do not need to install the cpu version of tensorflow in advance) requires the support of CUDA and cudnn. There are many versions of tensorflow-gpu, then the same problem arises now, which version of tensorflow-gpu should we choose to install? We can check the correspondence between tensorflow-gpu and CUDA and cudnn at this website: The correspondence between tensorflow-gpu and CUDA and cudnn . The following is the correspondence table (screenshot time: February 2, 2021).

Insert picture description here

About MSVC support:

Insert picture description here

  • After solving the version correspondence between tensorflow-gpu and CUDA and cudnn, is there a problem now? Which version of keras should we choose to install? Here keras official does not give the correspondence between keras and tensorflow-gpu (at least I did not find it), but you can refer to the correspondence given by the following website: The correspondence between keras and tensorflow . Installations that do not follow this correspondence relationship may or may not succeed. The following is the correspondence table (screenshot time: February 2, 2021).

Insert picture description here

Use conda demo to install tensorflow-gpu + keras

1 Configure conda domestic mirror source

  • This step can also be omitted, this step is to speed up the download

C:\Users\WXXCreate a new .condarcfile under the personal user folder (corresponding location in My Computer: ) , and add the following content to the file:

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
show_channel_urls: true

Reference URL: About the solution of CondaHTTPError using anaconda

In addition, it can also be replaced by a source from the University of Science and Technology of China.

2 Configure pip domestic mirror source

  • This step can also be omitted, this step is to speed up the download

C:\Users\WXXCreate a new pip folder under the personal user folder (corresponding location in My Computer: ), create a new pip.ini in the folder, and add the following content to the file:

[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
[install]
use-mirrors =true
mirrors =https://pypi.mirrors.ustc.edu.cn/simple/
trusted-host =pypi.mirrors.ustc.edu.cn/simple/

Reference URL: pip download acceleration

3 Installation environment

conda create -n kr243 python=3.6.5
conda activate kr243
pip install tensorflow-gpu==2.3.1
pip install keras==2.4.3

4 Test results

Use the following code to test whether GPU acceleration can be used:

# coding=utf-8
import tensorflow as tf

print(tf.__version__)
print('GPU', tf.test.is_gpu_available())

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42638946/article/details/113561967