Skip to content

Face Mask Detection system built with Flutter and TensorFlow lite in order to detect face masks using images and live camera.

Notifications You must be signed in to change notification settings

sarveshsrv/Face-Mask-Detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Mask Detection with Tensorflow(Flutter)

Face Mask Detection system built with Flutter and TensorFlow lite in order to detect face masks using images and live camera.

⭐ Features

  • Delect mask on the live camera

  • Detect mask from a photo

  • MVVM architecture


🚀  Installation

  1. Install Packages
camera: get the streaming image buffers
https://pub.dev/packages/camera
tflite: run our trained model
https://pub.dev/packages/tflite
image_picker: pick image from gallery
https://pub.dev/packages/image_picker

2. Configure Project
  • Android
android/app/build.gradle

android {
    ...
    aaptOptions {
        noCompress 'tflite'
        noCompress 'lite'
    }
    ...
}


minSdkVersion 21

3. Train our model
* Download the dataset for training
    https://www.kaggle.com/prasoonkottarathil/face-mask-lite-dataset

* Training
    - go to https://teachablemachine.withgoogle.com to train our model
    - Get Started
    - Image Project
    - Edit `Class 1` for any Label(example `WithMask`)
    - Edit `Class 2` for any Label(example `WithoutMask`)
    - Update image from dataset download above
    - Click `Train Model`(using default config) and waiting...
    - Click `Export Model` and select `Tensorflow Lite`
    - Download (include: *.tflite, labels.txt)

4. Load model
loadModel() async {
    Tflite.close();
    await Tflite.loadModel(
        model: "assets/model.tflite", 
        labels: "assets/labels.txt",
        //numThreads: 1, // defaults to 1
        //isAsset: true, // defaults: true, set to false to load resources outside assets
        //useGpuDelegate: false // defaults: false, use GPU delegate
    );
  }

5. Run model
  Future<List<dynamic>?> runModelOnFrame(CameraImage image) async {
    var recognitions = await Tflite.runModelOnFrame(
        bytesList: image.planes.map((plane) {
          return plane.bytes;
        }).toList(),
        imageHeight: image.height,
        imageWidth: image.width,
        imageMean: 127.5,   //defaults to 127.5
        imageStd: 127.5,    //defaults to 127.5
        rotation: 90,       // defaults to 90, Android only
        numResults: 2,      // defaults to 5
        threshold: 0.5,     // defaults to 0.1
        asynch: true,       // defaults to true
    );      
    return recognitions;
  }
  Future<List<dynamic>?> runModelOnImage(File image) async {
    var recognitions = await Tflite.runModelOnImage(
      path: image.path,
      numResults: 2,
      threshold: 0.5,
      imageMean: 127.5,
      imageStd: 127.5,
    );
    return recognitions;
  }
Output format:
  [{
    index: 0,
    label: "WithMask",
    confidence: 0.989
  },...]

6. Issue
* IOS
1.'vector' file not found
Open ios/Runner.xcworkspace in Xcode, click Runner > Tagets > Runner >Build Settings, 
search Compile Sources As, change the value to Objective-C++

2. 'tensorflow/lite/kernels/register.h' file not found
The plugin assumes the tensorflow header files are located in path "tensorflow/lite/kernels".
However, for early versions of tensorflow the header path is "tensorflow/contrib/lite/kernels".

💡 Demo

  1. Image

About

Face Mask Detection system built with Flutter and TensorFlow lite in order to detect face masks using images and live camera.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published