foreword
When installing Tensorflow-gpu and keras, you must first pay attention to the version correspondence, otherwise it is easy to make mistakes. When reading, it is recommended to read the entire article before getting started.
1. Environment + configuration
local environment
Graphics card: RTX3050Ti (notebook)
Windows 10 Professional Edition
NVIDIA 511.65
Available versions found online
(Deviates from what I use)
python3.7.0+CUDA11.6.0+cuDNN8.3.2+tensorflow2.7.0+Keras2.7.0
python3.7.0+CUDA11.3.1+cuDNN8.2.1+tensorflow2.7.0+Keras2.7.0
python3.7.0+CUDA10.1.2+cuDNN7.6.5+tensorflow2.2.0+keras 2.3.1
The version of CUDA, CUDNN, tensorflow-gpu, keras installed by me
cuda_11.6.1_511.6
hidden_8.3.2.44
tensorflow-gpu 2.7.0
hard 2.7.0
That is, the final environment I use is
python3.8.12 + CUDA 11.6.1 + cuDNN 8.3.2 + tensorflow 2.7.0 + Keras 2.7.0
Tensorflow and CUDA, cuDNN relationship query
https://tensorflow.google.cn/install/source_windows?hl=en#gpu
CUDA version selection
Correspondence between NVIDIA and CUDA versions
Refer to the table to choose
First, [Right click] on the desktop - open [NVIDIA Control Panel] - select [Help] - [System Information], and then select [Components] in the opened system information, you can see the CUDA version supported by the local GPU:
Component 3D settings focus on the product name behind NVCUDA64.DDL
Or you can enter the command in the terminal nvidia-smi
to view the GPU driver version
CUDNN version selection
The version correspondence between CUDA and CUDNN
Install according to the version of CUDA, download the compressed package version
2. Installation Tutorial
2.1 CUDA installation
Double-click cuda_11.6.1_511.65_windows.exe
to enter the installer:
Here is a temporary selection of the temporarily extracted folder, regardless of the direct ok:
After extraction, the program checks for compatibility:
Select [Agree and Continue], select [Custom] to install:
Uncheck it in CUDA Visual Studio Integration
. This is a plug-in for VS, which can easily cause installation failure. I don’t check it because I use pycharm
There are three more options. NVIDIA GeForce Experience is a graphics card driver. If you have updated the graphics card driver version, you don’t need to choose it, because each CUDA version contains a graphics card driver. If you choose it every time, it is equivalent to updating the graphics card driver version every time. Other components are device drivers such as sound cards. My computer has installed them, so there is no need to choose them, and the last one is also. (Everyone can according to their own situation)
Then select the installation path and click Install. The local version is very fast, but the online version needs to be downloaded and installed online, which is slower.
Wait for the installation to complete, you can check whether the installation is successful, enter the command in the terminal nvcc -V
, check the CUDA version, if it can be displayed, it is successful.
2.2 CUDNN installation
After cuDNN is downloaded, decompress it, and move the contents of the three folders into the corresponding folders with the same name in the CUDA installation directory. The include and bin folders can be moved directly, and the content of the lib folder should be moved to the lib\x64 directory
Then copy it to the installation path of CUDA, mine is C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6
(note! It is not overwritten, it is added to the corresponding folder)
lib exists in lib/x64
Finally, just configure the system environment:
Right-click [This Computer], also known as Computer - [Properties] - [Advanced System Settings] - [Environment Variables] - find [Path] in the lower part of [System Variables], double-click to open (or point edit)
Complete the following environment variables. If you have successfully installed CUDA before, the 2 and 3 environments have been automatically added by the system.
2.3 TensorFlow-gpu 2.7 installation
2.3.1 Conda creates a virtual environment
- Check the environment
conda info --env
- Create an environment (an example is to create an environment called tf27, python version 3.8)
conda create -n tf27 python=3.8
2. Delete the environment (for example, delete the environment named tf27)
conda remove -n tf27 --all
3. Activate the environment (the example is to activate the environment named py36)
activate tf27
4. Exit the environment
deactivate
5. Downloading from Tsinghua mirror source (for example, downloading numpy) will significantly increase the download speed
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
6. pip/ anaconda directly modify the image source without adding a link every time (Windows)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
Just install it later
pip install tensorflow-gpu==2.7.0
Second, enter pycharm and create a .py file for testing:
import tensorflow as tf
print(tf.__version__)
print('GPU', tf.test.is_gpu_available())
![Insert picture description here](https://img-blog.csdnimg.cn/554ef028f3fc4f57b8d50118312ff8e6.png#pic_center
output the version number, and True
Successful installation!
3. Explanation of terms
TensorFlow: An open source software library for machine learning on various perception and language understanding tasks.
Keras: An open source neural network library written in Python that can run on top of TensorFlow, Microsoft Cognitive Toolkit, Theano or PlaidML. Keras is designed to quickly implement deep neural networks, focusing on user-friendliness, modularity, and scalability.
CUDA: Unified Computing Architecture. It is specially designed for GPU to handle multiple tasks at the same time, and its large-scale parallel computing processing is very suitable for analysis and rendering in graphics processing, speech recognition, video and other fields.
cuDNN: A deep neural network library optimized for CUDA for high-performance GPU acceleration.
appendix
Available versions found online
python3.7.0+CUDA11.6.0+cuDNN8.3.2+tensorflow2.7.0+Keras2.7.0
python3.7.0+CUDA11.3.1+cuDNN8.2.1+tensorflow2.7.0+Keras2.7.0
python3.7.0+CUDA10.1.2+cuDNN7.6.5+tensorflow2.2.0+keras 2.3.1
1. Graphics card computing power and graphics card driver version
Graphics card computing power determines your CUDA version range:
NIVDIA Graphics Card Computing Power Official Query
2. Graphics card driver version update
The graphics card driver version can be found in the system information of the NVIDIA control panel. It is recommended to update to the latest version, so that the download of the CUDA version will not be restricted due to the driver version.
NVIDIA official graphics card driver update
To update the graphics card driver, it is recommended to select Studio Driver (SD) in the option Download Type, because it is beneficial to deep learning.
NVIDIA official CUDA and graphics card driver version correspondence table query
3. CUDA, cuDNN and python versions corresponding to tensorflow
Officially query the relationship between tensorflow-gpu and CUDA cuDNN Python version
reference
https://blog.csdn.net/typefree/article/details/117998734
https://blog.csdn.net/jiuzixu/article/details/122518914