0
我具有低於Python的Tensorflow運行在GPU代替CPU
import tensorflow as tf
with tf.device('/cpu:0'):
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)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess)
print(sess.run(c))
樣品tensorflow代碼明確我已經給tf.device( '/ CPU:0'),但它給以下錯誤:
InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'MatMul_5': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/cpu:0 ]. Make sure the device specification refers to a valid device.
[[Node: MatMul_5 = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/device:GPU:0"](a_5, b_5)]]
Tensorflow版本:1.3.0, Python版本:3.6.1與蟒蛇分佈
嘗試在'ConfigProto'的參數列表中添加'allow_soft_placement = True' – CoryKramer