Python语言与信息数据获取和机器学习

tensorflow-gpu版安装

2018-01-24  本文已影响2015人  听城

需要环境

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))
上一篇 下一篇

猜你喜欢

热点阅读