Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tensorflow serving input payload

I have a model saved in SavedModel format (.pb). After serving the model without problems i try to make a prediction via tensorflow serving. TF Serving requires me to input the data via a list, otherwise the answer i receive is TypeError: Object of type 'ndarray' is not JSON serializable . But when i input a list the response is an error

The input is

value = [1, 2, 3, 4, 5]
body = {"signature_name": "serving_default",
        "instances": [[values]]}
res = requests.post(url=url, data=json.dumps(body))

and the answer { "error": "In[0] is not a matrix. Instead it has shape [1,1,5]\n\t [[{{node sequential/dense/Relu}}]]" }

I know the model works, the input without using tensorflow serving is

value = np.array([1,2,3,4,5])
model.predict([[value]])

So the problem is how can use tensorflow serving if it requires to use a list as input but the model requires a np.array as input.

like image 697
Juan José Pardo Sierra Avatar asked Mar 27 '26 20:03

Juan José Pardo Sierra


1 Answers

I suppose you should do it in this way

value = <ndarray>
data = value.tolist()
body = {
    "signature_name": "serving_default",
    "instances": data}
like image 180
zzachimonde Avatar answered Mar 31 '26 10:03

zzachimonde