I am training a NN implemented in TensorFlow Keras.
model.fit(..., callbacks=[..., CustomCallback()])
My objective - during the training get:
- Gradients: params - the gradients used to update the weights, and layer propagated gradients.
- Bias
- BatchNorm: running mean, running var, Gamma, Beta
- Getting the input and target
I am using keras.callbacks.Callback
class CustomCallback(keras.callbacks.Callback):
...
def on_train_batch_end(self, batch, logs=None):
# 1.) Get gradients
# 2.) Get bias
# 3.) Get BN: running mean, running var, Gamma, Beta
# 4.) Input and target
I found how to get weights from self.model
. How do I get all the tensors I have mentioned?
You can get all tensors values in the following manner:
fetches_names - a list of strings, include names of tensors we wish to read Reading only the gradients may be done by calling to the gradients function form Keras backend:
The thing with this function is that it edits the graph.