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
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
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.