OperatorNotAllowedInGraphError:在图形执行中不允许将tf.Tensor用作Python布尔
嘿,我正在尝试将我的Keras模型转换为CoreML,但我一直遇到以下错误:OperatorNotAllowedInGraphError:在图形执行中不允许将tf.Tensor用作Python布尔,python,machine-learning,keras,coreml,coremltools,Python,Machine Learning,Keras,Coreml,Coremltools,嘿,我正在尝试将我的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. 这
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')
不知道我做错了什么。希望有一个答案 我认为错误来自您使用的Tensorflow和Keras版本。请将tensorflow降级为版本“1.14.0”,将Keras降级为版本“2.2.4”,也许这样可以解决问题