Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:edge2:npu:npu-convert

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
Last revision Both sides next revision
products:sbc:edge2:npu:npu-convert [2023/08/22 05:55]
louis
products:sbc:edge2:npu:npu-convert [2024/04/25 03:47]
louis
Line 1: Line 1:
-Edge2 NPU Model Convert 修改稿+{{indexmenu_n>3}} 
 ====== NPU Model Convert ====== ====== NPU Model Convert ======
  
Line 25: Line 26:
 ===== 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 44: Line 45:
 ===== Convert Model ===== ===== Convert Model =====
  
-Converting model has five main steps. Create RKNN object, pre-process config, load model, build model and export RKNN model. Here, take ''yolov5'' ‘’onnx’’ as an example.+Converting model has five main steps. Create RKNN object, pre-process config, load model, build model and export RKNN model. Here, take ''yolov5'' ''onnx'' as an example.
  
 Create RKNN object.  Create RKNN object. 
  
-```shell+```python
 # Create RKNN object # Create RKNN object
 rknn = RKNN(verbose=True)  rknn = RKNN(verbose=True) 
Line 55: Line 56:
 Pre-process config. Pre-process config.
  
-```shell+```python
 # pre-process config # pre-process config
 print('--> Config model') print('--> Config model')
Line 65: Line 66:
   * **std_values** - The variance of normalization parameter.   * **std_values** - The variance of normalization parameter.
 model input = (image – mean_values) / std_values model input = (image – mean_values) / std_values
-  * **target_platform** - Chooses ‘’rk3588’’.+  * **target_platform** - Chooses ''rk3588''.
  
 Load model. Load model.
  
-```shell+```python
 # Load ONNX model # Load ONNX model
 print('--> Loading model') print('--> Loading model')
-ret = rknn.load_onnx(model=./yolov5.onnx)+ret = rknn.load_onnx(model='./yolov5.onnx')
 if ret != 0: if ret != 0:
     print('Load model failed!')     print('Load model failed!')
Line 83: Line 84:
 Load other platform model. Load other platform model.
  
-```shell+```python
 # Load pytorch model # Load pytorch model
 print('--> Loading model') print('--> Loading model')
Line 130: Line 131:
 ``` ```
  
-  * **inputs/outputs** - Only use in ‘’tensorflow’’ model. It is the name of inputs/outputs.+  * **inputs/outputs** - Only use in tensorflow model. It is the name of inputs/outputs.
   * **input_size_list** - The size and channels of input.   * **input_size_list** - The size and channels of input.
  
 Build model Build model
  
-```shell+```python
 # Build model # Build model
 print('--> Building model') print('--> Building model')
-ret = rknn.build(do_quantization=True, 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 150: Line 151:
 Export RKNN model Export RKNN model
  
-```shell+```python
 # Export RKNN model # Export RKNN model
 print('--> Export rknn model') print('--> Export rknn model')
-ret = rknn.export_rknn(export_path=./yolov5_int8.rknn)+ret = rknn.export_rknn(export_path='./yolov5_int8.rknn')
 if ret != 0: if ret != 0:
     print('Export rknn model failed!')     print('Export rknn model failed!')
Line 162: Line 163:
   * **export_path** - The path of rknn model.   * **export_path** - The path of rknn model.
  
-All the above codes can be found in ‘’rknn-toolkit2/examples’’. There are all platforms we support now. Choose ‘’rk3588’’ in rknn-toolkit2/examples/onnx/yolov5/test.py and run the file to convert model.+All the above codes can be found in ''rknn-toolkit2/examples''. There are all platforms we support now. Choose ''rk3588'' in ''rknn-toolkit2/examples/onnx/yolov5/test.py'' and run the file to convert model.
  
 ```diff patch ```diff patch
Line 178: Line 179:
 ``` ```
  
-Run test.py to generate rknn model.+Run ''test.py'' to generate rknn model.
  
 ```shell ```shell
Line 190: Line 191:
 ===== See Also ===== ===== See Also =====
  
-For more usage, please refer to the related documents under ‘’doc’’.+For more usage, please refer to the related documents under ''doc''.
  
  
Last modified: 2024/06/06 21:57 by nick