Building an End-to-End Image Classifier using Flutter and TensorFlow Lite.
Published: 2020-09-27 11:28:28

>"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](https://miro.medium.com/max/875/1*ZyjIyGzWgqYi87Zl8VmqXA.jpeg)

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](https://dev-to-uploads.s3.amazonaws.com/i/xx1c1s1qvrsy0h2v6gn0.png)
There will be 3 important packages to add to pubspec.yaml, which are TFLite, SplashScreen, and image_picker.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/awdnuld3886iu1wcy6uz.png)
The main.dart will contain a stateless widget which will have a MySplash home.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8ezo6d1i73oss9gb8aw2.png)
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](https://dev-to-uploads.s3.amazonaws.com/i/6tugi1ymk6p282q24eyw.png)
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](https://dev-to-uploads.s3.amazonaws.com/i/sfg9vycdto0xd99e39t0.png)
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](https://dev-to-uploads.s3.amazonaws.com/i/1m5n75blfd2tcqcz4sn4.jpg)
*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](https://twitter.com/m_prth), [Github](https://github.com/m-prth), and [Linkedin](https://www.linkedin.com/in/m-prth/)._