How to obtain the gradients in keras? : <p>I am attempting to debug a <code>keras</code> model that I have built.  It seems that my gradients are exploding, or there is a division by 0 or some such.  It would be convenient to be able to inspect the various gradients as they back-propagate through the network.  Something like the following would be ideal:</p>

<pre><code>model.evaluate(np.array([[1,2]]), np.array([[1]])) #gives the loss
model.evaluate_gradient(np.array([[1,2]]), np.array([[1]]), layer=2) #gives the doutput/dloss at layer 2 for the given input
model.evaluate_weight_gradient(np.array([[1,2]]), np.array([[1]]), layer=2) #gives the dweight/dloss at layer 2 for the given input
</code></pre>
