python-3.xtensorflowkerastensorflow2.0eager-execution

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?


Solution

  • 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()