1. 首先是需要安装anaconda (python版本最好在3.8以上),如果需要换conda源和pip源执行下面的代码
# 更改pip为清华源
pip install pip -U --user
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
#更改conda为清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
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 --set show_channel_urls yes
2. tensorflow GPU版 2.6(注意对照cuda的版本) ,cuda 11.3版本及cudnn 8.2.1(你的电脑不一定合适这个版本)
pip install tensorflow_gpu==2.6 -i https://pypi.tuna.tsinghua.edu.cn/simple
conda install cudatoolkit=11.3
conda install cudnn=8.2.1
3. 如果不知道自己的cuda版本可以使用nvdia-smi来查看自己GPU版本最高支持那个版本
4. 然后查看自己conda库(使用之前最好更新一下)的cudnn版本,然后找到适合的版本
conda search cudnn
5. 根据上面可以看到8.2.1的版本是支持cuda 11.3的,此时只需
conda install cudnn=8.2.1
conda install cuda=11.3
6. 最后别忘了,下载tensorflow2.6就可以了
pip install tensorflow_gpu=2.6 -i https://pypi.tuna.tsinghua.edu.cn/simple
7. 最后测试一下
import tensorflow as tf
tf.config.list_physical_devices('GPU')
8. 大功告成