how to reduce input size for mask-RCNN trained model while running prediction on google cloud platform

364 Views Asked by At

I am trying to use Google AI Platform prediction to perform object recognition using Mask RCNN. After spending close to two weeks, I was able to:

  1. find out how to train on Google Cloud
  2. convert the model from h5 to the SavedModel format required by the AI platform
  3. create AI Platform Models and deploy the trained models there.

Now, that I am trying to perform prediction, it said that my input size exceeds 1.5 MB which is the maximum size the input can be. When I checked it, the code that converts the image ( of size 65KB) to the format required for prediction makes the input file to 57MB.

I have no idea how a 64 KB image file can be converted to a 57 MB json file when molded. And I wanted to know how I can reduce this? Not sure if I am doing something wrong.

I have tried to perform local prediction using the gcloud local predict, and I am able to get the response with the 57MB file. So, that means that the file is correct.

I tried to set the max dimension of the image to 400X400, and that reduced the size of file from 57MB to around 7 MB. which is still very high. I cannot keep reducing it as it leads to loss of information.

1

There are 1 best solutions below

2
On

As per the online prediction documentation

Binary data cannot be formatted as the UTF-8 encoded strings that JSON supports. If you have binary data in your inputs, you must use base64 encoding to represent it.

You need to have your input_image tensor called input_image_bytes and you will send it data like so:

{'input_image_bytes': {'b64': base64.b64encode(jpeg_data).decode()}}

If you need help correcting you model's inputs you should see def _encoded_image_string_tensor_input_placeholder() in exporter.py called from export_inference_graph.py