Linux快速搭建tensorflow-gpu 1.15.0环境&Keras(包括30系显卡)

1.创建虚拟环境:tmp_python

conda create -n tf python=3.6

温馨提醒:python3.8暂不支持tensorflow-gpu 1.15版本,请使用python3.6版本

2.显示自己创建的虚拟环境

conda env list

3.进入创建虚拟环境

source activate tf

4.安装指定 版本的TensorFlow

ps:若为tensorflow1.x版本则执行:

pip3 install tensorflow-gpu==1.15.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

ps:若为tensorflow2.x版本则执行:

pip3 install tensorflow-gpu==2.1.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

5.安装的包(务必执行)

ps:若为tensorflow1.x版本则执行:

conda install cudatoolkit=10.0 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/
conda install cudnn=7.6.5 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/

ps:若为tensorflow2.x版本则执行:

conda install cudatoolkit=10.1 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/
conda install cudnn=7.6.5 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/

小技巧:若安装其他版本,先查看Tensorflow-gpu对应支持的cuda版本(官网),然后进入清华镜像网站,搜索cudnn,然后找到对应的cuda版本

6.验证是否安装成功

先输入python进入交互式界面,然后用如下命令验证是否gpu版本启用

import tensorflow as tf
tf.test.is_gpu_available()

若最后显示True,则恭喜你,安装成功!
在这里插入图片描述

7.安装Keras(可选)

Keras需要在TensorFlow之上才能运行,所以要先安装Tensorflow;安装完Tensorflow后,输入以下命令安装Keras:

pip install keras==2.3.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

ps:附上keras与tensorflow对应版本的链接:https://master–floydhub-docs.netlify.app/guides/environments/

选看部分(踩过的坑)

针对RTX30系的显卡(如RTX3080),要注意cudatoolkit为10.x时并不能兼容,RTX30系的显卡需要安装cudatoolkit为11.x的版本,注意:可以去https://tensorflow.google.cn/install/source?hl=zh-cn#linux查看当前cuda版本所能支持的tensorflow的对应版本,至少为tensorflow-gpu-2.4.0版本以上。然后去https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/中找到对应的cuda和cudnn版本。这里博主踩了一个坑,按照官网查到的11.0版本安装cuda,结果清华镜像源的cudnn版本没有11.0版本的cuda,因此安装的时候发生了找不到包的情况。
解决方案如下:
安装11.3版本的cuda以及cudnn8.2.1版本!
在这里插入图片描述
具体命令:

conda install cudatoolkit=11.3 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/
conda install cudnn=8.2.1 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/
  • 17
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值