• Stars
    star
    401
  • Rank 104,434 (Top 3 %)
  • Language
    Dart
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated 30 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easily collect data and train image classification models.

Custom Image Classifier

If you want a custom image classifier, but don’t have the right data or the know-how to build it, you’ve come to the right place. With this Flutter app (runs on both iOS and Android) you can create datasets, collaborate on the collection of training data, and then trigger the training of the custom image classifier from the device. Once the classifier is ready, you can use it from the same app, and run inferences on device.

screenshots/labels.png        screenshots/infer.gif        screenshots/infer.png

        Create Datasets                           Gather training data                      Infer on-device

See a live demo of the app presented at Google I/O '19.

Status

Status: Archived

This sample is no longer actively maintained and is left here for reference only.

Full list of features

  • Create datasets and corresponding labels (e.g. flowers -> rose, tulip, sunflower, etc).
  • Collect images for a dataset via the phone’s camera. Images can be collected as individual pictures or short videos that are converted to multiple individual images.
  • Invite other users to contribute to your dataset.
  • Export your dataset.
  • Trigger cloud-based training of a model based on your dataset.
  • Once the model is trained, run on-device inferences from within the same app.
  • Export the trained TFLite model to use in any other apps using the ML Kit SDK.

Google Services used in the sample app

AutoML Vision Edge in ML Kit generates models meant to run on-device. If you are interested in cloud-hosted models for more fine-grained image recognition or higher accuracy, visit the Cloud AutoML documentation to learn more.

Please note:

  • Treat this project as sample code. You’ll need to create your own Firebase project and include its configuration files in the app in order to use it.
  • Given that the app requires access to several Google Cloud APIs, your Firebase project will need to be on the Blaze plan.
  • This app makes use of several Firebase and Google Cloud resources. You may be charged for any resources consumed. Learn more about pricing here.
  • You are responsible for your app and its distribution, and complying with applicable terms and usage policies for Firebase and Google Cloud services.
  • You are responsible for taking any necessary steps before distributing your app to third-party users, such as adding a privacy policy.

Getting Started

Note: Before proceeding, make sure you have Flutter & Node.js/NPM setup for your system.

  1. Clone this repo locally

    git clone https://github.com/firebase/mlkit-custom-image-classifier
    
  2. Create a new Firebase project from the console.

  3. Take a note of the Project ID from Settings page as we'll use it later. Also add a support email - this is required for sign-in to work.

  4. Follow the steps to add Firebase to the Flutter app in this repo. For the Android version, use com.example.classifier as bundle ID and for iOS use com.example.imageclassifier. If you want to provide your own bundleIDs, remember to replace the pre-filled bundleIDs from the code in flutter/

    NOTE: For the Android app, make sure to add a Debug signing certificate SHA-1 for Google Sign-in to work.

Enable Services

  1. Enable Firestore by going to Database tab in Firebase Console, click on Create Database, select "Start in locked mode" & click on Enable.
  2. Next, head to Sign-In Method tab under Authentication tab in Firebase console and enable the Google sign-in provider.
  3. Next up, we'd need to enable ML Kit by going to ML Kit and click on getting started.
  4. Follow that by clicking on the AutoML tab and click on getting started. This should take a few minutes to provision AutoML.
  5. Once that's done, we'd need to head to Storage and enable Storage. Finally, we'll need to add the pre-generated AutoML bucket (named: ${PROJECT_ID}-vcm) by doing the following:
    • Click on Add bucket in the overflow menu
    • In the "Set up bucket" dialog, choose Import existing Google Cloud Storage buckets and here you'll see a bucket name ${PROJECT_ID}-vcm. Select this bucket and click on continue.
    • Finally, head to the rules tab and copy the rules from storage.rules & automlstorage.rules to the ${PROJECT_ID}.appspot.com & ${PROJECT_ID}-vcm buckets respectively.

Firebase setup

  1. You must have the Firebase CLI installed. If you don't have it install it with npm install -g firebase-tools and then configure it with firebase login.
  2. Configure the CLI locally by using firebase use --add and select your project in the list.
  3. Install dependencies locally by running: cd functions; npm install; cd -
  4. For sending emails via your firebase functions, you'd need to set your api_key for the service you're using. In this case, we use Sendgrid. Once you have an API key, run the following command to configure it
$ firebase functions:config:set sendgrid.key="<API_KEY>"
  1. Next, set the FROM_EMAIL constant in this file to be email ID from which emails will be sent.
  2. Follow that up with setting the APP_NAME that you've decided for your app.
  3. Go to the Firebase Console, select the gear image > project settings > Service Accounts and click Generate New Private Key to download a Service Account Key JSON document.
  4. Add the JSON service account credentials file to the Functions directory as functions/lib/service-account-key.json.
  5. Now run, npm run deploy to deploy the functions, firestore & storage configuration.

Flutter app setup

  1. Set the PROJECT_ID constant in the flutter app in this file.
  2. If you're using iOS, you'd need to follow these steps for Google Sign-In to work.
  3. You can now run the app locally!
  4. If you want to deploy the app, make sure to read the Android and iOS instructions to finalize the app name, icon etc.

Using the app

  1. To create your own datasets, manage datasets or add data to existing datasets, log into the app.
  2. Use the main screen to add new datasets, or browse available datasets. Use the camera button to take a picture and run an inference with the latest model available for a dataset.
  3. Tap on a dataset to view the labels. If you are the owner, you can add more labels to it. If you've been invited to collaborate on a dataset, you can add data to labels in dataset.
  4. Once a dataset has enough data, the owner can initiate training of a new model on AutoML. Note: For best results, make sure each label has a diverse set of images and at least 100 images per label.
  5. If you want to view a dataset and start model training from the console, click "Export to Firebase" from the overflow menu, then go to ML Kit -> AutoML in the Firebase console. Otherwise you can train directly from the app by clicking "Train Model" under a dataset. You will be notified when the model training is complete.

More Repositories

1

firepad

Collaborative Text Editor Powered by Firebase
JavaScript
3,845
star
2

reactfire

Hooks, Context Providers, and Components that make it easy to interact with Firebase.
TypeScript
3,479
star
3

angularfire

AngularJS bindings for Firebase
JavaScript
2,729
star
4

firechat

Real-time Chat powered by Firebase
JavaScript
2,407
star
5

firebase-arduino

Arduino samples for Firebase.
C++
940
star
6

bolt

Bolt Compiler (Firebase Security and Modeling)
TypeScript
895
star
7

firebase-queue

JavaScript
787
star
8

emberfire

The officially supported adapter for using Firebase with Ember
TypeScript
688
star
9

action-hosting-deploy

Automatically deploy shareable previews for your Firebase Hosting sites
TypeScript
656
star
10

mlkit-material-android

ML Kit Showcase App with Material Design
Java
490
star
11

polymerfire

Polymer Web Components for Firebase
HTML
460
star
12

flutterfire_desktop

An early-stage, experimental pure-Dart implementation of Firebase SDKs.
Dart
399
star
13

firebase-import

Node module for importing large data into Firebase.
JavaScript
366
star
14

custom-auth-samples

Samples showcasing how to sign in Firebase using additional Identity Providers
Java
320
star
15

firechat-ios

An example chat application built using the Firebase iOS SDK
Objective-C
245
star
16

experimental-extensions

🧪 A laboratory for new extensions created by Firebase
TypeScript
243
star
17

firebase-framework-tools

Experimental addon to the Firebase CLI to add web framework support
JavaScript
235
star
18

make-it-so-android

Kotlin
205
star
19

protobuf-rules-gen

This is an experimental protoc plugin that generates Firebase Rules for Cloud Firestore based on Google's Protocol Buffer format. This allows you to easily validate your data in a platform independent manner.
C++
195
star
20

karas-coffee

TypeScript
149
star
21

rxfire

TypeScript
134
star
22

unity-solutions

Use Firebase tools to incorporate common features into your games!
C#
125
star
23

firebase-video-samples

This repository contains sample code for some of the videos on the Firebase YouTube channel.
Swift
102
star
24

user-data-protection

Generalizable examples of protecting user data in Firebase Applications
JavaScript
97
star
25

mlkit-material-ios

These apps demonstrate how to build an end-to-end user experience with Google ML Kit APIs and following the new Material for ML design guidelines.
Objective-C
82
star
26

TubeSock

A WebSocket client library implemented in Java
Java
79
star
27

codelab-friendlyeats-flutter

FlutterFire Firestore codelab. Develop a cross platform restaurant recommendation app with Flutter.
Dart
79
star
28

expense-tracker

JavaScript
76
star
29

fastlane-plugin-firebase_test_lab

Test your app with Firebase Test Lab with ease using fastlane
Ruby
74
star
30

firebase-auth-service-worker-sessions

JavaScript
73
star
31

auth-without-play-services

Demonstrates how to implement Firebase Auth on devices without Google Play services
Kotlin
70
star
32

user-privacy

Sample of general purpose functions for user data deletion and export
JavaScript
68
star
33

remote-styles

Conditionally load CSS from Firebase Remote Config
TypeScript
64
star
34

analytics-webview

Java
62
star
35

firebase-streaming-import

public node.js script for streaming large JSON files into a Firebase
Python
61
star
36

cocos2dx-cpp-sample

Firebase Cocos2d-x samples
C++
55
star
37

firestore-codelab-extended-swift

Swift
48
star
38

codelab-kanban-fire

TypeScript
41
star
39

firebase-continue

Firebase Continue enables mobile developers to integrate activity transitioning from their mobile apps to the web
JavaScript
36
star
40

MLKit-ARKit

Swift
34
star
41

parse-migration-tools

JavaScript
26
star
42

firestoreodm-flutter

Dart
22
star
43

firepad-demo

http://demo.firepad.io/ sources
CSS
15
star
44

firestore-nlp-extension

TypeScript
15
star
45

palm-chatbot-angular

TypeScript
14
star
46

codelab-contentrecommendation-android

Kotlin
12
star
47

MLKit-ARCore

Swift
11
star
48

firebase-auth-migration-helpers

Objective-C
11
star
49

codelab-measure-android-view-performance

Java
10
star
50

firebase-js-sdk-performance-dashboard

Firebase JS SDK Performance Dashboard
TypeScript
9
star
51

cmake-way-for-firebase

C++
6
star
52

codelab-fcm-and-fiam

Kotlin
5
star
53

codelab-textclassification-android

Jupyter Notebook
5
star
54

codelab-rules

JavaScript
4
star
55

fcm-external-prober

Go
4
star
56

firebase_fcm_flutter

Java
4
star
57

angularfire-expert-led-class

TypeScript
4
star
58

crashlytics-migration-android

Java
4
star
59

firebase-console-performance-dashboard

TypeScript
4
star
60

crashlytics-migration-ios

Swift
4
star
61

codelab-digitclassifier-android

Kotlin
3
star
62

codelab-actions-firestore

JavaScript
3
star
63

firebase-apple-sdk-triage

This repo contains a collection of "skeleton" apps for quickly reproducing issues from the firebase-ios-sdk.
Swift
2
star
64

codelab-appdistribution-android

Kotlin
2
star
65

github-actions

Python
2
star
66

firebase-functions-go

Go
2
star
67

codelab-contentrecommendation-ios

Swift
2
star
68

changelog

TypeScript
2
star
69

poem-from-image

TypeScript
2
star
70

ai-extensions-codelab

JavaScript
2
star
71

codelab-textclassification-ios

Swift
1
star
72

codelab-digitclassifier-ios

Swift
1
star
73

codelab-feature-rollout-performance

This is the source code that accompanies the Firebase Performance Monitoring Codelab: https://firebase.google.com/codelabs/feature-rollout-performance
Java
1
star