votes up 2

eval is not supported when eager execution is enabled, is .numpy() what you're looking for?

Package:
Exception Class:
NotImplementedError

Raise code

    "_as_node_def_input not supported when eager execution is enabled.")

  def _as_tf_output(self):
    raise NotImplementedError(
        "_as_tf_output not supported when eager execution is enabled.")

  def eval(self, feed_dict=None, session=None):
    raise NotImplementedError(
        "eval is not supported when eager execution is enabled, "
        "is .numpy() what you're looking for?")


# This call creates an EagerTensor class, as a subclass of _EagerTensorBase, and
# registers it with the current module.
# It is exposed as an __internal__ api for now (b/171081052), though we
# ex

Ways to fix

votes up 2 votes down

Calling the eval method on a tensor is not supported when eager execution is enabled. In Tensorflow2 eager execution is enabled by default which means .eval is method is not supported by default.

Here is the code that reproduce this exception:

import tensorflow as tf 
x = tf.constant([5,2,3,4,1]) 
x.eval()

--------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) <ipython-input-2-3a8b655810af> in <module>() 1 import tensorflow as tf 2 x = tf.constant([5,2,3,4,1]) ----> 3 x.eval() /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py in eval(self, feed_dict, session) 1279 def eval(self, feed_dict=None, session=None): 1280 raise NotImplementedError( -> 1281 "eval is not supported when eager execution is enabled, " 1282 "is .numpy() what you're looking for?") 1283 NotImplementedError: eval is not supported when eager execution is enabled, is .numpy() what you're looking for?

Fixed version:

First disable the eager execution using this line of code

import tensorflow as tf from tensorflow.compat.v1 import Session as sess tf.compat.v1.disable_eager_execution() x = tf.constant([5,2,3,4,1]) sess = tf.compat.v1.Session() x.eval(session=sess)

array([5, 2, 3, 4, 1], dtype=int32)

Nov 09, 2021 kellemnegasi answer
kellemnegasi 18.3k

Add a possible fix

Please authorize to post fix