Building an End-to-End Image Classifier using Flutter.

Original article was published by Parth Mistry on Deep Learning on Medium


Building an End-to-End Image Classifier using Flutter.

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 which is taken in 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.

In fact, as per Gartner Inc., 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 CatsVSDogs dataset. We will convert the model to TFLite.

There will be 3 important packages to add to pubspec.yaml, which are TFLite, SplashScreen, and image_picker.

The main.dart will contain a stateless widget which will have a MySplash home.

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.

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.

Methods implemented in 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.

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.