Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:vim4:npu:demos:face-recognition

This is an old revision of the document!


Doc for version ddk-3.4.7.7

Face Recognition VIM4 Demo - 7

Face Recognition Demo consists of two models, RetinaFace and FaceNet. It can detect face on image and recognize who it is. Here are two judgment indicators, cosine similarity and Euclidean distance. The closer the cosine similarity is to 1 and the closer the Euclidean distance is to 0, the more similar is between two faces.

Here takes lin_1.jpg as example. Inference results on VIM4. Only show cosine similarity.

Inference speed test: USB camera about 80ms per frame.

This demo integrates RetinaFace and FaceNet. Please refer RetinaFace PyTorch VIM4 Demo - 5 and FaceNet PyTorch VIM4 Demo - 6 to convert model. Here only run inference on the NPU.

Run inference on the NPU

Get source code

Clone the source code from our khadas/vim4_npu_applications.

$ git clone https://github.com/khadas/vim4_npu_applications

If your kernel is older than 241129, please use version before tag ddk-3.4.7.7.

Install dependencies

$ sudo apt update
$ sudo apt install libopencv-dev python3-opencv cmake

Compile and run

Picture input demo

Like facenet, there are also two modes of this demo. One is converting face images into feature vectors and saving vectors in the face library. Another is comparing input face image with faces in the library and outputting Euclidean distance and cosine similarity.

Put retinaface_int8.adla and facenet_int8.adla in vim4_npu_applications/face_recognition/data/model.

# Compile
$ cd vim4_npu_applications/face_recognition
$ mkdir build
$ cd build
$ cmake ..
$ make
 
# Run mode 1
$ ./face_recognition -M ../data/model/retinaface_int8.adla -m ../data/model/facenet_int8.adla -p 1

After running mode 1, a file named face_feature_lib will generate in vim4_npu_applications/face_recognition. With this file generated, you can run mode 2.

# Run mode 2
$ ./face_recognition -M ../data/model/retinaface_int8.adla -m ../data/model/facenet_int8.adla -p ../data/img/lin_2.jpg

Camera input demo

Put retinaface_int8.adla and facenet_int8.adla in vim4_npu_applications/face_recognition_cap/data/model.

Put your full face photo into the vim4_npu_applications/face_recognition/data/img and run mode 1 to generate face_feature_lib. Put face_feature_lib in vim4_npu_applications/face_recognition_cap.

# Compile
$ cd vim4_npu_applications/face_recognition_cap
$ mkdir build
$ cd build
$ cmake ..
$ make
 
# Run
$ ./face_recognition_cap -M ../data/model/retinaface_int8.adla -m ../data/model/facenet_int8.adla -d 0

0 is the camera device index.

Last modified: 2025/06/11 23:05 by louis