【问题标题】:OperatorNotAllowedInGraphError: using a tf.Tensor as a Python bool is not allowed in Graph executionOperatorNotAllowedInGraphError:Graph 执行中不允许使用 tf.Tensor 作为 Python bool
【发布时间】:2020-05-04 23:18:30
【问题描述】:

嘿,我正在尝试将我的 Keras 模型转换为 CoreML,但我不断收到此错误:

tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: using a tf.Tensor as 
a Python bool is not allowed in Graph execution. Use Eager execution or decorate this 
function with @tf.function.

这是我的代码:

import keras
import coremltools
import tensorflow as tf

model = keras.models.load_model('machine.h5')

print(model.input)
print(model.input_shape)
print(model.output)

model= coremltools.converters.keras.convert(
'machine.h5', input_name_shape_dict={'embedding_input:0': (None, 24)},
output_names=['dense_2/Sigmoid:0'])

model.save('xcodeModel.mlmodel')

不知道我在这里做错了什么。希望有答案!

【问题讨论】:

    标签: python machine-learning keras coreml coremltools


    【解决方案1】:

    我认为错误来自您使用的 Tensorflow 和 Keras 版本。请将 tensorflow 降级为“1.14.0”版本,将 Keras 降级为“2.2.4”版本,也许可以解决问题。

    【讨论】:

      猜你喜欢
      • 2018-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      • 2021-04-18
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      相关资源
      最近更新 更多