Hi-
I have been researching and playing around with batch inference on the android and I can’t get it quite right. As a proof of concept, I ran my model(MobilNetV2-classification) on the Coral Devboard and it was able to handle batch inference just fine.
Now I am trying to run batch inference on an Android phone, and it is quite difficult.
I’m using the Android Classification Example as my starting point, and then choosing to use the lib_support_api because the lib_task_api specifically says that it does not support batch inference.
It took me awhile to get familiar with this code, but I eventually figured out that everything that needed changing to make batch inference happen would probably be in the ../lib_support/src/main/java/org/tensorflow/lite/examples/classification/tflite/Classifier.java
file.
My strategy for cropping and processing a 1920x1080 input stream:
-
Reshape the model from [1,224,224,3] → [16,224,224,3]
-
Input comes in as a bitmap
-
Break the center of that large bitmap into 16 [224,224,3] chunks using for loops and createBitmap
-
Use TensorImage.load() on each bitmap and store in an array
ArrayList<TensorImage>
This TensorImage business is where I have run into my main problems.
I tried using the Interpreter.runForMultipleInputsOutputs(input,output) function but I realized that this is intended for a model which actually has multiple input tensors. So it expects something like this:
input{ 0:[1,224,224,3], 1:[1,224,224,3], 2:[1,224,224,3]... }
Whereas I have input like this
input{0:[16x224x224x3]}
I could try and train a model to take inputs like this but I don’t exactly know what that entails.
After learning the above information I went back to using the Interpreter.run(input,output) function, which presented issues of its own.
Specifically, the issue now is that the Interpreter.run(input,output)
function expects something that it can digest. My ArrayList<TensorImage>
input is not taken nicely and retorts that it does not understand the datatype TensorImage. This makes sense because the there is a check in the Interpreter code requiring that if the input is an array, its elements have to be one of these types:
- uint8
- int64
- String
- Bool
So now the question is, can I use a bitmap to create an ArrayList<uint8>
such that all the information is still present?
There is a whole lot of janky business going on with batch inference and Tensorflow. Not just in the android/java libraries, but in the python one too. Maybe they have deemed this concept not worth their time, but currently it seems as if they only half support it.
Sooooooo @tensorflow, would you kindly support batch inference? Its OP.
- Support Batch Inference
- Don’t Support Batch Inference