遇到以下问题:急切模式不支持build_tensor_flow

时间:2020-03-30 05:01:25

标签: python-3.x tensorflow keras tensorflow2.0 eager-execution

我正在玩TensorFlow,并且试图将Keras模型导出为TensorFlow模型。而且我遇到了上述错误。我正在遵循Lynda(https://www.linkedin.com/learning/building-deep-learning-applications-with-keras-2-0/exporting-google-cloud-compatible-models?u=42751868)的“使用Keras 2.0构建深度学习应用程序”

在尝试构建张量流模型时,我遇到了此错误,抛出了66行,其中定义了添加元图和变量函数。

第66行,位于build_tensor_info中 提高RuntimeError(“急切模式不支持build_tensor_info。”) RuntimeError:Eager模式不支持build_tensor_info。

...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
        }
    )
...

有什么想法的人吗?

1 个答案:

答案 0 :(得分:7)

是因为您正在使用tensorflow v2。您必须使用tensorflow v2兼容性并禁用eager模式。

请谨慎使用所使用的tensorflow导入,例如,如果使用tensorflow_core,请确保使用的是“ tensorflow”中的所有依赖项。 您必须在代码之前添加:

import tensorflow as tf
if tf.executing_eagerly():
   tf.compat.v1.disable_eager_execution()