搭建深度学习环境:Tensorflow-gpu过程记录

我的电脑配置NVIDIA RTX3060显卡
搭建的为cuda11.2 + cudnn8.2.1 + Tensorflow2.9.0
复制代码

一、搭建过程

1.官网安装Anaconda

2.对Anaconda和Python换源,使得下载地址为国内清华镜像Index of /anaconda/pkgs/main/win-64/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

3.使用conda install安装版本对应的cuda + cudnn + Tensorflow-gpu,cuda只需要安装cudatoolkit即可,版本对应可查阅Build from source on Windows  |  TensorFlow (google.cn)

4.进入python使用import Tensorflow as tf来验证是否下载成功,使用tf.test.is_gpu_available()来验证是否可用。

具体可参考Tensorflow-gpu安装超详细!!!_东海扬尘_BingO的博客-CSDN博客_tensorflowgpu安装

二、过程中遇到的问题及解决方法

  • 问题一:Tensorflow/keras 模型搭建以及训练的第一个epoch速度非常慢

由于我一开始按照上面教程创建的环境及对应的版本为python3.7 + cuda10.1 + cudnn7.6 + tensorflow-gpu2.1.0,从网上查阅,可能是由于30系显卡与cuda版本不符的问题,仅支持cuda11和cudnn8.0以上的版本。

  • 问题二:由于换源后的清华镜像网站上没有cudnn8.0及8.1的版本,而官网版本对照中cudnn最高仅到8.1版本

image.png 我查找清华镜像网站后,发现网站上有2021年的cudnn8.2.1版本,以及相对于的cuda11.2版本,于是我下载了最新的Tensorflow-gpu2.9.0版本,最后验证使用时,版本对应没有问题。

  • 问题三:按照顺序下载后,在验证import tensorflow as tf时会出现

TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are:

  1. Downgrade the protobuf package to 3.20.x or lower.
  2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: developers.google.com/protocol-bu…

解决方案

pip uninstall protobuf
pip install protobuf==3.20.1
复制代码
  • 问题四:由于我使用的是Anaconda的jupyter lab作为代码编辑器,最后需要添加一下python内核
conda env list         # 检查已有的虚拟环境

activate 环境名

conda install nb_conda

conda install ipykernel

conda install -n 环境名 ipykernel

python -m ipykernel install --user --name 环境名
复制代码

参考在Jupyter Notebook中添加conda虚拟环境内核_Triumph++的博客-CSDN博客

猜你喜欢

转载自juejin.im/post/7106426839630872584