我已成功使用以下代码以 SavedModel 格式导出了seq2seq模型
source_tokens_ph = tf.placeholder(dtype=tf.string, shape=(1, None))
source_len_ph = tf.placeholder(dtype=tf.int32, shape=(1,))
features_serve = {
"source_tokens": source_tokens_ph,
"source_len": source_len_ph
}
experiment = PatchedExperiment(
...
export_strategies = [saved_model_export_utils.make_export_strategy(serving_input_fn = build_default_serving_input_fn(features_serve))]
)
Saved_model_cli显示导出的文件中存在以下SignatureDefs
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:
signature_def['default_input_alternative:default_output_alternative']:
The given SavedModel SignatureDef contains the following input(s):
inputs['source_ids'] tensor_info:
dtype: DT_INT64
shape: (-1, -1)
name: model/att_seq2seq/hash_table_1_Lookup:0
inputs['source_len'] tensor_info:
dtype: DT_INT32
shape: (-1)
name: model/att_seq2seq/Minimum:0
inputs['source_tokens'] tensor_info:
dtype: DT_STRING
shape: (-1, -1)
name: model/att_seq2seq/strided_slice:0
The given SavedModel SignatureDef contains the following output(s):
outputs['attention_context'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, 512)
name: model/att_seq2seq/transpose_4:0
outputs['attention_scores'] tensor_info:
dtype: DT_FLOAT
shape: unknown_rank
name: model/att_seq2seq/transpose_2:0
outputs['cell_output'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, 256)
name: model/att_seq2seq/transpose_1:0
outputs['features.source_ids'] tensor_info:
dtype: DT_INT64
shape: (-1, -1)
name: model/att_seq2seq/hash_table_1_Lookup:0
outputs['features.source_len'] tensor_info:
dtype: DT_INT32
shape: (-1)
name: model/att_seq2seq/Minimum:0
outputs['features.source_tokens'] tensor_info:
dtype: DT_STRING
shape: (-1, -1)
name: model/att_seq2seq/strided_slice:0
outputs['logits'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, 42)
name: model/att_seq2seq/transpose:0
outputs['predicted_ids'] tensor_info:
dtype: DT_INT32
shape: (-1, -1)
name: model/att_seq2seq/transpose_3:0
outputs['predicted_tokens'] tensor_info:
dtype: DT_STRING
shape: (-1, -1)
name: model/att_seq2seq/hash_table_3_Lookup:0
Method name is: tensorflow/serving/predict
signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['source_ids'] tensor_info:
dtype: DT_INT64
shape: (-1, -1)
name: model/att_seq2seq/hash_table_1_Lookup:0
inputs['source_len'] tensor_info:
dtype: DT_INT32
shape: (-1)
name: model/att_seq2seq/Minimum:0
inputs['source_tokens'] tensor_info:
dtype: DT_STRING
shape: (-1, -1)
name: model/att_seq2seq/strided_slice:0
The given SavedModel SignatureDef contains the following output(s):
outputs['attention_context'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, 512)
name: model/att_seq2seq/transpose_4:0
outputs['attention_scores'] tensor_info:
dtype: DT_FLOAT
shape: unknown_rank
name: model/att_seq2seq/transpose_2:0
outputs['cell_output'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, 256)
name: model/att_seq2seq/transpose_1:0
outputs['features.source_ids'] tensor_info:
dtype: DT_INT64
shape: (-1, -1)
name: model/att_seq2seq/hash_table_1_Lookup:0
outputs['features.source_len'] tensor_info:
dtype: DT_INT32
shape: (-1)
name: model/att_seq2seq/Minimum:0
outputs['features.source_tokens'] tensor_info:
dtype: DT_STRING
shape: (-1, -1)
name: model/att_seq2seq/strided_slice:0
outputs['logits'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, 42)
name: model/att_seq2seq/transpose:0
outputs['predicted_ids'] tensor_info:
dtype: DT_INT32
shape: (-1, -1)
name: model/att_seq2seq/transpose_3:0
outputs['predicted_tokens'] tensor_info:
dtype: DT_STRING
shape: (-1, -1)
name: model/att_seq2seq/hash_table_3_Lookup:0
Method name is: tensorflow/serving/predict
我使用Tensorflow Serving连接了模型,并发送了以下请求,
{
"inputs": {
"source_tokens": "[['DATE','OF','BIRT']]",
"source_ids": [],
"source_len": [3]
}
}
但是,它返回的结果为
{ “错误”:“模型/ att_seq2seq /最小:0被送入和获取。” }
参考该错误后,我可以看到可能由于同一张量fed and fetched而出现问题。
分析SignatureDef显示,model/att_seq2seq/Minimum:0
属于inputs['source_len']
和outputs['features.source_len']
我该如何解决?
可以不获取outputs['features.source_len']
吗?
如何为该存储库中使用的实验API手动分配 SignatureDefs ?