Getting value of a Tensor inside train_step when eager execution is enabled

I’m following the tutorial here to create a custom train_step. I’m trying to save some intermediate results (which are Tensor objects) inside a custom Model class with eager execution enabled.

When I try something like tf.keras.backend.get_value(some_tensor), some_tensor.numpy() inside the train_step, I get an error that Tensor object has no attribute numpy. I’ve also tried some_tensor.eval(session = tf.compat.v1.Session()) and also got an error. I’m wondering if there’s any way to extract the value of tensors computed inside the train_step.

1 Like