33

Durng the test of TensorFlow r0.12(CPU) installed on Windows 10, I found that the printed string contant is always with an 'b' in the end. The print of python is normal. I cannot figure out the reason so came here for help. The code is as follows:

>>>import tensorflow as tf
>>>hello = tf.constant('Hello, TensorFlow!')
>>>sess = tf.Session()
>>>print(sess.run(hello))
b'Hello, TensorFlow!'
Sakura
  • 333
  • 1
  • 3
  • 6

1 Answers1

45

Use sess.run(hello).decode() because it is a bytestring. decode method will return the string.

Your print statement must look like

print(sess.run(hello).decode())
kemis
  • 4,404
  • 6
  • 27
  • 40
  • 3
    The `Tensor` object has no attribute `decode`, so did you mean `print(sess.run(hello).decode())`? This worked for me. – ProfPlum Jun 15 '17 at 16:55
  • 7
    why isn't this mentioned on [Validate your tensorflow installation](https://www.tensorflow.org/install/install_windows#validate_your_installation)!? (I use 3.6.2 which should use unicode `str`) – Saravanabalagi Ramachandran Aug 22 '17 at 10:42
  • Yeah it's always a bummer when you're trying something new, and things don't go the way. Even little warnings can be really annoying. I hope they would fix that on the website. – deeJ Jan 14 '18 at 10:18
  • 3
    2018 and still not fixed on website. Thanks @kermis – Rich Feb 22 '18 at 18:32