4165 views|4 replies

53

Posts

4

Resources
The OP
 

#AI Challenge Camp Second Stop# The process of converting ONNX to RKNN model under Windows [Copy link]

This post was last edited by MioChan on 2024-4-26 23:53

Step 1: Environment Configuration

Download the 1.7.5 compressed package in the release of the rknn-toolkit git repository:

链接已隐藏,如需查看请登录或者注册
. After decompression, you can see whl files for multiple platforms. Here I choose

rknn_toolkit-1.7.5-cp36-cp36m-win_amd64.whl file.

In addition, this library does not support higher versions of Python. It is recommended to create a new conda virtual environment for Python 3.6. In addition, this library has various dependencies, such as pytorch and tensorflow, which must be installed to run normally, and the version cannot be too high.

conda create --name=RKNNpython=3.6.13

Activate the environment

conda activate RKNN

Upgrade pip and change Tsinghua source

python -m pip install --upgrade
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

Manually install these libraries, the others will be automatically installed when installing rknn-toolkit

pip install scikit-build
pip install opencv-python==4.3.0.38
pip install torch==1.10.1torchversion==0.11.2
pip install tensorflow==1.15.5
pip install matplotlib

Install the whl file downloaded before

pip install rknn_toolkit-1.7.5-cp36-cp36m-win_amd64.whl

Note that if the current path of the command line is not the folder where the whl file is located, you need to put its path before the whl file name, like this:

pip install E:\rknn_toolkit-1.7.0-cp36-cp36m-win_amd64.whl

Normally, it can run smoothly, but if other libraries are missing, just use pip install or conda install to install what is missing.

Step 2: Write code to complete the conversion

from rknn.api import RKNN

# 创建 RKNN 对象
rknn = RKNN()
# 加载 ONNX 模型
ret = rknn.load_onnx(model='mnist_cnn.onnx')

# 模型配置
rknn.config(mean_values=[[128]], std_values=[[128]]) #图片归一化到【-1,1】
# 模型转换
ret = rknn.build(do_quantization=False)  # 这里设置是否量化

# 保存 RKNN 模型
ret = rknn.export_rknn('mnist_cnn.rknn')

# 释放 RKNN 对象
rknn.release()

In addition, the ONNX version cannot exceed 11, otherwise the conversion will report an error. In the previous task, add the version setting parameter to the code for exporting ONNX.

# 导出模型到ONNX格式
torch.onnx.export(model, dummy_input, 'mnist_cnn.onnx',
                  input_names=['input'], output_names=['output'],  # 输入和输出节点名称
                  do_constant_folding=True,  # 是否执行常量折叠优化
                  export_params=True,  # 是否包含权重
                    opset_version=10, #设置版本
                  verbose=True)  # 是否打印转换细节

mnist_cnn.rknn

832.07 KB, downloads: 1

mnist_cnn.pth

1.61 MB, downloads: 0

mnist_cnn.onnx

1.63 MB, downloads: 2

This post is from Embedded System

Latest reply

I also encountered this problem. It seems that the writing process of the terminal log is occupied. Here is the solution: When creating the rknn object, specify the output directory of the log. I create an output.txt in the current directory to receive it, so that the process will not be reported as occupied.   Details Published on 2024-5-15 14:23

734

Posts

4

Resources
2
 

The content shared by the host about the environment configuration of ONNX to RKNN model process under Windows is very helpful for beginners. Thanks to the host.

This post is from Embedded System
 
 

59

Posts

0

Resources
3
 

The onnx version cannot be too high, this bug is so magical

This post is from Embedded System
 
 
 

11

Posts

0

Resources
4
 
How to solve the problem of rknn.config? PermissionError: [WinError 32] The process cannot access the file because it is being used by another process. : 'C:\\Users\\24423\\AppData\\Local\\Temp\\tmpx00mgkkk\\log_feedback_to_the_rknn_toolkit_dev_team.log'
This post is from Embedded System
 
 
 

1

Posts

0

Resources
5
 
xianhangCheng posted on 2024-5-8 11:16 Please, how to solve the problem of rknn.config, PermissionError: [WinError 32] Another process is using this file, the process cannot...

I also encountered this problem. It seems that the writing process of the terminal log is occupied. Here is the solution:

When creating the rknn object, specify the output directory of the log. I create an output.txt in the current directory to receive it, so that the process will not be reported as occupied.

This post is from Embedded System
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list