tensorflow安装

Linux系统安装

Linux CentOS 7.6

tensorflow 2安装

tensorflow 2.x不再区分是否gpu,当检测到gpu并安装cuda后,自动调用gpu。

  • conda创建虚拟环境
conda create --name tf2 python=3.7
  • 查看gpu
nvidia-smi
  • conda安装cuda和cudnn
    • CUDA(ComputeUnified Device Architecture),是显卡厂商NVIDIA推出的运算平台。 CUDA是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。
    • NVIDIA cuDNN是用于深度神经网络的GPU加速库。可以集成到更高级别的机器学习框架中,如谷歌的Tensorflow。
    • CUDA看作是一个工作台,上面配有很多工具,如锤子、螺丝刀等。cuDNN是基于CUDA的深度学习GPU加速库,有了它才能在GPU上完成深度学习的计算。但是CUDA这个工作台买来的时候,并没有送扳手。
conda install cudatoolkit=10.1
conda install cudnn=7.6.5
  • pip安装tf库(用清华镜像源)
pip install tensorflow==2.1.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

python验证安装是否成功,如果 tf.config.list_physical_devices(‘GPU’) 输出为 空列表 ,则不支持 GPU ,如果有输出则支持 GPU。虽然import后会有警告但还是能使用。。

 import tensorflow as tf
 tf.__version__
 tf.config.list_physical_devices('GPU')

tensorflow 1.14-gpu安装

conda create --name tf python=3.6.5
source 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=7.6

进入python,验证是否成功在GPU上运行

import tensorflow as tf
tf.test.is_gpu_available()

tensorflow 1.13安装(cpu)

  • conda创建虚拟环境
    conda create --name tfcpu python=3.6.5
    conda activate tfcpu
  • pip安装tf库(用清华镜像源)
    pip install tensorflow==1.13.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

Windows系统安装

tensorflow-gpu 1.15安装

踩坑经历,这里由于cudnn安装不是很顺畅,以下步骤不建议参照

conda install cudatoolkit=10.0
pip install tensorflow-gpu==1.15.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

cudnn安装本来应该是7.4,我下的7.6而且还是linux版晕,以下就是反面教材

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

运行以下代码检测tensorflow的确用gpu来做运算

import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))

出现下图红框信息即成功
在这里插入图片描述

我这边没有直接成功,而是报下面这个错误

Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform

解决方案:复制cudnn64_7.dll到(省略)\Anaconda3\Library\bin里即可,这里官网要注册账号、每一步都容易报503错,建议换网以及多次尝试,我是取得这里的百度盘链接,感谢啊

最难过的好不容易能用GPU跑之后说gpu内存不够

tensorflow.python.framework.errors_impl.ResourceExhaustedError: 2 root error(s) found.

tensorflow 1.13安装(cpu)

  • conda创建虚拟环境
    conda create --name tfcpu python=3.6.5
    activate tfcpu
  • pip安装tf库(用清华镜像源)
    pip install tensorflow==1.13.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

参考资料

★官网版本对应性
tensorflow / tensorflow-gpu / tensorflow-cpu区别?
CUDA与cuDNN
简单粗暴 TensorFlow 2
windows如何检查显卡支持CUDA的最高版本
WIN10安装TENSORFLOW(GPU版本)详解(超详细,从零开始)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值