This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
products:sbc:edge2:npu:npu-convert [2023/08/22 05:56] louis |
products:sbc:edge2:npu:npu-convert [2024/06/06 21:57] (current) nick |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== NPU Model Convert ====== | + | {{indexmenu_n> |
+ | |||
+ | ====== | ||
===== Build Virtual Environment ===== | ===== Build Virtual Environment ===== | ||
Line 24: | Line 26: | ||
===== Get Convert Tool ===== | ===== Get Convert Tool ===== | ||
- | Download Tool from [[https:// | + | Download Tool from [[gh>rockchip-linux/ |
```shell | ```shell | ||
Line 43: | 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 '' | + | Converting model has five main steps. Create RKNN object, pre-process config, load model, build model and export RKNN model. Here, take '' |
Create RKNN object. | Create RKNN object. | ||
- | ```shell | + | ```python |
# Create RKNN object | # Create RKNN object | ||
rknn = RKNN(verbose=True) | rknn = RKNN(verbose=True) | ||
Line 54: | Line 56: | ||
Pre-process config. | Pre-process config. | ||
- | ```shell | + | ```python |
# pre-process config | # pre-process config | ||
print(' | print(' | ||
Line 64: | 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 | + | * **target_platform** - Chooses |
Load model. | Load model. | ||
- | ```shell | + | ```python |
# 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 82: | Line 84: | ||
Load other platform model. | Load other platform model. | ||
- | ```shell | + | ```python |
# Load pytorch model | # Load pytorch model | ||
print(' | print(' | ||
Line 129: | Line 131: | ||
``` | ``` | ||
- | * **inputs/ | + | * **inputs/ |
* **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(' | print(' | ||
- | ret = rknn.build(do_quantization=True, | + | ret = rknn.build(do_quantization=True, |
if ret != 0: | if ret != 0: | ||
print(' | print(' | ||
Line 149: | Line 151: | ||
Export RKNN model | Export RKNN model | ||
- | ```shell | + | ```python |
# Export RKNN model | # Export RKNN model | ||
print(' | print(' | ||
- | ret = rknn.export_rknn(export_path=“./ | + | ret = rknn.export_rknn(export_path='./ |
if ret != 0: | if ret != 0: | ||
print(' | print(' | ||
Line 161: | 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/ | + | All the above codes can be found in '' |
```diff patch | ```diff patch | ||
Line 177: | Line 179: | ||
``` | ``` | ||
- | Run test.py to generate rknn model. | + | Run '' |
```shell | ```shell | ||
Line 189: | 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 '' |