ONNX @riscv+OpenKylin

2024-03-20 13:28
文章标签 onnx openkylin riscv

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/829586

相关文章

yolov8 pt转onnx

第一步: 安装onnx pip install --upgrade onnx 第二步: 将以下代码创建、拷贝到yolov8根目录下。具体代码test.py: from ultralytics import YOLO# Load a modelmodel = YOLO('yolov8n.pt') # load an official model# Export the model

基于yolov8的包装盒纸板破损缺陷测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的包装盒纸板破损缺陷检测系统是一种高效、智能的解决方案,旨在提高生产线上包装盒纸板的质量检测效率与准确性。该系统利用YOLOv8这一前沿的深度学习模型,通过其强大的目标检测能力,能够实时识别并标记出包装盒纸板上的各种破损缺陷,如划痕、撕裂、孔洞等。 在系统中,首先需对包含破损缺陷的包装盒纸板图像进行数据采集和标注,形成训练数据集。随后,利用这些数据进行模型训练,使

基于yolov8的NEU-DET钢材缺陷检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的NEU-DET钢材缺陷检测系统是一种创新的解决方案,旨在通过深度学习技术实现对钢材表面缺陷的自动检测和识别。该系统利用YOLOv8算法,该算法以其高效、准确和实时检测的特点著称。 NEU-DET数据集为该系统提供了丰富的训练资源,涵盖了热轧带钢的六种典型表面缺陷,包括轧制氧化皮、斑块、开裂、点蚀表面、内含物和划痕,每种缺陷均有大量样本,确保了模型的全面性和准确性

基于yolov8的电动车佩戴头盔检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的电动车佩戴头盔检测系统利用了YOLOv8这一先进的目标检测模型,旨在提高电动车骑行者的安全意识,减少因未佩戴头盔而导致的交通事故风险。YOLOv8作为YOLO系列的最新版本,在检测速度和精度上均进行了优化,特别适用于处理复杂场景中的小目标检测。 该系统通过收集并标注包含电动车骑行者图像的数据集,对YOLOv8模型进行训练,使其能够准确识别骑行者是否佩戴头盔。在实

基于yolov8的西红柿缺陷检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的西红柿缺陷检测系统是一个利用深度学习技术的创新项目,旨在通过自动化和智能化的方式提高西红柿缺陷检测的准确性和效率。该系统利用YOLOv8目标检测算法,该算法以其高效性和准确性在目标检测领域表现出色。YOLOv8不仅继承了YOLO系列模型的优势,还引入了新的骨干网络、Anchor-Free检测头以及优化后的损失函数,这些改进使得模型在复杂环境下的检测性能更加优越。

基于yolov5的西红柿成熟度检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv5的西红柿成熟度检测系统是一个利用先进深度学习技术的创新项目,旨在提高西红柿成熟度检测的准确性和效率。该系统以YOLOv5为核心算法,该算法由Ultralytics公司于2020年发布,并在YOLOv3的基础上进行了显著改进。YOLOv5以其高效性和准确性在实时目标检测领域备受关注,特别适用于农业视觉检测任务。 该系统通过收集并预处理大量不同成熟度的西红柿图像数据,

基于yolov8的水面垃圾水面漂浮物检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的水面垃圾与漂浮物检测系统是一种高效、智能的监测解决方案。该系统利用YOLOv8这一前沿的深度学习模型,结合智能视频分析技术,对河道、湖泊等水面的垃圾漂浮物进行实时监测与识别。 YOLOv8作为YOLO系列的最新迭代,以其高准确度和实时检测能力著称。通过复杂的网络架构、优化的训练流程和强大的特征提取能力,YOLOv8能够在各种光照和水质条件下,准确识别包括生活垃圾

基于yolov8的路面垃圾检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的路面垃圾检测系统是一种利用深度学习技术实现的高效、精准的路面垃圾检测解决方案。该系统采用了YOLOv8目标检测算法,该算法在速度和精度上均表现出色,能够实时或近实时地检测路面上的垃圾。 系统通过训练YOLOv8模型,使其能够识别并定位多种类型的路面垃圾,如塑料袋、纸屑等。在实际应用中,系统可以支持图片、视频以及摄像头的输入,通过界面实时显示目标位置、检测结果、和

基于yolov5的猪只识别计数检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv5的猪只识别计数检测系统是一种创新的农业应用解决方案,它结合了深度学习和计算机视觉技术,专为提高养猪业的管理效率和精确度而设计。该系统利用YOLOv5这一先进的目标检测模型,能够实时、准确地在图像或视频中识别并计数猪只。 YOLOv5以其轻量级、高速和准确的特点著称,特别适合用于复杂多变的农场环境。通过摄像头采集的图像数据,系统能够自动检测并标记出每一头猪的位置和数

YOLOV----- ONNX 推理过程、可视化图片、保存检测到的目标

一、代码 import osimport cv2import numpy as npimport onnxruntimeimport timeCLASSES = ['person'] # coco80类别class YOLOV5():def __init__(self, onnxpath):self.onnx_session = onnxruntime.InferenceSession