且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

对TensorFlow服务的RaggedTensor请求失败

更新时间:2023-12-02 18:50:04

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. 
  }
})

我从此处了解了参差不齐的张量,看来第二个输入可能是行分区.我在文档中找不到有关通常使用哪种行分区样式的文档,因此我正在使用行长度方法. 幸运的是,参差不齐的TensorFlow提供了方法来为我们完成此任务.使用valuesrow_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.