tensorflow_gpu InvalidArgumentError: Cannot assign a device for operation 'add' 错误

在新安装的tensorflow gpu 版本上编译代码,之前代码在cpu 上面都是可以执行的。

报如下错误:

InvalidArgumentError: Cannot assign a device for operation 'add': Operation was explicitly assigned to /device:GPU:1 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:GPU:0 ]. Make sure the device specification refers to a valid device.
     [[{{node add}} = Add[T=DT_FLOAT, _device="/device:GPU:1"](a_1, b_1)]]

解决方法:

将:

sess = tf.Session()

改为:

sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True))

 

你可能感兴趣的:(深度学习)