糟糕,我在API中找到了该函数...
tf.to_float(x, name='ToFloat')
0
糟糕,我在API中找到了该函数...
tf.to_float(x, name='ToFloat')
0
您通常可以使用以下方法进行投放:
tf.cast(my_tensor, tf.float32)
将tf.float32替换为所需的类型。
编辑 :似乎至少在目前, tf.cast
不会转换为未签名的tf.uint8
(例如tf.uint8
)。要解决此问题,可以将其转换为已签名的等效项,并使用tf.bitcast
进行操作。例如
tf.bitcast(tf.cast(my_tensor, tf.int8), tf.uint8)
0
您可以使用tf.cast(x, tf.float32)
或tf.to_float(x)
,两者都tf.to_float(x)
为float32。
例:
sess = tf.Session()
# Create an integer tensor.
tensor = tf.convert_to_tensor(np.array([0, 1, 2, 3, 4]), dtype=tf.int64)
sess.run(tensor)
# array([0, 1, 2, 3, 4])
# Use tf.cast()
tensor_float = tf.cast(tensor, tf.float32)
sess.run(tensor_float)
# array([ 0., 1., 2., 3., 4.], dtype=float32)
# Use tf.to_float() to cast to float32
tensor_float = tf.to_float(tensor)
sess.run(tensor_float)
# array([ 0., 1., 2., 3., 4.], dtype=float32)
0
我试过了:
然后出现以下错误: