2

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.

akshay pai
  • 122
  • 12

1 Answers1

1

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

K41F4r
  • 1,443
  • 1
  • 16
  • 36
  • There is another issue. So, the input that I am sending is heavily modified. the maskRCNN library performs a lot of preprocessing before it sends the data to the model for prediction. So, if I do send bytes, then the pre-processing will not be there right? and thereby I won't be able to predict. I have extracted the bits from the mask-rcnn library to perform only the preprocessing. If you're interested, you can find it here: [preprocess_mrcnn.py](https://gist.github.com/sourcedexter/195bcc2fa8e1616189919e3a35fad4a4) – akshay pai Nov 14 '19 at 06:06
  • For other issues, you should always post a new question following the usual procedure. However, I can already tell you that when converting an image into bytes, any processing you have made to it is kept unchanged because you are not converting the original image but the new and already processed image. – enle lin Nov 26 '19 at 15:29