AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'

Viewed 29379

I just tried to enable eager execution in my shell which is actually showing an error:

AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'

My Tensorflow version is 2.0

The image shows my tensorflow version

can anyone tell me why am I getting this...

Thanks in advance

7 Answers

Tensorflow 2.0 has eager_execution enabled by default and so there is no need for you to run tf.enable_eager_execution. Only if your running versions below 2.0 should you enable eager execution

Eager execution is enabled by default in version 2.x You can check that by using

tf.executing_eagerly()

It should return True. If you are having version less then 2.0 then it can be enabled by using

tf.enable_eager_execution()

for tensorflow v1.x code, this will works:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
tf.enable_eager_execution()

Eager enabled by default in tf2, you do can disable it as below

import tensorflow as tf

tf.compat.v1.disable_eager_execution()

If you do have to call something, tf.compat.v1.enable_eager_execution is available.

Eager execution mode was added to Tensorflow starting with version 1.8. So an update is necessary. In addition, it is a relatively new feature with many glitches and frequent updates, so using the most recent version that can work for you is recommended. Try

conda update tensorflow

or with pip

pip install --upgrade Tensorflow

I have Keras v2.1.0 installed. Eager_execution was not enabled by default and import tensorflow.contrib.eager as tfe tfe.enable_eager_execution()

did not work for me. (A check using tf.executing_eagerly() returned False.)

However, what worked for me was:

import tensorflow as tf tf.enable_eager_execution()

Note: tf.placeholder() is not compatible with eager execution.

Related