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 [2023/09/20 03:12] (current) louis |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ~~tag> NPU FaceNet Edge2 PyTorch~~ |
+ | |||
+ | ====== | ||
+ | |||
+ | {{indexmenu_n> | ||
===== Get Source Code ===== | ===== Get Source Code ===== | ||
- | The codes we use. | + | The codes we use [[gh> |
```shell | ```shell | ||
Line 34: | Line 38: | ||
==== Get convert tool ==== | ==== Get convert tool ==== | ||
- | Download Tool from [[https:// | + | Download Tool from [[gh>rockchip-linux/ |
```shell | ```shell | ||
Line 41: | Line 45: | ||
``` | ``` | ||
- | Install dependences and RKNN toolkit2 packages, | + | Install dependences and RKNN toolkit2 packages. |
```shell | ```shell | ||
Line 51: | Line 55: | ||
``` | ``` | ||
- | ==== 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 76: | ||
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 90: | ||
``` | ``` | ||
- | 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 103: | ||
# 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 111: | ||
# 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 119: | ||
# 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 126: | ||
``` | ``` | ||
- | Run test.py to generate rknn model. | + | Run '' |
```shell | ```shell | ||
Line 132: | Line 136: | ||
==== 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 153: | ||
=== 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/ | ||
``` | ``` | ||