如何使用张量流服务?

时间:2019-02-06 05:40:32

标签: tensorflow tensorflow-serving

我正在学习使用Tensorflow服务,但是我很难找到包括Stackoverflow在内的示例。

我正在TensorFlow网站上使用鲜花示例。培训部分是成功的,并且很难部署。

我按如下方式运行服务器:

docker run -p 8501:8501 --mount type=bind,source=C:\tmp\saved_models,target=/models/flowers -e MODEL_NAME=flowers -t tensorflow/serving &

要查看所有SignatureDef,我使用了以下

saved_model_cli show --dir c:\tmp\saved_models\1 --all

响应为

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['image'] tensor_info:
        dtype: DT_STRING
        shape: ()
        name: DecodeJpeg/contents:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['classes'] tensor_info:
        dtype: DT_STRING
        shape: (5)
        name: Const:0
    outputs['prediction'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 5)
        name: final_result:0
  Method name is: tensorflow/serving/predict

如我所见here,它应该具有“方法名称为:tensorflow / serving / classify”

为什么我的示例中缺少它?

我的RESTAPI请求如下:

http://localhost:8501/v1/models/flowers/versions/1:classify

身体:

{
  "signature_name": "serving_default",
  "flowers": [
    {
      "image": { "b64": "c:/Users/pubud/OneDrive/Pictures/bird.jpg=" },
      "rose": "flower"
    }
  ]
}

我得到的错误是:

{
    "error": "Expected classification signature method_name to be tensorflow/serving/classify. Was: tensorflow/serving/predict"
}

我们非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您的RESTful URL指定...:classify,这与signature_def ['serving_default']-predict中的内容不同。

尝试将RESTful URL更改为...:predict,然后参考说明here来获取请求的json正文。

这里是有关SignatureDefs的更多信息: https://www.tensorflow.org/serving/signature_defs

祝你好运!