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\" }"
如何解决此错误?
答案 0 :(得分:0)
您能否使用命令检查该模型的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)。因此,相应地更改它应该可以解决您的问题。