# Getting value of a Tensor inside train\_step when eager execution is enabled

**URL:** <https://discuss.ai.google.dev/t/getting-value-of-a-tensor-inside-train-step-when-eager-execution-is-enabled/30897>\
**Category:** General Discussion\
**Tags:** keras, models, tf-v1, help\_request\
**Created:** [June 11, 2021, 2:51am UTC](https://discuss.ai.google.dev/t/getting-value-of-a-tensor-inside-train-step-when-eager-execution-is-enabled/30897 "2021-06-11T02:51:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lu\_Bin\_Liu](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/lu_bin_liu/32/7046_2.png) [@Lu\_Bin\_Liu](https://discuss.ai.google.dev/u/Lu_Bin_Liu)\
**Post date:** [June 11, 2021, 2:51am UTC](https://discuss.ai.google.dev/t/getting-value-of-a-tensor-inside-train-step-when-eager-execution-is-enabled/30897/1 "2021-06-11T02:51:34Z")

</div>

I’m following the tutorial [here](https://keras.io/guides/customizing_what_happens_in_fit/) 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.

---

<div class="post-metadata">

**Author:** ![Kiran\_Sai\_Ramineni](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/kiran_sai_ramineni/32/8859_2.png) [@Kiran\_Sai\_Ramineni](https://discuss.ai.google.dev/u/Kiran_Sai_Ramineni)\
**Post date:** [January 15, 2025, 11:46am UTC](https://discuss.ai.google.dev/t/getting-value-of-a-tensor-inside-train-step-when-eager-execution-is-enabled/30897/3 "2025-01-15T11:46:36Z")

</div>

Hi @Lu_Bin_Liu, You can define a list in the custom train step and can append the values which you want and after training the model you can access those values. please refer to this [gist](https://gist.github.com/kiransair/975a1f7e02bef0a7698a2b80c8442f8b) for code example. Thank You.
