Machine Learning With Flutter

In this task we will training a cat and dog model using machine learning and then we will create a app using that model

Requirements

  • Any Operating System (ie. MacOS X, Linux, Windows).
  • Android Studio/Visual Studio Code.

First go to Teachable Machine and open Image Project. To get started with training the model we will need to create two classes, namely “Dog” and “Cat” and upload training images for model to learn from. You can download the dataset from here.

After your model is trained, click on the export model and download the Tensorflow Lite Floating Point Model.

Now it’s time to integrate the .tflite mode in Flutter

Create a new Flutter Project and add tflite and image_picker as a dependency in your pubspec.yaml file.

In android/app/build.gradle, add the following setting in android block.

aaptoption {

noCompress ‘tflite’

noCompress ‘lite’

}

Create a assets folder and place your labels.txt file and model_unquant.tflite file in assets folder. In pubspec.yaml do the following changes to specify files that should be included with the app

flutter:

uses-material-design: true

assets:

-assets/

In main.dart include import 'package:tflite/tflite.dart'; & import ‘package:image_picker/image_picker.dart’;

The image_picker plugin will be used for picking images from the image library, and taking new pictures with the camera.

After importing libraries, it’s time to load your .tflite model in main.dart .We will be using a bool variable _loading to show CircularProgressIndicator while the model is loading.

main.dart and all related files are uploaded on github:

Thank you…