Closed adriangay closed 3 years ago
Hi, @adriangay, as you've correctly guessed, you can pass an array of numbers as float_val
or a base64-encoded string as string_val
. That's not the problem.
but Tensorflow complains about the tensor shape
I am pretty sure your problem is the shape, not the contents.
I assume the TensorShapeProto
you are trying to use is this one.
Your example has this:
"tensor_shape": [
{"dim": {
"size": 1
}},
{"dim": {
"size": 252
}}
],
But the tensor_shape
field is not repeated, so it should not be an array. And the dim
field therein is repeated, so it should be an array. So I think you've got the array vs. object relationship backwards. You want this instead:
"tensor_shape": {
"dim": [
{"size": 1},
{"size": 252}
]
},
@jhump Thank you so much for this. I have been staring at this for far too long and was looking at the Tensor array data for the issue. I feel so dumb! :) Yes, that was it.
Trying to get grpcurl to send a predict request to Tensorflow Serving. If I use protobuf text representation, I get a successful prediction result. But I've been unable to create a JSON representation that works. In fact the only way I managed to get the text version to work was by using
google.protobuf.text_format()
to dump a Predict request message to a file then cat it into stdin. The issue seems to be in serialising the tensor float array from JSON . Several different type representations are provided, but they all result is an incorrect tensor shape being reported by the Tensorflow model. Maybe its a serialisation and packing issue with the JSON field?The Predict message proto is:
As you can see below, the TensorProto spec offers several ways of representing the tensor 'array' as repeated types:
Here is an example using Protobuf text syntax, produced by
google.protobuf.text_format()
and written direct to file. I have no control over which type it chose to use, in this casetensor_content
. Sending this with grpcurl with-format=text
works:As a human, I want to represent the Tensor float array in a form it's easy to specify, unlike the above. The following protobuf text form also works:
Aside: I found it interesting how protobuf represents a
map
in the text form.Here is a JSON example of the above that passes the
grpcurl
syntax checking and a request is sent using-format=json
, but Tensorflow complains about the tensor shape, suggesting the repeated float array is not being serialised as expected:Please help me understand if/how I can make this work with JSON, preferably using JSON float representation as in the example above. Thanks.
For info, I also tried a bytes -> base64 representation, which is equivalent, but results in the same, underlying serialisation problem: