4

I have a tensor of type tf.int32 I would like to use tf.Print but I need the result to be in binary. Is this even possible? It is for debugging.

Example:

constant = tf.constant(5)
#magic
tf.Print(constant) # prints 101
1
  • Your best bet may be to redirect the output from the C stream, modify it using python, and the print it as binary. See this post for details. Commented Jan 6, 2018 at 4:28

1 Answer 1

3

You can use tf.py_function:

x = tf.placeholder(tf.int32)
bin_op = tf.py_function(lambda dec: bin(int(dec))[2:], [x], tf.string)

bin_op.eval(feed_dict={x: 5})   # '101'

But note that tf.py_function creates a node in the graph. So if you want to print many tensors, you can wrap them with tf.py_function before tf.Print, but doing this in a loop may cause bloating.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.