Tensorflow 2.3.0-GPU download and installation tutorial under Windows
note:
To install TensorFlow-GPU, you need to confirm that there is at least one NVIDIA GPU on the machine. If you already have one, you first need to install the NVIDIA frameworks cuda and cudnn to take advantage of the powerful computing capabilities of the GPU.
View computer NVIDIA information
1. Right-click on the desktop> NVIDIA Control Panel
2. Click Help> System Information on the upper menu bar
3. Click on the component to view NVIDIA related information
One, install visual studio 2019
After finding the NVIDIA information of your computer, you first need to install vs2019, because you need to compile the cuda source code with a c++ compiler that supports the Windows operating system during the installation of cuda.
(1) Download vs2019
VS official website: VS official website
Select download from the menu bar:
select the free version of the community community to download.
(1) Install vs2019
After downloading, double-click the exe program to install:
click Continue to start the installation preparations:
after the preparations are over, the installation selection interface will pop up:
C++ is required. Because a C++ compiler is required to compile the cuda source code, the option "Desktop development using C++" must be selected.
Then start the installation:
wait for the installation to complete, restart the computer according to the prompts, and the vs2019 installation is complete.
After restarting, the first time you open vs2019, you will be asked to register. You can register for a Microsoft account and log in for free, or you can "talk about it later".
Then enter the option interface:
select and start vs2019:
if there is no error prompt, it proves that vs2019 has been installed correctly.
Two, install cuda
(1) Download the cuda installer
The NVIDIAcuda installation program can be found on the
NVIDIA official website link: NVIDIA official website link
click to download
According to my NVIDIA version information, I choose the Windows version cuda11.0 download:
click Windows->x86-64->10->exe in turn (local)
Cuda download interface, where base installer is the core installation package of the cuda program
(2) Install auda
Double-click to execute the downloaded base installer (cuda_11.0.3_451.82_win10.exe) file:
select the extraction file path: the
default path generated based on the user name is displayed in the extraction path box, and the default path can be used by long, please try Use the default path, and then you may get an error. After specifying the path, click OK to start extracting the file path.
After the extraction is complete, the installation program is launched and the system compatibility check is performed:
Since the vs2019 is pre-installed and GPU hardware is available, it can pass smoothly.
After the check is passed, you will enter the "NVIDIA Software License Agreement" interface.
Select "Agree and Continue" to enter the "Installation Options" interface:
generally select the simplified mode to meet the needs of training neural networks, and then the next step.
Wait patiently for the installation to complete. The
installation is successful. Picture:
Login/register NVIDIA account
(3) Check the installation of cuda
NVIDIA cuda will automatically add environment variables to the system. After the installation is complete, you need to make the newly added environment variables take effect to check the installation.
There are two ways to make environment variables take effect:
① Restart the computer
② For win10 system, enter "cmd" in the search function next to the start menu and
select "Run as administrator".
This step is to ensure that the system can reload the environment variables so that The new environment variable takes effect.
After manually loading environment variables or restarting and loading environment variables, you can check the installation of cuda:
enter the command: nvcc -V
will print out the information of the installed cuda, indicating that the cuda installation is complete.
Three, install cudnn'
(1) Download cudnn'
Enter NVIDIA's official website interface and download the cuDNN corresponding to cuda:
Official website link: Official website link
Cudnn download link: Cudnn download link
Click download
to log in or register (free) to
download the compressed package:
(2) Install cudnn
Unzip the compressed package:
copy all the files in the cuda folder to the cuda installation directory, overwrite the original files, and then you can successfully install cudnn.
The cuda installation directory can be found in the system environment variables:
Cuda-path is cuda Installation directory.
Fourth, install python
(1) Check the python installation. It
can be seen that the python version I installed is python3.7.4.
If python is not installed, you can check the relevant installation tutorial yourself , which is omitted here.
Five, install anaconda
(1) Check whether anaconda is installed
Open the terminal (win+R->enter cmd) and enter conda –version in cmd.
If anaconda is not installed, you can check the relevant installation tutorial by yourself , which is omitted here.
(2) Check the installed environment
Enter conda info ---envs in cmd.
If no other environment is created, there is only one default root/base environment in anaconda.
(3) Create a python3.7.4 environment
conda create --name tensorflow python=3.7.4
If the above warning appears: don’t panic, just follow the prompts to enter it, continue to enter:
conda update -n base -c defaults conda, upgrade anaconda
in the generated "Proceed( [y]/n)?” Under the question, enter y to continue the configuration process. If an error still occurs, repeat the input: conda
create -n py36 python=3.6; sooner or later it will appear: Solving environment: done. It
can be seen that the anaconda at this time is already 4.8.4 The latest version.
At this point, continue to create a virtual environment named tensorflow python3.7.4 environment: conda create --name tensorflow
python=3.7.4; under the question of "Proceed([y]/n)?" generated, enter y to continue configuration process.
(4) Activate the new environment
conda activate tensorflow
view the installed environment and
found that in addition to the original default root environment, there is one more tensorflow.
The (tensorflow) on the left represents entering the new virtual environment, here is tensorflow.
(5) Exit the current environment first
The Deactivate
environment name ((tensorflow) on the left) is gone, indicating that it has been exited.
(6) Verify that the python version in the tensorflow environment is correct
Activate the TensorFlow environment: activate TensorFlow
Check the python version: python --version
Six, install TensorFlow
Enter pip install TensorFlow-gpu -i https://pypi.douban.com/simple/ and
use "-i" to switch to Douban's mirror source (soon) and
wait for the installation to succeed.
After the installation is complete, enter the following command in the terminal console to check the installation:
here, the installation of the tensorflow-GPU2.3.0 environment is complete.
Seven, create a virtual environment in Pycharm
(1) Create an empty folder and remember the path
(2) Open pycharm, click file, and click settings
Select the project interpreter, click the drop down, and click show all
Click the plus sign in the upper right corner
Select virtualenv environment, select new environment path, select the folder path just created, base interpreter select python system interpreter path, click ok:
Choose a new environment
(3) After the creation is successful, the newly created folder will become like this:
(4) Click the terminal at the bottom of the pycharm window, come out the command window, enter the path and execute activate, you can enter the virtual environment