Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:edge2:npu:demos:retinaface

Differences

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

Link to this comparison view

Next revision
Previous revision
products:sbc:edge2:npu:demos:retinaface [2023/08/22 06:07]
louis created
products:sbc:edge2:npu:demos:retinaface [2025/04/09 23:33] (current)
louis
Line 1: Line 1:
-====== Demo5 retinaface ======+~~tag> NPU RetinaFace Edge2 PyTorch~~
  
-===== Get Source Code =====+====== RetinaFace PyTorch Edge2 Demo - 5 ======
  
-The codes we use.+{{indexmenu_n>5}} 
 + 
 +===== Introduction ===== 
 + 
 +RetinaFace is a face detection model. It can draw five key points on each face, including two eyes, nose and two corners of mouth. 
 + 
 +Inference results on Edge2. 
 + 
 +{{:products:sbc:edge2:npu:demos:retinaface-result.jpg?800|}} 
 + 
 +**Inference speed test**: USB camera about **39ms** per frame. MIPI camera about **33ms** per frame. 
 + 
 +===== Train Model ===== 
 + 
 +The codes we use [[gh>bubbliiiing/retinaface-pytorch]].
  
 ```shell ```shell
 git clone https://github.com/bubbliiiing/retinaface-pytorch git clone https://github.com/bubbliiiing/retinaface-pytorch
 +```
 +
 +Before training, modify ''retinaface-pytorch/utils/utils.py'' as follows.
 +
 +```diff
 +diff --git a/utils/utils.py b/utils/utils.py
 +index 87bb528..4a22f2a 100644
 +--- a/utils/utils.py
 ++++ b/utils/utils.py
 +@@ -25,5 +25,6 @@ def get_lr(optimizer):
 +         return param_group['lr']
 + 
 + def preprocess_input(image):
 +-    image -= np.array((104, 117, 123),np.float32)
 ++    image = image / 255.0
 +     return image
 ``` ```
  
Line 34: Line 64:
 ==== Get convert tool ==== ==== Get convert tool ====
  
-Download Tool from [[https://github.com/rockchip-linux/rknn-toolkit2.git|Rockchip Github]].+Download Tool from [[gh>rockchip-linux/rknn-toolkit2]].
  
 ```shell ```shell
Line 51: Line 81:
 ``` ```
  
-==== convert ==== +==== Convert ====
- +
-Before training, modify retinaface-pytorch/utils/utils.py as follows. +
- +
-```shell +
-diff --git a/utils/utils.py b/utils/utils.py +
-index 87bb528..4a22f2a 100644 +
---- a/utils/utils.py +
-+++ b/utils/utils.py +
-@@ -25,5 +25,6 @@ def get_lr(optimizer): +
-         return param_group['lr'+
-  +
- def preprocess_input(image): +
--    image -= np.array((104, 117, 123),np.float32) +
-+    image = image / 255.0 +
-     return image +
-```+
  
 After training model, we should convert pytorch model to onnx model. Create a python file written as follows and run. After training model, we should convert pytorch model to onnx model. Create a python file written as follows and run.
  
-```shell+```python export.py
 import torch import torch
 import numpy as np import numpy as np
Line 86: Line 100:
 ``` ```
  
-Enter rknn-toolkit2/examples/onnx/yolov5 and modify test.py as follows.+Enter ''rknn-toolkit2/examples/onnx/yolov5'' and modify ''test.py'' as follows.
  
-```shell+```python test.py
 # Create RKNN object # Create RKNN object
 rknn = RKNN(verbose=True) rknn = RKNN(verbose=True)
Line 99: Line 113:
 # Load ONNX model # Load ONNX model
 print('--> Loading model') print('--> Loading model')
-ret = rknn.load_onnx(model=./retinaface.onnx)+ret = rknn.load_onnx(model='./retinaface.onnx')
 if ret != 0: if ret != 0:
     print('Load model failed!')     print('Load model failed!')
Line 107: Line 121:
 # Build model # Build model
 print('--> Building model') print('--> Building model')
-ret = rknn.build(do_quantization=T rue, dataset=./dataset.txt)+ret = rknn.build(do_quantization=True, dataset='./dataset.txt')
 if ret != 0: if ret != 0:
     print('Build model failed!')     print('Build model failed!')
Line 115: Line 129:
 # Export RKNN model # Export RKNN model
 print('--> Export rknn model') print('--> Export rknn model')
-ret = rknn.export_rknn(./retinaface.rknn)+ret = rknn.export_rknn('./retinaface.rknn')
 if ret != 0: if ret != 0:
     print('Export rknn model failed!')     print('Export rknn model failed!')
Line 122: Line 136:
 ``` ```
  
-Run test.py to generate rknn model.+Run ''test.py'' to generate rknn model.
  
 ```shell ```shell
Line 132: Line 146:
 ==== Get source code ==== ==== Get source code ====
  
-Clone the source code form our [[https://github.com/khadas/edge2-npu|Github]].+Clone the source code from our [[gh>khadas/edge2-npu]].
  
 ```shell ```shell
Line 149: Line 163:
 === Picture input demo === === Picture input demo ===
  
-Put retinaface.rknn in edge2-npu/C++/retinaface/data/model.+Put ''retinaface.rknn'' in ''edge2-npu/C++/retinaface/data/model''.
  
 ```shell ```shell
-// compile+# Compile
 $ bash build.sh $ bash build.sh
  
-// run+# Run
 $ cd install/retinaface $ cd install/retinaface
 $ ./retinaface data/model/retinaface.rknn data/img/timg.jpg $ ./retinaface data/model/retinaface.rknn data/img/timg.jpg
Line 162: Line 176:
 === Camera input demo === === Camera input demo ===
  
-Put retinaface.rknn in edge2-npu/C++/retinaface_cap/data/model.+Put ''retinaface.rknn'' in ''edge2-npu/C++/retinaface_cap/data/model''.
  
 ```shell ```shell
-// compile+# Compile
 $ bash build.sh $ bash build.sh
  
-// run+# Run USB camera 
 +$ cd install/retinaface_cap 
 +$ ./retinaface_cap data/model/retinaface.rknn usb 60 
 + 
 +# Run MIPI camera
 $ cd install/retinaface_cap $ cd install/retinaface_cap
-$ ./retinaface_cap data/model/retinaface_cap.rknn 33+$ ./retinaface_cap data/model/retinaface.rknn mipi 42
 ``` ```
  
-''33'' is the interface of camera.+<WRAP info > 
 +''60'' and ''42'' are camera device index. 
 +</WRAP>
  
Last modified: 2023/08/22 06:07 by louis