当我使用 simple_save 保存模型时,当我尝试加载模型时遇到运行时错误。
要保存的代码是:
session = Session()
inputs = tf.placeholder(dtype=tf.float32, shape=(None, height, width, in_channel_size), name='input_img')
model = Some_Model(inputs, num_classes=no_of_defects, is_training=False)
logits, _ = model.build_model()
predictor = tf.nn.softmax(self.logits, name='logits_to_softmax')
feed_dict = {inputs: inputs}
prediction_probabilities = session.run(self.predictor, feed_dict=feed_dict)
tf.saved_model.simple_save(self.session, path,
inputs={"inputs" : self.inputs},
outputs={"predictor": self.predictor})
要加载的代码是:
tf.saved_model.loader.load(session, tag_constants.SERVING, path)
给出了错误:
RuntimeError: MetaGraphDef associated with tags serve could not be found in SavedModel. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: `saved_model_cli`
当我运行时
saved_model_cli show --dir path --tag_set serve --signature_def serving_default
我明白了
The given SavedModel SignatureDef contains the following input(s):
inputs['inputs'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 512, 1024, 8)
name: input_img:0
The given SavedModel SignatureDef contains the following output(s):
outputs['predictor'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 512, 1024, 25)
name: logits_to_softmax:0
Method name is: tensorflow/serving/predict
我做错了什么?
最佳答案
问题出在加载调用上。应该是:
tf.saved_model.loader.load(session, [tag_constants.SERVING], path)
tag_constants
位于 tf.saved_model.tag_constants
。
关于python - TensorFlow 运行时错误 : MetaGraphDef associated with tags serve could not be found in SavedModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52209587/