TypeError: ‘tensorflow.python.framework.ops.EagerTensor’ object is not callable

EagerTensor is a Tensor object in TensorFlow that represents a value immediately available in memory. The tf.Tensor objects represent symbolic handles to a computation executed when the TensorFlow graph is run, EagerTensor objects are evaluated, and their values are immediately available.

TypeError:’tensorflow.python.framework.ops.EagerTensor’ object is not callable

The TypeError: ‘tensorflow.python.framework.ops.EagerTensor’ object is not callable error occurs when you try to call a TensorFlow EagerTensor object as if it were a function or method.

If you forget to use the .numpy() method to convert the EagerTensor to a NumPy array before calling it, this TypeError will be raised. See the below code.

import tensorflow as tf

tenr = tf.constant([11, 21, 19])

output = tenr()

Output

TypeError: 'tensorflow.python.framework.ops.EagerTensor' object is not callable

How to fix TypeError: ‘tensorflow.python.framework.ops.EagerTensor’ object is not callable

To fix TypeError: ‘tensorflow.python.framework.ops.EagerTensor’ object is not callable, ensure that you are not calling an EagerTensor object without the use of the .numpy() method, which will convert the EagerTensor to a NumPy array and then call the NumPy array as a function.

import tensorflow as tf
import numpy as np

tenr = tf.constant([11, 21, 19])

output = np.square(tenr.numpy())

print(output)

Output

[121 441 361]

And we successfully converted an EagerTensor to a numpy array, and the TypeError is resolved.

That’s it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.