3

I need to monitor the gradients in real time during training when using fit or fit_generator methods. This should have been achieved by using custom callback function. However, I don't how to access the gradients correctly. The attribute model.optimizer.update returns tensors of gradients but it need to be fed with data. What I want to get is the value of gradients that have been applied in the last batch during training.

The following answer does not give the corresponding solution because it just define a function to calculate the gradients by feeding extra data.

Getting gradient of model output w.r.t weights using Keras

JunjieChen
  • 385
  • 2
  • 13
  • Try to look at keras source code, of [TensorBoard callback](https://github.com/keras-team/keras/blob/3bda5520b787f84f687bb116c460f3aedada039b/keras/callbacks.py#L1069). It has argument `write_grads`, so it somehow gets those grads and visualizes them through TensorBoard. You can do the same but do not visualize it. – Khan Jul 10 '19 at 11:23

0 Answers0