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

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即可解决

猜你喜欢

转载自blog.csdn.net/weiyumeizi/article/details/78631697
今日推荐