1

So, I have come across a pain point in model deployment on android platform. I have trained a model in python and converted it into tensorflow lite format for android platform. The problem is how to do things/processing that I did in python in Java. After a tedious search on net and going through no. of examples, nothing really explains this process clearly.

Eg: How to emulate preprocess/normalization algorithm in Java i.e. do pre-processing and post-processing of images.

Also what changes to make in code if using quantized model for inference and how to implement passing of multiple inputs to the model.

Below are corresponding code in python:

def preprocess(img):
  return (img / 255. - 0.5) * 2

def deprocess(img):
  return (img + 1) / 2

Can anyone please guide me as to how to do the same in Java and for multiple inputs. This can be a holy grail for someone looking for model integration in Android.

Thanks in advance!!!

1 Answer 1

1

Please take a look at the TensorFlow Lite Android Support Library.

In particular, take a deeper look at the TensorProcessor and its supported ops, which includes the quantization / dequantization operations (which you referred to as preprocess / deprocess in your example code).

Also, here is a full example Android project using TFLite and the Support Library.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.