title: Keras metric based on output of an intermediate layer
body: <p>Problem:
  I want to monitor my model better during training. Because in some cases the loss suddenly turn to nan during training, and I want to know what the model is doing when this happens.
  Besides that, I want to see if a certain layer obeys a specific condition (rows and columns should sum to one).</p>
  
  <p>Approach:
  Defining a custom metric wont help, since this one will only work on <code>y_pred</code> and <code>y_true</code>. Maybe there is some complex solution with building a model within a model, and trying to somehow calculate a metric on the output of the intermediate-model layer. But that feels a bit too complex.</p>
  
  <p>Solution:
  The only thing I could think of otherwise is to switch to Tensorflow itself, so that I have more control over the training process. Any other ideas?</p>