更新时间:2023-12-02 18:42:22
https://www.tensorflow.org/tfx/serving/api_rest#predict_api
我认为您需要使用 REST API 中推荐的列格式而不是行格式,因为您的第 0 个输入的尺寸不匹配.这意味着您将不得不使用输入而不是实例.由于您还有多个输入,因此您还必须将其作为命名输入提及.
I think that you need to use a columnar format as recommended in the REST API instead of the row format because the dimensions of your 0th input do not match. This means that instead of instances you will have to use inputs. Since you also have multiple inputs, you will have to also mention that as a named input.
示例数据请求可能如下所示
A sample data request could look like this
data = json.dumps({
"inputs": {
"args_0": [[-0.9984272718429565, -0.9422321319580078, -0.27657580375671387, -3.185823678970337, -0.6360141634941101, -1.6579184532165527, -1.9000954627990723, -0.49169546365737915, -0.6758883595466614, -0.6677696704864502, -0.532067060470581],
[-0.9984272718429565, -0.9421600103378296, 2.2048349380493164, -1.273996114730835, -0.6360141634941101, -1.5917999744415283, 0.6147914528846741, -0.49169546365737915, -0.6673409938812256, -0.6583622694015503, -0.5273991227149963]],
"args_0_1": [10, 11] #Substitute this with the correct row partition values.
}
})
我从 here 读到了 Ragged tensors,似乎第二个输入可能是行分区.我在有关通常使用的行分区样式的文档中找不到它,所以我使用的是行长度方法.幸运的是,TensorFlow ragged 为我们提供了方法.使用 values
和 row_splits
属性来访问它们.那应该可行.
I read about Ragged tensors from here and it seems that the second input may be the row partitions. I couldn't find it in the documentation about what row partition style is normally used so I am using the row lengths method.
Luckily TensorFlow ragged provides methods that do this for us. Use the values
and row_splits
properties to access them. That should work.