You can use either tf.cast(x, tf.float32)
or tf.to_float(x)
, both of which cast to float32.
Example:
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)