json - tensorflow 服务 : Expects arg[0] to be float but string is provided

标签 json tensorflow tensorflow-serving

Tensorflow Serving 返回标题中的错误信息,我不明白为什么。我通过回归 API 调用它,如下面的代码片段所示:

using RestSharp;
using Newtonsoft.Json;

var client_myclient = new RestClient("http://192.168.100.1:8501/v1/models/mymodel:regress");
// request preparation
json_prep.examples.Add( blah blah blah);
string json_prep_converted = JsonConvert.SerializeObject(json_prep, Formatting.Indented);
var req_ = new RestRequest(Method.POST);
req_.AddJsonBody(json_prep_converted);
// response
var res_mymodel = client_myclient.Execute(req_candle);

我的错误消息包含以下确认我发送内容的请求;它只是一个完全如下所示的示例,除了 ... 省略了几个条目:

{
  "examples": [
    {
      "a": [
        1.937336,
        ...
        -5.107522
      ],
      "b": [
        -0.704486,
        ...
        -6.868737
      ],
      "c": [
        2.817943,
        ...
        -4.226915
      ],
      "d": [
        -3.346308,
        -...
        -7.749344
      ],
      "e": [
        1.0625,
        -0.1875,
        ...
        -0.8125
      ],
      "f": [
        0.943968,
        -1.17052,
        ...
        0.641898
      ],
      "g": [
        0.22639801,
        ...
        0.19194462
      ],
      "h": [
        -1.449828,
        ...
        0.34936
      ],
      "i": [
        -50.61624,
        ...
        -17.362056
      ],
      "j": [
        0.148651,
        ...
        -0.228189
      ],
      "k": [
        0.16410813748132047,
        ...
        0.39454449551653981
      ],
      "l": [
        0.704047,
        ...
        -1.462873
      ],
      "m": [
        4.55,
        ...
        2.54
      ]
    }
  ]
}

JSON 消息经过双重检查,它不包含我将列表主体替换为 ... 的字符串(而且它不能根据定义)
我试图跟随 official manual on this .

更多细节,原始格式的错误是:

"{ \"error\": \"Expects arg[0] to be float but string is provided\" }"

如何解决这个错误?

最佳答案

你能用命令检查那个模型的 SignatureDefs吗,

saved_model_cli show --dir /usr/local/google/home/abc/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu/00000123 --all

正如您所说,您正在为回归签名执行推理,模型的签名定义应该是:

signature_def['regress_x_to_y']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['inputs'] tensor_info:
        dtype: DT_STRING
        shape: unknown_rank
        name: tf_example:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['outputs'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 1)
        name: y:0
  Method name is: tensorflow/serving/regress

当我的输入数据类型是 DT_FLOAT 而不是 DT_STRING 时,我遇到了与您类似的错误。

回归和分类签名期望输入数据类型为 DT_STRING (tf.examples)。因此,相应地更改它应该可以解决您的问题。

关于json - tensorflow 服务 : Expects arg[0] to be float but string is provided,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54680499/

相关文章:

java - Android首次使用addValueEventListener的方法

python - NotFoundError(请参阅上面的回溯): Key Variable not found in checkpoint

python - Tensorflow:批处理输入队列然后更改队列源

python - python 中的 RESTful API 请求 [tensorflow 服务]

tensorflow-serving - 操作类型未注册 'SentencepieceEncodeSparse' 二进制

json - 尝试从数组中获取字符串(打开天气图)

ios - 使用 SwiftyJson 从锁匠那里提取值(value)

python - TF-如何正确设置模型签名以与Docker一起使用?

json - R:将 JSON 通用扁平化为 data.frame

tensorflow - 如何在 TensorFlow 中调整参差不齐的张量中的元素大小