【问题标题】:How to make REST calls to a served TensorFlow model using JSON?如何使用 JSON 对服务的 TensorFlow 模型进行 REST 调用?
【发布时间】:2018-04-12 17:58:39
【问题描述】:

我已经构建并训练了一个 TensorFlow 模型,该模型使用 tf.Estimator 范式进行部署。我已经建立了一个如下所示的服务功能:

def serving_input_fn(params):
    feature_placeholders = {
        'inputs' : tf.placeholder(tf.int64, [None], name='inputs')
    }
    features = {
        key: tensor
        for key, tensor in feature_placeholders.items()
    }
    return tf.estimator.export.ServingInputReceiver(features, feature_placeholders) 

现在,我希望能够使用 application/json 作为内容类型来调用它。所以我构建了一个 JSON 文件,就像我在 question 中找到的示例一样:

payload = {'instances': [{'inputs': [1039]}]}
json_string = json.dumps(payload)

当我调用模型时,我会返回:

ERROR in serving: Unsupported request data format: {u'instances': [{u'inputs': [1039]}]}.
Valid formats: tensor_pb2.TensorProto, dict<string, tensor_pb2.TensorProto> and predict_pb2.PredictRequest

有什么想法可以实现我的目标吗?

【问题讨论】:

    标签: tensorflow tensorflow-serving


    【解决方案1】:

    事实证明 JSON 应该是:

    request = {'dtype': 'DT_INT64', 
               'tensorShape': {'dim':[{'size': 1}]},
               'int64Val': [1039]}
    
    json_string = json.dumps(request)
    

    【讨论】:

      猜你喜欢
      • 2021-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 1970-01-01
      • 2018-01-26
      • 2019-08-12
      相关资源
      最近更新 更多