saved_model_cli的使用
saved_model_cli提供了从命令行直接查看,调用tensorflow的方法。
主要有show和run两个command。
用法一,显示所有内容(tags,signatures,inputs,outputs)
saved_model_cli show --all --dir
如:
>> saved_model_cli show --all --dir ./temp_model/1548813741
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:
signature_def['predict']:
The given SavedModel SignatureDef contains the following input(s):
inputs['30days_userprofile_category'] tensor_info:
dtype: DT_STRING
shape: (-1, 100)
name: Placeholder_4:0
The given SavedModel SignatureDef contains the following output(s):
outputs['logits'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 3)
name: dnn/logits/BiasAdd:0
outputs['probabilities'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 3)
name: dnn/head/predictions/probabilities:0
Method name is: tensorflow/serving/predict
用法二,调用模型进行预测,用法如下
usage: saved_model_cli run [-h] --dir DIR --tag_set TAG_SET --signature_def
SIGNATURE_DEF_KEY [–inputs INPUTS]
[–input_exprs INPUT_EXPRS]
[–input_examples INPUT_EXAMPLES] [–outdir OUTDIR]
[–overwrite] [–tf_debug]
例子:
>> saved_model_cli run --dir ./temp_model/1548813741 --tag_set serve --signature_def predict --input_exprs '30days_userprofile_category=np.random.rand(1,100).astype(np.str);7days_userprofile_category=np.random.rand(1,100).astype(np.str);alldays_userprofile_category=np.random.rand(1,100).astype(np.str);'
Result for output key logits:
[[-0.06087026 -0.0672477 -0.03029768]]
Result for output key probabilities:
[[0.4847871 0.48319438 0.4924262 ]]