Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run into the following issue: build_tensor_flow is not supported in Eager Mode

I am playing around with TensorFlow, and I am trying to export a Keras Model as a TensorFlow Model. And I ran into the above-mentioned error. I am following the "Build Deep Learning Applications with Keras 2.0" from Lynda (https://www.linkedin.com/learning/building-deep-learning-applications-with-keras-2-0/exporting-google-cloud-compatible-models?u=42751868)

While trying to build a tensor flow model, I came across this error, thrown at line 66 where the add meta graphs and variables function is defined.

line 66, in build_tensor_info raise RuntimeError("build_tensor_info is not supported in Eager mode.") RuntimeError: build_tensor_info is not supported in Eager mode.

...model_builder.add_meta_graph_and_variables(
        K.get_session(),
        tags=[tf.compat.v1.saved_model.tag_constants.SERVING],
        signature_def_map={
            tf.compat.v1.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature_def
        }
    )
...

Any thoughts folks?

like image 595
Hazim Ahmed Avatar asked Mar 30 '20 05:03

Hazim Ahmed


People also ask

What is eager execution mode?

With eager execution enabled, TensorFlow functions execute operations immediately (as opposed to adding to a graph to be executed later in a tf. compat. v1. Session ) and return concrete values (as opposed to symbolic references to a node in a computational graph).

Is eager execution enabled?

Eager execution is enabled by default and this API returns True in most of cases. However, this API might return False in the following use cases.

Is eager mode slower?

Eager execution is slower than graph execution! Since eager execution runs all operations one-by-one in Python, it cannot take advantage of potential acceleration opportunities .


1 Answers

Is because you are using tensorflow v2. You have to use the tensorflow v2 compatibility and disable eager mode.

Be careful with the tensorflow imports that you use, for example if you use tensorflow_core, be sure that you are using all the dependencies from "tensorflow". You have to add before your code:

import tensorflow as tf
if tf.executing_eagerly():
   tf.compat.v1.disable_eager_execution()
like image 193
Cristian Zumelzu Avatar answered Nov 03 '22 19:11

Cristian Zumelzu