Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 运行时错误:无法加载SavedModel或.h5模型。找不到作为ReadVariableOp输入的占位符op_Python_Tensorflow_Keras - Fatal编程技术网

Python 运行时错误:无法加载SavedModel或.h5模型。找不到作为ReadVariableOp输入的占位符op

Python 运行时错误:无法加载SavedModel或.h5模型。找不到作为ReadVariableOp输入的占位符op,python,tensorflow,keras,Python,Tensorflow,Keras,我正在尝试将我的模型转换并保存到CoreML。我正在使用tf.keras,这是我的代码 import keras import coremltools import tensorflow as tf keras_model = tf.keras.models.load_model('machine.h5') print(keras_model.input.name) print(keras_model.input_shape) print(keras_model.output.name)

我正在尝试将我的模型转换并保存到CoreML。我正在使用tf.keras,这是我的代码

import keras
import coremltools
import tensorflow as tf

keras_model = tf.keras.models.load_model('machine.h5')

print(keras_model.input.name)
print(keras_model.input_shape)
print(keras_model.output.name)

output_labels = ['0', '1']

keras_model= coremltools.converters.tensorflow.convert(
'machine.h5', input_name_shape_dict={'embedding_input': (None, 24)},
output_feature_names=['Identity'])

model.save('xcodeModel.mlmodel')
我不断地发现这个错误:

Traceback (most recent call last):
  File "/Users/shenoyaar/MACHINES_LEARN/venv/lib/python3.6/site-packages/coremltools/converters/tensorflow/_tf_converter.py", line 213, in _graph_def_from_saved_model_or_keras_model
    frozen_func = _convert_to_constants.convert_variables_to_constants_v2(concrete_func)
  File "/Users/shenoyaar/MACHINES_LEARN/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/convert_to_constants.py", line 506, in convert_variables_to_constants_v2
    raise ValueError("Cannot find the Placeholder op that is an input "
ValueError: Cannot find the Placeholder op that is an input to the ReadVariableOp.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "convert.py", line 15, in <module>
    output_feature_names=['Identity'])
  File "/Users/shenoyaar/MACHINES_LEARN/venv/lib/python3.6/site-packages/coremltools/converters/tensorflow/_tf_converter.py", line 160, in convert
    filename = _graph_def_from_saved_model_or_keras_model(filename)
  File "/Users/shenoyaar/MACHINES_LEARN/venv/lib/python3.6/site-packages/coremltools/converters/tensorflow/_tf_converter.py", line 218, in _graph_def_from_saved_model_or_keras_model
    raise RuntimeError('Failed to load SavedModel or .h5 model. {}.'.format(e))
RuntimeError: Failed to load SavedModel or .h5 model. Cannot find the Placeholder op that is an input to the ReadVariableOp..
回溯(最近一次呼叫最后一次):
文件“/Users/shenoyar/MACHINES\u LEARN/venv/lib/python3.6/site packages/coremltools/converters/tensorflow/\u tf\u converter.py”,第213行,来自保存的模型或keras模型的图形定义
冻结函数=\u转换为常数。转换变量为常数(具体函数)
文件“/Users/shenoyar/MACHINES\u LEARN/venv/lib/python3.6/site packages/tensorflow\u core/python/framework/convert\u to\u constants.py”,第506行,在convert\u variables\u to\u constants\u v2中
raise VALUERROR(“找不到作为输入的占位符op”)
ValueError:找不到作为ReadVariableOp输入的占位符op。
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“convert.py”,第15行,在
输出特征名称=['Identity'])
文件“/Users/shenoyar/MACHINES\u LEARN/venv/lib/python3.6/site packages/coremltools/converters/tensorflow/_tf\u converter.py”,第160行,转换为
filename=_graph_def_from_saved_model_或_keras_model(文件名)
文件“/Users/shenoyar/MACHINES\u LEARN/venv/lib/python3.6/site packages/coremltools/converters/tensorflow/\u tf\u converter.py”,第218行,来自保存的模型或keras模型的图形定义
raise RUNTIMERROR('未能加载SavedModel或.h5模型。{}..format(e))
运行时错误:无法加载SavedModel或.h5模型。找不到作为ReadVariableOp输入的占位符op。。

这是一个文本分类模型,而不是图像分类模型。

回答之前,您应该阅读以下内容:回答之前,您应该阅读以下内容: