bash
/mnt/e/github/rknn_model_zoo/examples/yolov5/python$ python convert.py ../model/yolov5s_relu.onnx rv1106 i8 ../model/yolov5s_relu.rknn
/home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages/rknn/api/rknn.py:51: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
self.rknn_base = RKNNBase(cur_path, verbose)
I rknn-toolkit2 version: 2.3.2
--> Config model
done
--> Loading model
I Loading : 100%|██████████████████████████████████████████████| 121/121 [00:00<00:00, 14200.08it/s]
E load_onnx: Traceback (most recent call last):
File "rknn/api/rknn_log.py", line 344, in rknn.api.rknn_log.error_catch_decorator.error_catch_wrapper
File "rknn/api/rknn_base.py", line 1579, in rknn.api.rknn_base.RKNNBase.load_onnx
File "rknn/api/rknn_base.py", line 613, in rknn.api.rknn_base.RKNNBase._create_ir_and_inputs_meta
File "rknn/api/ir_graph.py", line 84, in rknn.api.ir_graph.IRGraph.__init__
File "rknn/api/ir_graph.py", line 665, in rknn.api.ir_graph.IRGraph.rebuild
File "rknn/api/base_utils.py", line 34, in rknn.api.base_utils.to_np_type
AttributeError: module 'onnx' has no attribute 'mapping'
I ===================== WARN(0) =====================
E rknn-toolkit2 version: 2.3.2
Traceback (most recent call last):
File "rknn/api/rknn_log.py", line 344, in rknn.api.rknn_log.error_catch_decorator.error_catch_wrapper
File "rknn/api/rknn_base.py", line 1579, in rknn.api.rknn_base.RKNNBase.load_onnx
File "rknn/api/rknn_base.py", line 613, in rknn.api.rknn_base.RKNNBase._create_ir_and_inputs_meta
File "rknn/api/ir_graph.py", line 84, in rknn.api.ir_graph.IRGraph.__init__
File "rknn/api/ir_graph.py", line 665, in rknn.api.ir_graph.IRGraph.rebuild
File "rknn/api/base_utils.py", line 34, in rknn.api.base_utils.to_np_type
AttributeError: module 'onnx' has no attribute 'mapping'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/f/github/rknn_model_zoo/examples/yolov5/python/convert.py", line 52, in <module>
ret = rknn.load_onnx(model=model_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages/rknn/api/rknn.py", line 168, in load_onnx
return self.rknn_base.load_onnx(model, inputs, input_size_list, input_initial_val, outputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "rknn/api/rknn_log.py", line 349, in rknn.api.rknn_log.error_catch_decorator.error_catch_wrapper
File "rknn/api/rknn_log.py", line 95, in rknn.api.rknn_log.RKNNLog.e
ValueError: Traceback (most recent call last):
File "rknn/api/rknn_log.py", line 344, in rknn.api.rknn_log.error_catch_decorator.error_catch_wrapper
File "rknn/api/rknn_base.py", line 1579, in rknn.api.rknn_base.RKNNBase.load_onnx
File "rknn/api/rknn_base.py", line 613, in rknn.api.rknn_base.RKNNBase._create_ir_and_inputs_meta
File "rknn/api/ir_graph.py", line 84, in rknn.api.ir_graph.IRGraph.__init__
File "rknn/api/ir_graph.py", line 665, in rknn.api.ir_graph.IRGraph.rebuild
File "rknn/api/base_utils.py", line 34, in rknn.api.base_utils.to_np_type
AttributeError: module 'onnx' has no attribute 'mapping'
当前环境中安装的 onnx 版本太高,而 RKNN-Toolkit2 v2.3.2 内部代码仍依赖旧版 ONNX 的 API(如 onnx.mapping),该 API 在新版 ONNX 中已被移除或重构。
确认当前 ONNX 版本
bash
/mnt/e/github/rknn_model_zoo/examples/yolov5/python$ python -c "import onnx; print(onnx.__version__)"
1.20.0
卸载当前 ONNX 并安装兼容版本
RKNN-Toolkit2 v2.3.x 官方推荐使用 ONNX 1.16.1
bash
pip uninstall onnx
Found existing installation: onnx 1.20.0
Uninstalling onnx-1.20.0:
Would remove:
/home/mazhongguang/.conda/envs/toolkit2/bin/backend-test-tools
/home/mazhongguang/.conda/envs/toolkit2/bin/check-model
/home/mazhongguang/.conda/envs/toolkit2/bin/check-node
/home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages/onnx-1.20.0.dist-info/*
/home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages/onnx/*
Proceed (Y/n)? y
Successfully uninstalled onnx-1.20.0
尝试安装 onnx
bash
pip install onnx==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
报错如下:
bash
guang@Thinkbook:/mnt/e/github/rknn_model_zoo/examples/yolov5/python$ pip install onnx==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting onnx==1.14.0
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d2/f4/8bdd479ace89b7957231157cfdfec4be629e5bbbbebe21535d6c40df6d02/onnx-1.14.0.tar.gz (11.3 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages (from onnx==1.14.0) (1.26.4)
Requirement already satisfied: protobuf>=3.20.2 in /home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages (from onnx==1.14.0) (4.25.4)
Requirement already satisfied: typing-extensions>=3.6.2.1 in /home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages (from onnx==1.14.0) (4.15.0)
Building wheels for collected packages: onnx
Building wheel for onnx (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for onnx (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [120 lines of output]
<string>:33: DeprecationWarning: Use shutil.which instead of find_executable
<string>:34: DeprecationWarning: Use shutil.which instead of find_executable
致命错误:不是 git 仓库(或者直至挂载点 / 的任何父目录)
停止在文件系统边界(未设置 GIT_DISCOVERY_ACROSS_FILESYSTEM)。
/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py:289: UserWarning: Unknown distribution option: 'tests_require'
warnings.warn(msg)
running bdist_wheel
running build
running build_py
running create_version
running cmake_build
Using cmake args: ['/usr/bin/cmake3', '-DPYTHON_INCLUDE_DIR=/home/mazhongguang/.conda/envs/toolkit2/include/python3.12', '-DPYTHON_EXECUTABLE=/home/mazhongguang/.conda/envs/toolkit2/bin/python3.12', '-DBUILD_ONNX_PYTHON=ON', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DONNX_NAMESPACE=onnx', '-DPY_EXT_SUFFIX=.cpython-312-x86_64-linux-gnu.so', '-DCMAKE_BUILD_TYPE=Release', '-DONNX_ML=1', '/tmp/pip-install-9jnhve_2/onnx_c163a1b87f884daea2b436bd3df9b84a']
CMake Deprecation Warning at CMakeLists.txt:2 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
CMake.
Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
-- The C compiler identification is GNU 15.2.1
-- The CXX compiler identification is GNU 15.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:119 (find_package):
Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
are removed. Run "cmake --help-policy CMP0148" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Found PythonInterp: /home/mazhongguang/.conda/envs/toolkit2/bin/python3.12 (found version "3.12.12")
CMake Warning (dev) at CMakeLists.txt:121 (find_package):
Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
are removed. Run "cmake --help-policy CMP0148" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Found PythonLibs: /home/mazhongguang/.conda/envs/toolkit2/lib/libpython3.12.so (found version "3.12.12")
Generated: /tmp/pip-install-9jnhve_2/onnx_c163a1b87f884daea2b436bd3df9b84a/.setuptools-cmake-build/onnx/onnx-ml.proto
CMake Error at CMakeLists.txt:303 (message):
Protobuf compiler not found
Call Stack (most recent call first):
CMakeLists.txt:334 (relative_protobuf_generate_cpp)
-- Configuring incomplete, errors occurred!
Traceback (most recent call last):
File "/home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
main()
File "/home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main
json_out["return_val"] = hook(**hook_input["kwargs"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 280, in build_wheel
return _build_backend().build_wheel(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 435, in build_wheel
return _build(['bdist_wheel', '--dist-info-dir', str(metadata_directory)])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 423, in _build
return self._build_with_temp_dir(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 404, in _build_with_temp_dir
self.run_setup()
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 512, in run_setup
super().run_setup(setup_script=setup_script)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 317, in run_setup
exec(code, locals())
File "<string>", line 342, in <module>
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 115, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 186, in setup
return run_commands(dist)
^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 202, in run_commands
dist.run_commands()
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1002, in run_commands
self.run_command(cmd)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 1102, in run_command
super().run_command(command)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command
cmd_obj.run()
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/command/bdist_wheel.py", line 370, in run
self.run_command("build")
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command
self.distribution.run_command(command)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 1102, in run_command
super().run_command(command)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command
cmd_obj.run()
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command
self.distribution.run_command(command)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 1102, in run_command
super().run_command(command)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command
cmd_obj.run()
File "<string>", line 236, in run
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command
self.distribution.run_command(command)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 1102, in run_command
super().run_command(command)
File "/tmp/pip-build-env-a49os9co/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command
cmd_obj.run()
File "<string>", line 222, in run
File "/home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/subprocess.py", line 413, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/cmake3', '-DPYTHON_INCLUDE_DIR=/home/mazhongguang/.conda/envs/toolkit2/include/python3.12', '-DPYTHON_EXECUTABLE=/home/mazhongguang/.conda/envs/toolkit2/bin/python3.12', '-DBUILD_ONNX_PYTHON=ON', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DONNX_NAMESPACE=onnx', '-DPY_EXT_SUFFIX=.cpython-312-x86_64-linux-gnu.so', '-DCMAKE_BUILD_TYPE=Release', '-DONNX_ML=1', '/tmp/pip-install-9jnhve_2/onnx_c163a1b87f884daea2b436bd3df9b84a']' returned non-zero exit status 1.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for onnx
Failed to build onnx
error: failed-wheel-build-for-install
× Failed to build installable wheels for some pyproject.toml based projects
╰─> onnx
安装protobuf-compiler protobuf-devel
bash
guang@Thinkbook:/mnt/e/github/rknn_model_zoo/examples/yolov5/python$ sudo dnf install protobuf-compiler protobuf-devel
仓库更新和加载中:
仓库加载完成。
Package Arch Version Repository Size
Installing:
protobuf-compiler x86_64 3.19.6-18.fc43 fedora 2.5 MiB
protobuf-devel x86_64 3.19.6-18.fc43 fedora 2.7 MiB
Transaction Summary:
Installing: 2 packages
本次要处理的软件包总大小为 1 MiB. 还需下载 1 MiB。
此次操作完成之后,5 MiB 额外的空间被使用 (安装 5 MiB, 删除 0 B)。
Is this ok [y/N]: y
[1/2] protobuf-devel-0:3.19.6-18.fc43.x86_64 100% | 230.7 KiB/s | 389.0 KiB | 00m02s
[2/2] protobuf-compiler-0:3.19.6-18.fc43.x86_64 100% | 438.2 KiB/s | 783.5 KiB | 00m02s
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[2/2] Total 100% | 655.0 KiB/s | 1.1 MiB | 00m02s
执行事务
[1/4] 验证软件包文件 100% | 200.0 B/s | 2.0 B | 00m00s
[2/4] 准备事务 100% | 2.0 B/s | 2.0 B | 00m01s
[3/4] 安装protobuf-compiler-0:3.19.6-18.fc43.x86_64 100% | 47.9 MiB/s | 2.5 MiB | 00m00s
[4/4] 安装protobuf-devel-0:3.19.6-18.fc43.x86_64 100% | 3.9 MiB/s | 2.8 MiB | 00m01s
完成!
再次尝试安装
bash
guang@Thinkbook:/mnt/e/github/rknn_model_zoo/examples/yolov5/python$ pip install onnx==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting onnx==1.14.0
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d2/f4/8bdd479ace89b7957231157cfdfec4be629e5bbbbebe21535d6c40df6d02/onnx-1.14.0.tar.gz (11.3 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages (from onnx==1.14.0) (1.26.4)
Requirement already satisfied: protobuf>=3.20.2 in /home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages (from onnx==1.14.0) (4.25.4)
Requirement already satisfied: typing-extensions>=3.6.2.1 in /home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages (from onnx==1.14.0) (4.15.0)
Building wheels for collected packages: onnx
Building wheel for onnx (pyproject.toml) ... done
Created wheel for onnx: filename=onnx-1.14.0-cp312-cp312-linux_x86_64.whl size=13823887 sha256=a494c9c80c98d4744df67e7e6986afd1148d1a896418f60de46c44273321772f
Stored in directory: /home/mazhongguang/.cache/pip/wheels/7d/4e/6f/9ed818d356eeb773973fa8122bf7138b8e4c329a096a624db2
Successfully built onnx
Installing collected packages: onnx
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
rknn-toolkit2 2.3.2 requires onnx>=1.16.1, but you have onnx 1.14.0 which is incompatible.
Successfully installed onnx-1.14.0
提示需要安装1.16.1
bash
guang@Thinkbook:/mnt/e/github/rknn_model_zoo/examples/yolov5/python$ pip install onnx==1.16.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting onnx==1.16.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/14/a9/bb3a9aedbdc6a5ab8423d3d246a8e6d14f527de0d992fefa55d5b23fd7f0/onnx-1.16.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.9 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.9/15.9 MB 14.4 MB/s 0:00:01
Requirement already satisfied: numpy>=1.20 in /home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages (from onnx==1.16.1) (1.26.4)
Requirement already satisfied: protobuf>=3.20.2 in /home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages (from onnx==1.16.1) (4.25.4)
Installing collected packages: onnx
Successfully installed onnx-1.16.1
转换完成
bash
guang@Thinkbook:/mnt/e/github/rknn_model_zoo/examples/yolov5/python$ python convert.py ../model/yolov5s_relu.onnx rv1106 i8 ../model/yolov5s_relu.rknn
/home/mazhongguang/.conda/envs/toolkit2/lib/python3.12/site-packages/rknn/api/rknn.py:51: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
self.rknn_base = RKNNBase(cur_path, verbose)
I rknn-toolkit2 version: 2.3.2
--> Config model
done
--> Loading model
I Loading : 100%|██████████████████████████████████████████████| 121/121 [00:00<00:00, 14217.18it/s]
done
--> Building model
I OpFusing 0: 100%|█████████████████████████████████████████████| 100/100 [00:00<00:00, 2961.43it/s]
I OpFusing 1 : 100%|████████████████████████████████████████████| 100/100 [00:00<00:00, 1543.77it/s]
I OpFusing 2 : 100%|████████████████████████████████████████████| 100/100 [00:00<00:00, 1409.30it/s]
I GraphPreparing : 100%|████████████████████████████████████████| 149/149 [00:00<00:00, 6904.62it/s]
I Quantizating : 100%|████████████████████████████████████████████| 149/149 [00:08<00:00, 18.19it/s]
W build: The default input dtype of 'images' is changed from 'float32' to 'int8' in rknn model for performance!
Please take care of this change when deploy rknn model with Runtime API!
W build: The default output dtype of 'output0' is changed from 'float32' to 'int8' in rknn model for performance!
Please take care of this change when deploy rknn model with Runtime API!
W build: The default output dtype of '286' is changed from 'float32' to 'int8' in rknn model for performance!
Please take care of this change when deploy rknn model with Runtime API!
W build: The default output dtype of '288' is changed from 'float32' to 'int8' in rknn model for performance!
Please take care of this change when deploy rknn model with Runtime API!
I rknn building ...
I rknn building done.
done
--> Export rknn model
done