Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:vim4:npu:demos:facenet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
products:sbc:vim4:npu:demos:facenet [2023/09/15 03:01]
sravan [Facenet Pytorch VIM4 Demo - 6]
products:sbc:vim4:npu:demos:facenet [2025/01/08 22:31] (current)
louis
Line 1: Line 1:
-~~tag> NPU Facenet VIM4 Pytorch~~ +~~tag> NPU FaceNet VIM4 PyTorch~~ 
-====== Facenet Pytorch VIM4 Demo - 6 ======+ 
 +**Doc for version ddk-3.4.7.7** 
 + 
 +====== FaceNet PyTorch VIM4 Demo - 6 ======
  
 {{indexmenu_n>6}} {{indexmenu_n>6}}
 ===== Get Source Code ===== ===== Get Source Code =====
 +
 +[[gh>bubbliiiing/facenet-pytorch]]
  
 ```shell ```shell
-git clone https://github.com/bubbliiiing/facenet-pytorch.git+git clone https://github.com/bubbliiiing/facenet-pytorch
 ``` ```
  
Line 13: Line 18:
 ==== Build virtual environment ==== ==== Build virtual environment ====
  
-Follow Docker official docs to install Docker: [[https://docs.docker.com/engine/install/ubuntu/|Install Docker Engine on Ubuntu]].+Follow Docker official documentation to install Docker: [[https://docs.docker.com/engine/install/ubuntu/|Install Docker Engine on Ubuntu]].
  
-Get Docker.+Follow the script below to get Docker image:
  
 ```shell ```shell
-docker pull yanwyb/npu:v1 +docker pull numbqq/npu-vim4
-$ docker run -it --name vim4-npu1 -v $(pwd):/home/khadas/npu \ +
- -v /etc/localtime:/etc/localtime:ro \ +
- -v /etc/timezone:/etc/timezone:ro \ +
- yanwyb/npu:v1+
 ``` ```
  
-==== Get convert tool ====+==== Get Convert Tool ====
  
-Download Tool from [[gl>khadas/vim4_npu_sdk.git|Rockchip Github]].+Download Tool from [[gh>khadas/vim4_npu_sdk]].
  
 ```shell ```shell
-$ git clone https://gitlab.com/khadas/vim4_npu_sdk.git+$ git lfs install 
 +$ git lfs clone https://github.com/khadas/vim4_npu_sdk 
 +$ cd vim4_npu_sdk 
 +$ ls 
 +adla-toolkit-binary  adla-toolkit-binary-3.1.7.4  convert-in-docker.sh  Dockerfile  docs  README.md
 ``` ```
 +
 +  * ''adla-toolkit-binary/docs'' - SDK documentations
 +  * ''adla-toolkit-binary/bin'' - SDK tools required for model conversion
 +  * ''adla-toolkit-binary/demo'' - Conversion examples
 +
 +<WRAP important>
 +If your kernel is older than 241129, please use branch npu-ddk-1.7.5.5.
 +</WRAP>
 +
 +==== Convert ====
  
 After training model, modify ''facenet-pytorch/nets/facenet.py'' as follows. After training model, modify ''facenet-pytorch/nets/facenet.py'' as follows.
Line 50: Line 65:
 ``` ```
  
-Create a python file written as follows and run to convert model to onnx.+Create a Python file written as follows and run to convert the model to ONNX.
  
 ```python export.py ```python export.py
Line 68: Line 83:
 Enter ''vim4_npu_sdk/demo'' and modify ''convert_adla.sh'' as follows. Enter ''vim4_npu_sdk/demo'' and modify ''convert_adla.sh'' as follows.
  
-```shell convert_adla.sh+```bash convert_adla.sh
 #!/bin/bash #!/bin/bash
      
Line 86: Line 101:
         --dtypes "float32" \         --dtypes "float32" \
         --inference-input-type float32 \         --inference-input-type float32 \
- --inference-output-type float32 \+ --inference-output-type float32 \
         --quantize-dtype int8 --outdir onnx_output  \         --quantize-dtype int8 --outdir onnx_output  \
         --channel-mean-value "0,0,0,255"  \         --channel-mean-value "0,0,0,255"  \
Line 95: Line 110:
 ``` ```
  
-Run ''convert_adla.sh'' to generate VIM4 model. The converted model is ''xxx.adla'' in ''onnx_output''.+Run ''convert_adla.sh'' to generate the VIM4 model. The converted model is ''xxx.adla'' in ''onnx_output''.
  
 ```shell ```shell
Line 101: Line 116:
 ``` ```
  
-===== Run NPU =====+===== Run inference on the NPU =====
  
 ==== Get source code ==== ==== Get source code ====
Line 108: Line 123:
  
 ```shell ```shell
-$ git clone https://github.com/khadas/vim4_npu_applications.git+$ git clone https://github.com/khadas/vim4_npu_applications
 ``` ```
 +
 +<WRAP important>
 +If your kernel is older than 241129, please use version before tag ddk-3.4.7.7.
 +</WRAP>
  
 ==== Install dependencies ==== ==== Install dependencies ====
Line 122: Line 141:
 === Picture input demo === === Picture input demo ===
  
-There are two modes of this demo. One is converting face images into feature vectors and saving vectors in face library. Another is comparing input face image with faces in library and outputting Euclidean distance and cosine similarity.+There are 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 ''facenet_int8.adla'' in ''vim4_npu_applications/facenet/data/''. Put ''facenet_int8.adla'' in ''vim4_npu_applications/facenet/data/''.
Line 128: Line 147:
 ```shell ```shell
 # Compile # Compile
-$ cd vim4_npu_applications/retinaface+$ cd vim4_npu_applications/facenet
 $ mkdir build $ mkdir build
 $ cd build $ cd build
Line 135: Line 154:
  
 # Run mode 1 # Run mode 1
-sudo ./facenet -m ../data/facenet_int8.adla -p 1+$ ./facenet -m ../data/facenet_int8.adla -p 1
 ``` ```
  
-After running mode 1, a file named ''face_feature_lib'' will generate in ''vim4_npu_applications/facenet''Had this file, you can run mode 2.+After running mode 1, a file named ''face_feature_lib'' will generate in ''vim4_npu_applications/facenet''With this file generated, you can run mode 2.
  
 ```shell ```shell
 # Run mode 2 # Run mode 2
-sudo ./facenet -m ../data/facenet_int8.adla -p ../data/img/lin_2.jpg+$ ./facenet -m ../data/model/facenet_int8.adla -p ../data/img/lin_2.jpg
 ``` ```
  
 +{{:products:sbc:vim4:npu:demos:facenet-demo-output.webp?400|}}
 +
 +Here are two comparison methods, **Euclidean distance** and **cosine similarity**.
 +
 +**Euclidean distance** is smaller, more similar between two faces.
 +
 +**Cosine similarity** is closer to 1, more similar between two faces.
Last modified: 2023/09/15 03:01 by sravan