您的位置:首页 > 大数据 > 人工智能

tensorflow小白---Operation was explicitly assigned to /device:GPU:1 but available devices are [ /job:l

2017-11-25 14:42 651 查看
1、

import tensorflow as tf
c1=tf.constant(5.0)
c2=tf.constant(2.0)
c=c1*c2
sess=tf.Session()
result=sess.run(c)
print (result)
sess.close()


10.0

运行后不报错

然后再运行

2

with tf.Session() as sess:
with tf.device("/gpu:1"):
matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul(matrix1, matrix2)


运行不报错

再运行1

import tensorflow as tf
c1=tf.constant(5.0)
c2=tf.constant(2.0)
c=c1*c2
sess=tf.Session()
result=sess.run(c)
print (result)
sess.close()


报错

操作挂载到了gpu:1上,但是可用设备只有cpu:0

InvalidArgumentError: Cannot assign a device for operation 'MatMul': Operation was explicitly assigned to /device:GPU:1 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
[[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/device:GPU:1"](Const_4, Const_5)]]


根据提示执行

4 不报错

with tf.Session() as sess:
with tf.device("/cpu:0"):
matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul(matrix1, matrix2)


再执行1还是报错

InvalidArgumentError: Cannot assign a device for operation 'MatMul': Operation was explicitly assigned to /device:GPU:1 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
[[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/device:GPU:1"](Const_4, Const_5)]]


解决方法,不关闭当前页面而是shutdown当前的jupter,再重新启动jupyter即可解决
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tensorflow
相关文章推荐