简体   繁体   English

有没有办法将多个图像发送到 tf 服务 model?

[英]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_prototf.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.

相关问题 "如何将base64图像发送到gRPC tf服务服务器而不是http请求?" - How to send base64 image to gRPC tf serving server instead of http request? 提供可变长度输入的 TF 模型 - Serving TF model with Variable length input 如何将 tf.example 发送到 TensorFlow Serving gRPC 预测请求中 - How to send a tf.example into a TensorFlow Serving gRPC predict request 使用 TF 2.0 为 Tensorflow/Keras model 提供嵌入层问题 - Issue with embedding layer when serving a Tensorflow/Keras model with TF 2.0 测试TF服务模型失败,字节为字符串,字符串为字节混淆 - Testing TF serving model fails with bytes as strings and strings as bytes confusion 从保存的 Keras 模型获取 tf.Serving 的配置 - Getting Configurations for tf.Serving From Saved Keras Model 保存自定义tf.estimator训练模型的tensorflow服务 - Saving a custom tf.estimator trained model for tensorflow serving 无法使用自定义服务方法保存 tf.keras.Model - Can't save tf.keras.Model with custom serving method 如何导出 tf 模型以直接从会话中提供服务(不创建 tf 检查点)以最小化导出时间 - how to export tf model for serving directly from session (no creating of tf checkpoint) to minimize export time 我可以使用来自 TF HUB 的非微调 BERT 模型来为它提供 TF 服务吗? - Can I use non-fine-tuned BERT model from TF HUB to serve it with TF serving?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM