~~tag> NPU RetinaFace FaceNet Edge2 ~~ ====== Face Recognition Edge2 Demo - 7 ====== {{indexmenu_n>7}} ===== Introduction ===== 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 Edge2. Only show cosine similarity. {{:products:sbc:edge2:npu:demos:face-recognition-result.png?200|}} {{:products:sbc:edge2:npu:demos:result.jpg?400|}} **Inference speed test**: USB camera about **44ms** per frame. MIPI camera about **33ms** per frame. This demo integrates RetinaFace and FaceNet. Please refer [[retinaface]] and [[facenet]] to convert model. Here only run inference on the NPU. ===== Run NPU ===== ==== Get source code ==== Clone the source code from our [[gh>khadas/edge2-npu]]. ```shell $ git clone https://github.com/khadas/edge2-npu ``` ==== Install dependencies ==== ```shell $ sudo apt update $ sudo apt install cmake libopencv-dev ``` ==== 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.rknn'' and ''facenet.rknn'' in ''edge2-npu/C++/retinaface/data/model''. ```shell # Compile $ bash build.sh # Run mode 1 $ cd install/face_recognition $ ./face_recognition data/model/retinaface.rknn data/model/facenet.rknn 1 ``` After running mode 1, a file named ''face_feature_lib'' will generate in ''edge2-npu/C++/face_recognition/install/face_recognition/data''. With this file generated, you can run mode 2. ```shell # Run mode 2 $ ./face_recognition data/model/retinaface.rknn data/model/facenet.rknn data/img/lin_1.jpg ``` === Camera input demo === Put ''retinaface.rknn'' and ''facenet.rknn'' in ''edge2-npu/C++/face_recognition_cap/data/model''. ```shell # Compile $ bash build.sh ``` Put your full face photo into the ''edge2-npu/C++/face_recognition/data/img''. Recompile and run mode 1 to generate ''face_feature_lib''. Put ''face_feature_lib'' in ''edge2-npu/C++/face_recognition_cap/install/face_recognition_cap/data''. ```shell # Run USB camera $ cd install/retinaface_cap $ ./face_recognition data/model/retinaface.rknn data/model/facenet.rknn usb 60 # Run MIPI camera $ cd install/retinaface_cap $ ./face_recognition data/model/retinaface.rknn data/model/facenet.rknn mipi 42 ``` ''60'' and ''42'' are camera device index.