TF2: Compute gradients in keras callback in non-eager mode
问题 TF Version: 2.2.0-rc3 (in Colab) I am using the following code (from tf.keras get computed gradient during training) in a callback to compute gradients for all parameters in a model. def on_train_begin(self, logs=None): # Functions return weights of each layer self.layerweights = [] for lndx, l in enumerate(self.model.layers): if hasattr(l, 'kernel'): self.layerweights.append(l.kernel) input_tensors = [self.model.inputs[0], self.model.sample_weights[0], self.model.targets[0], K.learning_phase