Recently in some interview I have been asked about experience of implementing trained tensorflow models in android platform. I have tried one android project cloned from github which embedded a tflite model in it. However, I have not yet tried implementing my own model in an Android application. Thus I did such an exercise today and I successfully made my CNN model work on my Redmi Note 8 pro.
CNN model
Here is the code for training a CNN model with mnist
dataset. This model then is converted as tflite
model and shall be implemented in Android application for recognizing hand-write digits.
1 |
|
Implementation in Android app
I refereed to this post for obtaining the original android project. I imported the kotlin version into my Android Studio. However, there were some bugs initially when I loaded my model into it.
My own model is located to asset
repository:
The most important thing for this work is the following Gradle setting:
After about 15min of debugging and code modifications, I successfully made my model work.
Check out the video (there is still accuracy issue):
I will upload the android project src code to my github repo once I finish cleaning the code and improve the performance.