[英]Is there a way to send multiple image to tf serving model?
I'm trying this below code but I got unexpected error我正在尝试下面的代码,但出现意外错误
This is my code for getting input and pass it to model.这是我获取输入并将其传递给 model 的代码。
def get_instances(dir = '/test_data'):
instances = list()
file_names = [file.split('/')[-1] for file in os.listdir(dir)]
for file in file_names :
image = nv.imread(os.path.join(dir ,file), resize = (300,300), color_mode='rgb',normalize=True)
image = combine_rgb_xyz(image)
#image = nv.expand_dims(image,axis=0)
instances.append(image)
return np.array(instances) ,file_names
After I send these data to model with below code:在我使用以下代码将这些数据发送到 model 之后:
def make_prediction(instances):
url = get_url()
data = json.dumps({"signature_name": "serving_default", "instances": instances.tolist()})
headers = {"content-type": "application/json"}
json_response = requests.post(url, data=data, headers=headers)
predictions = json.loads(json_response.text)['predictons']
return predictions
but I get unexpected output:但我得到了意想不到的 output:
'predictons'
You can use tf.make_tensor_proto
and tf.make_ndarray
for image numpy array to/from tensor conversions.您可以使用
tf.make_tensor_proto
和tf.make_ndarray
进行图像 numpy 数组与张量的转换。 Then, you can use 'serving_default' signature to make predictions and pass multiple images to serving_default request to achieve faster results.然后,您可以使用“serving_default”签名进行预测并将多张图像传递给 serving_default 请求以获得更快的结果。 'serving_default' signature supports multiple images to be processed at once since it has 4d input (batch, height, width, channel).
'serving_default' 签名支持一次处理多个图像,因为它具有 4d 输入(批次、高度、宽度、通道)。 Please refer this guide to pass multiple images to TF serving.
请参考本指南将多个图像传递给 TF 服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.