python - TensorFlow 运行时错误 : MetaGraphDef associated with tags serve could not be found in SavedModel

标签 python tensorflow

当我使用 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/

相关文章:

python - np.mean 和 tf.reduce_mean 有什么区别?

python - 将一张图复制到另一张图

python - Flask-RESTful 项目结构

python - 在 __next__() 中修改对象之前返回对象

python - 用于训练/验证/测试集拆分的 SHA 哈希

python - 使用gather_nd构建矩阵

python - 来自 Keras 应用程序模块的 TensorFlow/Keras : How to get missing models (ResNet101, ResNeXt 等)?

python - docker中的tensorflow镜像是否使用GPU?

python - pandas DataFrame DatetimeIndex 切片错误

python - 为什么Django说没有名为views的模块?