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 [2024/10/28 21:12]
louis
products:sbc:vim4:npu:demos:facenet [2026/04/02 02:47] (current)
nick
Line 1: Line 1:
 ~~tag> NPU FaceNet VIM4 PyTorch~~ ~~tag> NPU FaceNet VIM4 PyTorch~~
 +
 +**Doc for version ddk-3.4.7.7**
 +
 ====== FaceNet PyTorch VIM4 Demo - 6 ====== ====== FaceNet PyTorch VIM4 Demo - 6 ======
  
 {{indexmenu_n>6}} {{indexmenu_n>6}}
 +
 +===== Introduction =====
 +
 +FaceNet is a face recognition model. It will convert a face image into a feature map. Compare the feature map between image and face database. 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.
 +
 +{{:products:sbc:vim4:npu:demos:facenet-demo-output.webp?400|}}
 +
 ===== Get Source Code ===== ===== Get Source Code =====
  
Line 23: Line 35:
 ``` ```
  
-===== Get Convert Tool =====+==== Get Convert Tool ==== 
 + 
 +You can find the SDK here: [[dl>products/vim4/tools/npu-sdk/]]
  
 ```shell ```shell
-git lfs install +wget https://dl.khadas.com/products/vim4/tools/npu-sdk/vim4_npu_sdk-ddk-3.4.7.7-250508.tgz 
-$ git lfs clone https://gitlab.com/khadas/vim4_npu_sdk.git +$ tar xvzf vim4_npu_sdk-ddk-3.4.7.7-250508.tgz 
-$ cd vim4_npu_sdk+$ cd vim4_npu_sdk-ddk-3.4.7.7-250508
 $ ls $ ls
-adla-toolkit-binary  adla-toolkit-binary-1.2.0. convert-in-docker.sh  Dockerfile  docs  README.md+adla-toolkit-binary  adla-toolkit-binary-3.1.7. convert-in-docker.sh  Dockerfile  docs  README.md
 ``` ```
  
-  * ''adla-toolkit-binary/docs'' - SDK documentations+  * ''docs'' - SDK documentations
   * ''adla-toolkit-binary/bin'' - SDK tools required for model conversion   * ''adla-toolkit-binary/bin'' - SDK tools required for model conversion
   * ''adla-toolkit-binary/demo'' - Conversion examples   * ''adla-toolkit-binary/demo'' - Conversion examples
 +  * ''adla-toolkit-binary/python'' - KSNN conversion examples
  
-==== Get conversion tool ====+<WRAP important> 
 +If your kernel is older than 241129, please use branch npu-ddk-1.7.5.5. 
 +</WRAP>
  
-Download Tool from [[gl>khadas/vim4_npu_sdk]]. +==== Convert ====
- +
-```shell +
-$ git clone https://gitlab.com/khadas/vim4_npu_sdk +
-```+
  
 After training model, modify ''facenet-pytorch/nets/facenet.py'' as follows. After training model, modify ''facenet-pytorch/nets/facenet.py'' as follows.
Line 98: Line 111:
         --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 122: Line 135:
 $ git clone https://github.com/khadas/vim4_npu_applications $ 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 147: Line 164:
  
 # Run mode 1 # Run mode 1
-sudo ./facenet -m ../data/facenet_int8.adla -p 1+$ ./facenet -m ../data/facenet_int8.adla -p 1
 ``` ```
  
Line 154: Line 171:
 ```shell ```shell
 # Run mode 2 # Run mode 2
-sudo ./facenet -m ../data/model/facenet_int8.adla -p ../data/img/lin_2.jpg+$ ./facenet -m ../data/model/facenet_int8.adla -p ../data/img/lin_2.jpg
 ``` ```
  
 +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: 2024/10/28 21:12 by louis