I am working on tensorflow 0.12 and am having problem with casting. The following snippet of code does a strange thing:
sess = tf.InteractiveSession()
a = tf.constant(1)
b = tf.cast(a, tf.float32)
print b.eval()
I get a value: 6.86574233e-36
I also tried using tf.to_float()
and tf.saturate_cast
. Both gave the same result.
Please help.
sess = tf.InteractiveSession()
a = tf.constant(1, tf.int64) <--------
b = tf.cast(a, tf.float32)
print b.eval() # 1.0
You need to declare the dtype
for your tf.constant
: https://www.tensorflow.org/api_docs/python/tf/constant
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With