This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
products:sbc:edge2:npu:demos:facenet [2023/08/22 06:08] louis created |
products:sbc:edge2:npu:demos:facenet [2025/04/09 23:38] (current) louis |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Demo6 facenet ====== | + | ~~tag> NPU FaceNet Edge2 PyTorch~~ |
- | ===== Get Source Code ===== | + | ====== FaceNet PyTorch Edge2 Demo - 6 ====== |
- | The codes we use. | + | {{indexmenu_n> |
+ | |||
+ | ===== 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 Edge2. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ===== Train Model ===== | ||
+ | |||
+ | The codes we use [[gh> | ||
```shell | ```shell | ||
Line 34: | Line 46: | ||
==== Get convert tool ==== | ==== Get convert tool ==== | ||
- | Download Tool from [[https:// | + | Download Tool from [[gh>rockchip-linux/ |
```shell | ```shell | ||
Line 41: | Line 53: | ||
``` | ``` | ||
- | Install dependences and RKNN toolkit2 packages, | + | Install dependences and RKNN toolkit2 packages. |
```shell | ```shell | ||
Line 51: | Line 63: | ||
``` | ``` | ||
- | ==== convert | + | ==== Convert |
After training model, modify facenet-pytorch/ | After training model, modify facenet-pytorch/ | ||
- | ```shell | + | ```diff |
diff --git a/ | diff --git a/ | ||
index e7a6fcd..93a81f1 100644 | index e7a6fcd..93a81f1 100644 | ||
Line 72: | Line 84: | ||
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 model to onnx. | ||
- | ```shell | + | ```python export.py |
import torch | import torch | ||
import numpy as np | import numpy as np | ||
Line 86: | Line 98: | ||
``` | ``` | ||
- | Enter rknn-toolkit2/ | + | Enter '' |
- | ```shell | + | ```python test.py |
# Create RKNN object | # Create RKNN object | ||
rknn = RKNN(verbose=True) | rknn = RKNN(verbose=True) | ||
Line 99: | Line 111: | ||
# Load ONNX model | # Load ONNX model | ||
print(' | print(' | ||
- | ret = rknn.load_onnx(model=”./ | + | ret = rknn.load_onnx(model='./ |
if ret != 0: | if ret != 0: | ||
print(' | print(' | ||
Line 107: | Line 119: | ||
# Build model | # Build model | ||
print(' | print(' | ||
- | ret = rknn.build(do_quantization=T rue, dataset=”./ | + | ret = rknn.build(do_quantization=True, dataset='./ |
if ret != 0: | if ret != 0: | ||
print(' | print(' | ||
Line 115: | Line 127: | ||
# Export RKNN model | # Export RKNN model | ||
print(' | print(' | ||
- | ret = rknn.export_rknn(“./ | + | ret = rknn.export_rknn('./ |
if ret != 0: | if ret != 0: | ||
print(' | print(' | ||
Line 122: | Line 134: | ||
``` | ``` | ||
- | Run test.py to generate rknn model. | + | Run '' |
```shell | ```shell | ||
Line 132: | Line 144: | ||
==== Get source code ==== | ==== Get source code ==== | ||
- | Clone the source code form our [[https:// | + | Clone the source code from our [[gh>khadas/ |
```shell | ```shell | ||
Line 149: | Line 161: | ||
=== Picture input demo === | === Picture input demo === | ||
- | Put facenet.rknn in edge2-npu/ | + | Put '' |
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 face library. Another is comparing input face image with faces in library and outputting Euclidean distance and cosine similarity. | ||
- | Put library faces in edge2-npu/ | + | Put library faces in '' |
```shell | ```shell | ||
- | // compile | + | # Compile |
$ bash build.sh | $ bash build.sh | ||
- | // run mode 1 | + | # Run mode 1 |
$ cd install/ | $ cd install/ | ||
$ ./facenet data/ | $ ./facenet data/ | ||
``` | ``` | ||
- | After running mode 1, a file named face_feature_lib will generate in edge2-npu/ | + | After running mode 1, a file named '' |
```shell | ```shell | ||
- | // run mode 2 | + | # Run mode 2 |
$ ./facenet data/ | $ ./facenet data/ | ||
``` | ``` | ||