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
2 Answers
Answers 1
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
Answers 2
I checked the code in python3 and python2 for the same tensorflow version as well the code seems to be working correctly as in both the cases I got the following output for python2
print b.eval() 1.0
I would suggest checking the tensorflow installation or the virtualenv.
0 comments:
Post a Comment