背景:
\n\n在 GCP 上的视觉应用程序中,我们使用 TF 服务。使用 TF Serving 的应用程序是用 Go 编写的。该应用程序将图像转换为 Tensor,并使用 gRPC 将其发送到 TF 服务。
\n\n问题:
\n\nGolang 中的预处理逻辑不像 Python 中那样工作,使用 Keras 图像库(推理的准确性受到影响)。部分原因可能是训练期间使用了 Python 库。
\n\n我们尝试了,
\n\nTensorflow 服务提供了一种引入可在服务容器上运行的预处理器的方法。它的功能似乎有限(无法将 Keras 库与模型打包)。我们尝试了以下两种选择
\n\n有效的是 Keras 预处理 (Python),在客户端如下。
\n\nimg = tf.keras.preprocessing.image.load_img(file_name, target_size=(HEIGHT, WIDTH))\nimg_array = tf.keras.preprocessing.image.img_to_array(img)\n\n
Run Code Online (Sandbox Code Playgroud)\n\n\xe2\x80\xa6 grpc 调用 TensorflowServing...
\n\n我们的目标是使用 \xe2\x80\x9cserving_input_receiver_fn\xe2\x80\x9d 并在 TFServing 空间中预处理图像,如本博客文章中所述: https ://medium.com/devseed/technical-walkthrough-packaging-ml-models -for-inference-with-tf-serving-2a50f73ce6f8
\n\n但是以下作为 \xe2\x80\x9cserving_input_receiver_fn\xe2\x80\x9d 执行的代码不会产生正确的推论。
\n\nimage = tf.image.decode_image(image_str_tensor, channels=CHANNELS dtype=tf.uint8)\nimage = tf.reshape(image, [HEIGHT, WIDTH, CHANNELS])\n
Run Code Online (Sandbox Code Playgroud)\n\n我们的目标 …