Skip to content

koji4104/FlutterVision

Repository files navigation

Flutter Vision

📘 Overview

This app uses Flutter and Google ML Kit and TensorFlow Lite. use google_ml_kit 0.12.0 (2022/8)

📘 Screen

Face Detector

Text Recognizer

Image Labeler

Barcode Detector

Pose Detector

Object Detector

Selfie Segmenter

TensorFlow Lite (Custom model)

📘 You need to get the file

1 Create a project in Firebase

https://console.firebase.google.com/u/0/

2 Download file

google-services.json (android) GoogleService-Info.plist (ios)

3 Add file to project

FlutterVision (project)
📁android
 :file_folder:gradle
 :open_file_folder:app
  :file_folder:build
  :file_folder:src
  :notebook:build.gradle
  :notebook:google-service.json :arrow_left:
📁ios
 :file_folder:Flutter
 :file_folder:Runner
  :file_folder:Assets.xcaseets
  :file_folder:Base.lpoj
  :notebook:AppDelegate.swift
  :notebook:GoogleService-Info.plist :arrow_left:
  :notebook:Info.plist

⚠️ It doesn't work on ios. This is because TensorFlow cannot be used.

📘 Creating a model with Tensorflow Lite

Run python

# pip install tensorflow
# pip install tflite-model-maker

import os
import numpy as np
import tensorflow as tf
 
from tflite_model_maker import model_spec
from tflite_model_maker import image_classifier
from tflite_model_maker.config import ExportFormat
from tflite_model_maker.config import QuantizationConfig
from tflite_model_maker.image_classifier import DataLoader
import matplotlib.pyplot as plt

data = DataLoader.from_folder('train/')
train_data, test_data = data.split(0.9)
model = image_classifier.create(train_data)
loss, accuracy = model.evaluate(test_data)

model.export(export_dir='.')
model.export(export_dir='.', export_format=ExportFormat.LABEL)

Add it to pubspec.yaml

flutter:
  assets:
    - assets/model.tflite  ←Add
    - assets/labels.txt  ←Add