DEV Community

Cover image for Building an End-to-End Image Classifier using Flutter and TensorFlow Lite.
Parth Mistry
Parth Mistry

Posted on

Building an End-to-End Image Classifier using Flutter and TensorFlow Lite.

"No machine learning model is valuable unless it’s deployed to production" — Luigi Patruno, Founder of MLinProduction.com

Machine learning is not just about creating models and predicting answers on it. We need to make the models work in production.
Having an application that would help anyone(one who doesn’t know how to code) to use the model and make predictions out of it will be a boon to the portfolio. Deployment is also a skill that is taken into consideration while hiring Machine Learning Engineers and Data Scientists. The project will highlight your skills related to both Machine Learning and Deployment of the model in various frameworks.

Alt Text

In fact, as per Gartner Inc., the majority of developers find difficulty in deployment.

There are various tools to deploy like Docker, Kubernetes, Heroku, Django, Flask, TensorFlow.js, TensorFlow Lite.

This time we will try TensorFlow Lite to deploy our model using Flutter. We will create a Flutter Application that classifies whether the animal in the picture we provide is a cat or a dog.
Here we assume that we have created the model which is trained using the CatsVSDogs dataset. We will convert the model to TFLite.
Alt Text
There will be 3 important packages to add to pubspec.yaml, which are TFLite, SplashScreen, and image_picker.
Alt Text
The main.dart will contain a stateless widget which will have a MySplash home.
Alt Text
The splashscreen.dart will be on the screen for 2 seconds which will load all the assets required to run the application and then it will navigate us to the main part of the app, which is App home.
Alt Text
The next file will have all the functions and methods to be done. We will use Tflite.LoadModel to load our .tflite CNN model and labels will be in labels.txt file. Tflite.runModelOnImage to do the preprocessing which will return the predictions. We will use the image picker module to load images from the gallery or from the camera.
Alt Text
Methods implemented in the home.dart file.
All the source code and resources for the project will be at this link. After setting up everything which includes the three files in the lib folder, adding the packages, and changing the configurations in the runner folder for iOS and in Gradle for Android, you can run the application in your Android Emulator or your device.
Alt Text
That’s it for this time. I would like to thank Aayush Jain and Avinash Khatri who helped me in successfully completing this application. 🎉
About the author: Parth is an undergraduate student who is passionate about Machine Learning and Flutter. You can connect with him on Twitter, Github, and Linkedin.

Top comments (0)