搭建tensorflow(gpu)虚拟环境

搭建tensorflow2.x环境

  • 首先创建一个新的环境
conda create -n 环境名称 python=xx(python版本)
  • 激活环境
conda activate 刚才创建的环境名称
  • 安装tensorflow2.xpip install tensorflow==2.x
pip install tensorflow==2.x

若安装非常慢,可以使用镜像网站安装

pip install tensorflow==2.x -i https://pypi.tuna.tsinghua.edu.cn/simple

国内镜像网址 

清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/

网址来源:​​​​​​解决安装tensorflow等速度慢,超时 - whw1314 - 博客园 (cnblogs.com)​​​​​

conda install cudatoolkit==11.0
conda install cudnn==8.0

若找不到对应版本的cudatoolkit和cudnn,则可以使用如下代码,查看具体的版本号

conda search cudnn -c conda-forge

会出现如下版本,在其中找到自己需要的版本,再次进行安装,安装命令如下。

  

conda install cudnn==8.0.5.39 -c conda-forge
conda install cudatoolkit==11.0.3 -c conda-forge
  • 最后查看gpu是否可以使用,输入如下命令
python
import tensorflow as tf
gpu_out=tf.config.list_physical_devices('GPU')
print(gpu_out)
exit()

搭建tensorflow1.x环境

步骤同上,所以只写了完整的代码,以安装tensorflow-gpu-1.14.0+cuda10.0+cudnn7.4为例。

conda create -n tf python=3.5


conda activate tf


pip install tensorflow_gpu==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple


conda install cudatoolkit==10.0
conda install cudnn
(或
conda search cudatoolkit -c conda-forge
conda search cudnn -c conda-forge
conda install cudatoolkit==7.4 -c conda-forge
conda install cudnn==10.0.130 -c conda-forge
)


python
import tensorflow as tf
tf.test.gpu_device_name()
exit()

在实际安装的时候找不到cudnn7.4,所以直接使用了conda install cudnn命令,安装的cudnn版本为7.6.5,在使用时,需要将protobuf降低版本在3.20.x之下,降低之后也可以正常使用,不知道是不是cudnn版本能够向下兼容。后面使用vscode调试代码的时候还将gast版本降为了0.2.2。

但是在3090上再次安装此虚拟环境时,却一直遇到问题,包括tensorflow2.x版本。

2023.9.20更新,环境的问题解决了,3090上使用tensorflow2.15.0+python3.9+cudnn8.1+cudatoolkit11.2,解决的过程中看到3090最好配置cudatoolkit11.2以上

参考资料:

【仙女踩坑实录】conda找不到高版本(8.0)的cudnn_cudnn 8.0找不到_vivigreeeen的博客-CSDN博客

 https://zhuanlan.zhihu.com/p/610027015

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值