title: TensorFlow's Print or K.print_tensor are not printing intermediate tensors in loss function
body: <p>I have written a rather complex loss function for a Keras model and it keeps returning <code>nan</code> while training. Therefore, I need to print the intermediate tensors while training. I understand that you cannot do K.eval in your loss function because the tensors are not initialized. However, I have tried both <code>K.print_tensor()</code> and <code>tf.Print()</code> and neither work. </p>
  
  <p>Pretty much I want to do something like this: </p>
  
  <pre><code>def mean_squared_error(y_true, y_pred):
      print("mean_squared_error")
      loss = K.mean(K.square(y_pred - y_true), axis=-1)
      loss = tf.Print(loss, [loss])
      return loss
  model.compile(optimizer=self.optimizer, loss=mean_squared_error)
  </code></pre>
  
  <p>In practice, I would replace <code>mean_squared_error</code> with my custom loss. "mean_squared_error" would get printed, but not the values I try to print using TensorFlow print (nor Keras print). I also tried the exact same code as in <a href="https://stackoverflow.com/q/49819438/3924118">How do I print inside the loss function during training in Keras?</a> and I still don't see anything getting printed in the console. </p>
  
  <p>In addition, I have written a separate file to test something. </p>
  
  <pre><code>import tensorflow as tf
  import keras.backend as K
  
  input1 = K.constant(1)
  input2 = K.constant(2)
  input3 = K.constant(3)
  
  node1 = tf.add(input1, input2)
  print_output = K.print_tensor(node1)
  output = tf.multiply(print_output, input3)
  </code></pre>
  
  <p>Nothing gets printed either. </p>
  
  <p>Am I using TensorFlow's <code>Print</code> and Keras <code>print_tensor</code> wrongly? Or are the results printed elsewhere? I have tried to test for my console's stderr using <code>print("test", file=sys.stderr)</code> and got the correct output <code>test</code>. </p>
  
  <p>For clarification, I know that you can use <code>K.eval</code> to make the test code print out values of the tensor, but since I cannot use <code>K.eval</code> in my loss function, I need to make <code>tf.Print</code> or <code>K.print_tensor</code> work. </p>