tobegit3hub / simple_tensorflow_serving

Generic and easy-to-use serving service for machine learning models
https://stfs.readthedocs.io
Apache License 2.0
757 stars 195 forks source link

Status 400 :Invalid json data when posting http request #62

Closed YifengChen94 closed 3 years ago

YifengChen94 commented 5 years ago

I have successfully deployed my model but I got some problems when trying to post http request. The shape of my model input tensor is (-1,-1-1,3). The Graph Signature information is listed below

捕获

The following code is used to post request

import cv2
import numpy as np
import json
import requests

img = cv2.imread('./Images/0001TP_008550.png')
img = cv2.resize(img,(352,288))
rows = img.shape[0]
cols = img.shape[1]
img = np.expand_dims(img,0)
dict_min  = {"images":img.tolist()}
endpoint = "http://127.0.0.1:8500"
jsr=json.dumps(dict_min)
result = requests.post(endpoint, json=jsr)
print(result.text)

I know this is a problem with my data format, but how could I solve it? Thx a lot.

tobegit3hub commented 3 years ago

The OpenCV python image object would not be submitted as json data.

You can refer to our image client which will read the image file and parse to json string for inference. Please refer to https://github.com/tobegit3hub/simple_tensorflow_serving/blob/master/clients/python_client/image_client.py .