张量流中gpu上的复杂梯度

时间:2017-02-16 21:22:52

标签: tensorflow

有人可以向我解释为什么以下代码无法运行:

import tensorflow as tf

TF_DEVICE = '/gpu:0'
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=False))

with tf.device("/gpu:0"):
    x = tf.Variable(1.0, name='x')
    y = tf.complex(x, x)
    z = tf.complex(tf.real(y), tf.imag(y))
    grads = tf.gradients(tf.abs(z), x)


init = tf.initialize_all_variables()
sess.run(init)
sess.run(grads)

但这样做:

import tensorflow as tf

TF_DEVICE = '/gpu:0'
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=False))

with tf.device("/gpu:0"):
    x = tf.Variable(1.0, name='x')
    y = tf.complex(x, x)
    z = y#tf.complex(tf.real(y), tf.imag(y))
    grads = tf.gradients(tf.abs(z), x)


init = tf.initialize_all_variables()
sess.run(init)
sess.run(grads)

这是张量流中的错误还是我错过了什么?

这是堆栈跟踪:

InvalidArgumentError: Cannot assign a device to node 'gradients/Real_grad/Complex': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
Colocation group had the following types and devices: 
AddN: CPU 
Complex: GPU CPU 
     [[Node: gradients/Real_grad/Complex = Complex[T=DT_FLOAT, Tout=DT_COMPLEX64, _device="/device:GPU:0"](gradients/Complex_1_grad/Reshape, gradients/Real_grad/Const)]]
Caused by op u'gradients/Real_grad/Complex', defined at:
...which was originally created as op u'Real', defined at:

0 个答案:

没有答案