Python deep learning environment to install the GPU version


1. Install Anaconda

This article mainly uses Anaconda to configure the deep learning environment.
You can download the attached link through the Anaconda official website:
https://www.anaconda.com/
to determine whether the installation is successful win+r to call up cmd
and enter the following command

conda -V

  
  
   
   
  • 1

insert image description here
If the above results appear, the installation is successful.

1. Change source

Next, we need to change the source of Anaconda. The default source of Anaconda is relatively slow to download. We need to change the source of Tsinghua University or Chinese Academy of Sciences. Taking Tsinghua source as an example, the terminal input:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/simpleitk
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

To judge whether the source change is successful, enter the terminal:

conda info

 
 
  
  
  • 1

insert image description here
If the above results appear, the source change is successful.

2. Common commands

Next are some commands commonly used by Anaconda
to view existing virtual environments :

conda env list

 
 
  
  
  • 1

Create a new virtual environment

conda create --name 环境名

 
 
  
  
  • 1

Enter the virtual environment:

conda activate 环境名

 
 
  
  
  • 1

Exit the virtual environment:

conda deactivate

 
 
  
  
  • 1

Delete the virtual environment:

conda remove -n 环境名 --all

 
 
  
  
  • 1

Copy the virtual environment:

conda create -n conda-env2 --clone conda-env1

 
 
  
  
  • 1

Here conda-env2 is the newly created virtual environment, and conda-env1 is the copied virtual environment, which must be paid attention to.

2. Install cuda and cudnn

1. Corresponding version

Before installing Tensorflow - gpu , we need to install the versions corresponding
to cuda and cudnn according to the following table
insert image description here
.
insert image description here
Check the official website, with a link: https://tensorflow.google.cn/install/source_windows#gpu

2. Create a virtual environment

First, we create a virtual environment through Anaconda:

conda create -n csdn python=3.7

 
 
  
  
  • 1

Create a virtual environment named csdn.
Output y to complete the creation
insert image description here
As shown in the figure, the creation is completed
insert image description here

3. Activate the virtual environment

activate csdn

 
 
  
  
  • 1

As shown, the virtual environment name is displayed on the left.
insert image description here

4. Install cuda

conda install cudatoolkit=10.1

 
 
  
  
  • 1

Corresponding version, modify as required.
Enter y to install
insert image description here
, as shown in the figure, complete the installation.
insert image description here

4. Install cudnn

conda install cudnn=7.6

 
 
  
  
  • 1

Enter y to install,
insert image description here
as shown in the figure, complete the installation
insert image description here

3. Install the GPU version of tensorflow

pip install tensorflow-gpu==2.1.0

 
 
  
  
  • 1

As shown in the figure, the installation is in progress
insert image description here
and the installation is complete
insert image description here

1. Determine whether the installation is successful

Next, test to determine whether the installation is successful.
Enter in the virtual environment pythonto enter the python environment
, then enter import tensorflow as ts
as shown in the figure ,
insert image description here
enter again ts.test.is_gpu_available()
as shown in the figure, if it is True, the installation is successful.
insert image description here

Fourth, pycharm configures the virtual environment

1. Create a new project

insert image description here

2. Configure the environment

insert image description here

3. Complete the creation

insert image description here

Summarize

This article mainly uses Anaconda to configure the tensorflow-gpu environment. It introduces how to create a new virtual environment, download cuda, cudnn, tensorflow-gpu, and judge whether the installation is successful. Finally, it introduces how to create a new project in pycharm to configure the virtual environment.

Original article address: https://blog.csdn.net/thj_2017720/article/details/123574587

Guess you like

Origin blog.csdn.net/qq_44231797/article/details/125050333