0

I want to check some values of my Keras tensor. I tried to use backend.print_tensor.

I have changed my package code of Keras, and I changed the code tf.Print -> tf.print.

x = Dozat(21)(x) # custom Lambda layer

x = backend.print_tensor(x)

print('x : ', x, '\n\n\n')

This message occurred.

WARNING:
Print (from tensorflow.python.ops.logging_ops) is deprecated and will be removed after 2018-08-20.
Instructions for updating:
Use tf.print instead of tf.Print. Note that tf.print returns a no-output operator that directly prints the output. Outside of defuns or eager mode, this operator will not be executed unless it is directly specified in session.run or used as a control dependency for other operators. This is only a concern in graph mode. Below is an example of how to ensure tf.print executes in graph mode:

sess = tf.Session()
with sess.as_default():
    tensor = tf.range(10)
    print_op = tf.print(tensor)
    with tf.control_dependencies([print_op]):
      out = tf.add(tensor, tensor)
    sess.run(out)
Community
  • 1
  • 1
JKD_Spiegel
  • 31
  • 1
  • 2

1 Answers1

0

Your variable out is defined inside a with block, but you are trying to run it outside of the block in which it is defined. Try indenting your sess.run(out) to where it is valid.

sess = tf.Session()
with sess.as_default():
    tensor = tf.range(10)
    print_op = tf.print(tensor)
    with tf.control_dependencies([print_op]):
      out = tf.add(tensor, tensor)
      sess.run(out)
J Lossner
  • 129
  • 10
  • Thank you for your comment :). I appreciate your favor. I tried your way, and it works. The answer is goot, but that is not a exact answer that I want. I have a question. How do you usually do when you wanna check the value of your own tensor or layer's output?? Thanks. – JKD_Spiegel May 20 '19 at 00:15
  • @JKD_Spiegel Perhaps the answer to [this question](https://stackoverflow.com/a/33633839/11496617) is what you are looking for? – J Lossner May 20 '19 at 06:08