tensorflow-gpu版安装

需要环境

  • Anaconda
  • CUDA
  • cuDNN
    注:tensorflow1.4用的是cuda8,cudnn6;tensorflow用的是cuda9,cudnn7,选择版本时要注意

CUDA安装

首先确认你的gpu支持CUDA,在这里可以看到

我用的是tensorflow1.4,因此cuda需要安装8.0版本的,安装9.0版本会报错,提示dll文件找不到下载地址
注:安装前需要先安装显卡驱动,可以去英伟达官网,下载GeForce Experience,自动检测驱动并下载,驱动装好后,再安装CUDA

cuDNN安装

下载地址,选择对应CUDA8.0的版本下载


将解压后的文件复制到CUDA的安装目录下

安装tensorflow-gpu

使用命令pip install tensorflow-gpu

测试代码

运行代码可以看到,使用的是gpu而不是cpu了!!!

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))
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容