本文主要是介绍ONNX @riscv+OpenKylin,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
安装onnxruntime-riscv
下载软件:
git clone https://github.com/ucb-bar/onnxruntime-riscv
apt install unzip
cd onnxruntime-riscv && sh build.sh
报错...
改了g++环境变量部分还是不行,放弃。
安装onnxruntime
使用这个库
git clone https://github.com/zhangwm-pt/onnxruntime
因为刚开始报错需要cmake>3.25 ,所以去Download CMake
下载了3.28安装,但是configure的时候报错,所以放弃升级cmake,改切onnxruntime到2.6
git switch 2.6export MAX_JOBS=64sh build.sh --allow_running_as_root
第一次需要加上--allow_running_as_root,后面再build就不需要了。
还学到用这个增加编译速度,不管是否有用,先存着
export makeflags=-j64
export MAKEFLAGS=-j64
使用编译好的onnxruntime包@python3.10
创建python3.10环境,
设置多版本并存
下载pip软件:curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
使用编译好的onnxruntime包@python3.11
安装3.11python环境
apt install python3.11
设置多版本并存
update-alternatives --install /bin/python3 python3 /bin/python3.8 1
update-alternatives --install /bin/python3 python3 /bin/python3.10 2
update-alternatives --install /bin/python3 python3 /bin/python3.11 3
使用这个命令切换:
update-alternatives --config python3
下载pip软件:curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
切换到3.11之后,安装311的包,其中onnx在这里下载: Releases · zhangwm-pt/onnxruntime · GitHub
具体地址:https://github.com/zhangwm-pt/onnxruntime/releases/download/riscv_whl_v2.9/onnxruntime-2.9.0-cp311-cp311-linux_riscv64.whl
onnx@飞桨
调试
build.sh报错
看build.sh内容,这三句存疑问
export CXX=riscv64-unknown-linux-gnu-g++
export CC=riscv64-unknown-linux-gnu-gcc
export CXXFLAGS="-march=rv64imafdc -mabi=lp64d"
修该成
export CXX=g++
export CC=gcc
export CXXFLAGS="-march=rv64imafdc -mabi=lp64d"
报错Could not find 'flake8' to check python scripts.
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
CMake Warning at flake8.cmake:19 (message):
Could not find 'flake8' to check python scripts. Please install flake8
using pip.
Call Stack (most recent call first):
CMakeLists.txt:1776 (include)
新库报错
2024-03-18 04:21:50,299 build [INFO] - Generating CMake build tree
CMake Error at CMakeLists.txt:5 (cmake_minimum_required):
CMake 3.26 or higher is required. You are running version 3.25.1
本来想安装cmake2.28的,但是编译太慢了,准备用onnx2.81 因为它用cmake3.24就行了。
切2.81 git checkout 2.8.1 怀疑没切成,因为还需要cmake>3.25
切2.6 git switch 2.6
cmake3.28configure报错
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)
CMake Error at Utilities/cmcurl/CMakeLists.txt:647 (message):
Could not find OpenSSL. Install an OpenSSL development package or
configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.
没事,不安装3.28了。
最终onnx本地没有编译成功,转而使用已编译好的包。已编译好的包只支持python3.10和3.11
onnx推理报错
class_id:15, confidence:0.9407, left_top:[-0.20,0.11],right_bottom:[499.84,375.78] Traceback (most recent call last):File "/home/aistudio/Paddle2ONNX/model_zoo/detection/infer.py", line 341, in <module>save_imgs(File "/home/aistudio/Paddle2ONNX/model_zoo/detection/utils/visualize.py", line 139, in save_imgsim = visualize_box_mask(File "/home/aistudio/Paddle2ONNX/model_zoo/detection/utils/visualize.py", line 173, in visualize_box_maskim = draw_box(im, results['boxes'], labels, threshold=threshold)File "/home/aistudio/Paddle2ONNX/model_zoo/detection/utils/visualize.py", line 287, in draw_boxtw, th = draw.textsize(text) AttributeError: 'ImageDraw' object has no attribute 'textsize'
降低Pillow版本解决 pip install Pillow==9.5.0
编译过程中到80%左右报错
/usr/bin/ld: libonnxruntime_common.a(threadpool.cc.o): in function `std::atomic<onnxruntime::concurrency::RunQueue<std::function<void ()>, onnxruntime::concurrency::ThreadPoolTempl<onnxruntime::Env>::Tag, 1024u>::ElemState>::compare_exchange_strong(onnxruntime::concurrency::RunQueue<std::function<void ()>, onnxruntime::concurrency::ThreadPoolTempl<onnxruntime::Env>::Tag, 1024u>::ElemState&, onnxruntime::concurrency::RunQueue<std::function<void ()>, onnxruntime::concurrency::ThreadPoolTempl<onnxruntime::Env>::Tag, 1024u>::ElemState, std::memory_order, std::memory_order)':
/usr/include/c++/9/atomic:324: undefined reference to `__atomic_compare_exchange_1'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/onnxruntime_mlas_test.dir/build.make:422: onnxruntime_mlas_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:2236: CMakeFiles/onnxruntime_mlas_test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
重新编译,报错变成
/usr/bin/ld: libonnxruntime_common.a(threadpool.cc.o): in function `std::atomic<onnxruntime::concurrency::RunQueue<std::function<void ()>, onnxruntime::concurrency::ThreadPoolTempl<onnxruntime::Env>::Tag, 1024u>::ElemState>::compare_exchange_strong(onnxruntime::concurrency::RunQueue<std::function<void ()>, onnxruntime::concurrency::ThreadPoolTempl<onnxruntime::Env>::Tag, 1024u>::ElemState&, onnxruntime::concurrency::RunQueue<std::function<void ()>, onnxruntime::concurrency::ThreadPoolTempl<onnxruntime::Env>::Tag, 1024u>::ElemState, std::memory_order, std::memory_order)': /usr/include/c++/9/atomic:324: undefined reference to `__atomic_compare_exchange_1' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/onnxruntime_mlas_test.dir/build.make:422: onnxruntime_mlas_test] Error 1 make[1]: *** [CMakeFiles/Makefile2:2236: CMakeFiles/onnxruntime_mlas_test.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs....
尝试 apt-get install libatomic-ops-dev
还是报错
切换到2.8版本,需要cmake升级到3.28
编译cmake3.28时报错:
make: 'cmake' is up to date.
loading initial cache file /root/work/cmake-3.28.3/Bootstrap.cmk/InitialCacheFlags.cmake
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)
CMake Error at Utilities/cmcurl/CMakeLists.txt:647 (message):
Could not find OpenSSL. Install an OpenSSL development package or
configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.
尝试apt-get install libssl-dev
过了,bootstrap继续下去了。
make报错
/usr/bin/ld: ../Utilities/cmcppdap/libcmcppdap.a(io.cpp.o): in function `.L0 ': io.cpp:(.text+0x462): undefined reference to `__atomic_exchange_1' /usr/bin/ld: io.cpp:(.text+0x566): undefined reference to `__atomic_exchange_1' /usr/bin/ld: io.cpp:(.text+0x5be): undefined reference to `__atomic_exchange_1' /usr/bin/ld: io.cpp:(.text+0x5fa): undefined reference to `__atomic_exchange_1' /usr/bin/ld: io.cpp:(.text+0x648): undefined reference to `__atomic_exchange_1' /usr/bin/ld: ../Utilities/cmcppdap/libcmcppdap.a(io.cpp.o):io.cpp:(.text+0x698): more undefined references to `__atomic_exchange_1' follow collect2: error: ld returned 1 exit status make[2]: *** [Source/CMakeFiles/cmake.dir/build.make:130: bin/cmake] Error 1 make[1]: *** [CMakeFiles/Makefile2:2220: Source/CMakeFiles/cmake.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs....
这里过不去了,先搁置,准备用现成的包。
切换pip3.10和pip3.11后,都报错
File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
from pip._vendor import html5lib, requests
ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
解决方法:
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
安装好onnx之后,运行报错:
>>> import onnxruntime
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/.local/lib/python3.11/site-packages/onnxruntime/__init__.py", line 55, in <module>
raise import_capi_exception
File "/root/.local/lib/python3.11/site-packages/onnxruntime/__init__.py", line 23, in <module>
from onnxruntime.capi._pybind_state import (
File "/root/.local/lib/python3.11/site-packages/onnxruntime/capi/_pybind_state.py", line 33, in <module>
from .onnxruntime_pybind11_state import * # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: libshl_th1520.so.2: cannot open shared object file: No such file or directory
手工执行pip install onnxruntime -U 之后报错
i>>> import onnxruntime
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/dist-packages/onnxruntime/__init__.py", line 52, in <module>
from onnxruntime.capi import onnxruntime_validation
File "/usr/local/lib/python3.10/dist-packages/onnxruntime/capi/onnxruntime_validation.py", line 8, in <module>
import linecache
File "/usr/lib/python3.11/linecache.py", line 11, in <module>
import tokenize
File "/usr/lib/python3.11/tokenize.py", line 33, in <module>
import re
File "/usr/lib/python3.11/re/__init__.py", line 125, in <module>
from . import _compiler, _parser
File "/usr/lib/python3.11/re/_compiler.py", line 18, in <module>
assert _sre.MAGIC == MAGIC, "SRE module mismatch"
AssertionError: SRE module mismatch
这篇关于ONNX @riscv+OpenKylin的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!