eIQ Sample Apps - Face Recognition using TF Lite

Document created by Diego Dorta Employee on Jun 21, 2019Last modified by Diego Dorta Employee on May 13, 2020
Version 7Show Document
  • View in full screen mode

This Lab 4 explains how to get started with TensorFlow Lite application demo on i.MX8 board using Inference Engines for eIQ Software.

Get the source code available on code aurora:

TensorFlow Lite MobileFaceNets MIPI/USB Camera


Face Detection Using OpenCV


This application demo uses Haar Feature-based Cascade Classifiers for real time face detection. The pre-trained Haar Feature-based Cascade Classifiers for face, named as XML, is already contained in OpenCV. The XML file for face is stored in the opencv/data/haarcascades/ folder as well as code aurora. Read Face Detection using Haar Cascades for more details.


TensorFlow Lite implementation for MobileFaceNets 


The MobileFaceNets is re-trained on a host PC with a smaller batch size and input size to get higher performance. The trained model is loaded as a source file in this demo.


Setting Up the Board


Step 1 - Download the demo from eIQ Sample Apps and put it in /opt/tflite folder. Then enter the src folder:

root@imx8mmevk:~# cd /opt/tflite/examples-tflite/face_recognition/src/


This folder should include these files:

├── face_detect_helpers.cpp
├── face_detect_helpers.h
├── face_detect_helpers_impl.h
├── face_recognition.cpp
├── face_recognition.h
├── haarcascade_frontalface_alt.xml
├── Makefile
├── mfn.h
├── profiling.h
└── ThreadPool.h

Step 2 - Compile the source code on the board:

root@imx8mmevk:/opt/tflite/examples-tflite/face_recognition/src# make

Step 3 - Run the demo:

root@imx8mmevk:/opt/tflite/examples-tflite/face_recognition/src# ./FaceRecognition -c 0 -h 0.85

NOTE: -c is used to specify the camera index. '0' means the MIPI/USB camera is mounted on /dev/video0. -h is a threshold for the prediction score.

Step 4 - Add a new person to the face data set. 

When the demo is running, it will detect one biggest face at real time. Once the face is detected, you can click keyboards on the right of GUI to input the new person's name. Then, click 'Add new person' to add the face to data set. 

In brief,

1. Detect face.

2. Input new person's name.

3. Click 'Add new person'.

NOTE: Once new faces are added, it will create a folder named 'data' in current directory. If you want to remove the new face from the data set, just delete it in 'data'.