我正在尝试使用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标志运行save_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:{serv}
有什么想法会导致这种情况吗?
谢谢
答案 0 :(得分:0)
经过反复试验,看来问题出在我同时拥有tf.saved_model.TRAINING和tf.saved_model.SERVING标签
在构建模型时删除tf.saved_model.TRAINING标记时,一切正常