小编Ara*_*ash的帖子

如何在 Google Cloud AI Platform 中使用 Base64 服务 Tensorflow2 图像分割模型

我可以使用以下代码成功保存 TF2 图像分割模型并将其部署到 AI Platform:

@tf.function(input_signature=[tf.TensorSpec(shape=(None), dtype=tf.string)])
def serving(input_image):

    # Convert bytes of jpeg input to float32 tensor for model
    def _input_to_feature(image_bytes):
        img = tf.image.decode_jpeg(image_bytes, channels=3)
        img = tf.image.convert_image_dtype(img, tf.float32) / 255.0
        img = tf.image.resize_with_pad(img, 256, 256)
        return img
    img = tf.map_fn(_input_to_feature, input_image, dtype=tf.float32)

    # Predict
    pred = model(img)

    def _pred_to_image(pred):
        pred = tf.cast(pred * 255, dtype=tf.uint8)

        img_str = tf.image.encode_png(pred, compression=-1, name=None)
        return img_str

    img_str = tf.map_fn(_pred_to_image, pred, dtype=tf.string)

    return img_str


tf.saved_model.save(model, export_dir=checkpoint_dir+'/saved_model', signatures=serving)
Run Code Online (Sandbox Code Playgroud)

但是,我在发送这样的请求时收到此错误:

img_str = base64.b64encode(open('sample_372.jpg', "rb").read()).decode()
response …
Run Code Online (Sandbox Code Playgroud)

google-cloud-platform tensorflow-serving tensorflow2.0 gcp-ai-platform-training

1
推荐指数
1
解决办法
476
查看次数