I want to make an app that capture an image using mobile camera and pass this image to tensorflow lite to classify, what is in the image.
"How to pass single image to Tensorflow lite"
3.8k views Asked by Sumair Aslam At
2
There are 2 answers
0
On
If you are an experienced, you can follow the approach mentioned by @somethingorange.
If you are a beginner and want to develop an image classification app on Mobile, then follow the following approach. For example, you are trying to develop a model to classify whether the given image is Cat or Dogs.
- collect data of your classes (Images of
CatsandDogs) - Make two folders one for images of Cats and other for images of Dogs
- Use any pretrained models to do develop classification model through transfer learning approach
- train the model and save the model
- convert the model to tflite format (
model.tflite) - create
label.txtwith the names of classes - move the
model.tfliteandlabel.txtto assets folder in Android Studio.
Best thing is all the above steps are mentioned in this tutorial by TFLite team which is a great place to start.
Hope these steps help beginners.
You can use a
TensorImage(from org.tensorflow.lite.support.image). It has constructors for aTensorBuffer, aBitmap, anint []orfloat [].So, say you have an image as a bitmap called
myImage, while running inmyContextcontext, then you can use the following code to run the tflite interpreter on themyModel.tflitemodel:If your image input is given as bytes, you can use
TensorBuffer'sByteBuffer, and the rest is the same.Note that I did not specify the interpreter
output.You can also use
TensorBufferas the output, which can easily provide you withByteBuffer,int []orfloat []arrays.Hope this helps :)