Reputation: 23
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!!!
Upvotes: 1
Views: 214
Reputation: 3845
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.
Upvotes: 1