我刚刚成功安装了tensorflow-gpu
。之后,我还成功安装了tensorflow
。我在spyder3
上尝试了以下代码:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
但是结果是:
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 18318063967424845606
]
似乎Tensorflow的GPU版本不起作用!我该如何解决?
我还必须提到我的笔记本电脑有2个图形卡,为此我安装CUDA / cuDNN的第二张卡是Geforce GTX 960M
。
我还尝试了以下代码:
import tensorflow as tf
# Creates a graph.
with tf.device('/device:GPU:2'):
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 allow_soft_placement and log_device_placement set
# to True.
sess = tf.Session(config=tf.ConfigProto(
allow_soft_placement=True, log_device_placement=True))
# Runs the op.
print(sess.run(c))
并得到以下结果:
[[22. 28.]
[49. 64.]]