我正在尝试使用tensorflow-serving(如果有任何区别,请加载到docker上,以服务于经过训练的Tensorflow模型)
训练模型后,我使用以下代码保存了它:
prediction_signature = (
tf.saved_model.signature_def_utils.build_signature_def(
inputs={'verif': tensor_info_input, 'enroll': tensor_info_input},
outputs={'similarity_matrix': tensor_info_output},
method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME))
with tf.Session(graph=loaded_graph) as sess:
# Restore from checkpoint
loader = tf.train.import_meta_graph(trained_checkpoint_prefix + '.meta')
loader.restore(sess, trained_checkpoint_prefix)
# Export checkpoint to SavedModel
builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
builder.add_meta_graph_and_variables(sess,
[tf.saved_model.TRAINING, tf.saved_model.SERVING],
signature_def_map={
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: prediction_signature,
})
builder.save()
并且在版本文件夹上使用--all标志运行saved_model_cli之后,我得到以下响应:
MetaGraphDef with tag-set: 'train, serve' contains the following SignatureDefs: signature_def['serving_default']: The given SavedModel SignatureDef contains the following input(s): inputs['enroll'] tensor_info: dtype: DT_FLOAT shape: (80, 20, 40) name: Const:0 inputs['verif'] tensor_info: dtype: DT_FLOAT shape: (80, 20, 40) name: Const:0 The given SavedModel SignatureDef contains the following output(s): outputs['similarity_matrix'] tensor_info: dtype: DT_FLOAT shape: (20, 4) name: add_1:0 Method name is: tensorflow/serving/predict
但是-尝试提供服务时,我仍然收到以下错误:
正在加载可服务的:{名称:服务版本:0}失败:找不到:可以找不到与提供的标签匹配的元图def:{serve}
任何想法可能是什么原因造成的?
谢谢
经过反复试验,似乎问题出在我同时拥有tf.saved_model.TRAINING和tf.saved_model.SERVING标签
[当我在构建模型时删除tf.saved_model.TRAINING标记时,一切正常