title: How can I print the intermediate variables in the loss function in TensorFlow and Keras?
body: <p>I'm writing a custom objective to train a Keras (with TensorFlow backend) model but I need to debug some intermediate computation. For simplicity, let's say I have:</p>
  
  <pre><code>def custom_loss(y_pred, y_true):
      diff = y_pred - y_true
      return K.square(diff)
  </code></pre>
  
  <p>I could not find an easy way to access, for example, the intermediate variable diff or its shape during training. In this simple example, I know that I could return diff to print its values, but my actual loss is more complex and I can't return intermediate values without getting compiling errors.</p>
  
  <p>Is there an easy way to debug intermediate variables in Keras?</p>