人工智能
直播中

陈启清

3年用户 17经验值
擅长:嵌入式技术
私信 关注

【爱芯派 Pro 开发板试用体验】yolov8模型转换

尝试将最新的yolov8模型转换为爱芯派的模型。

环境准备

准备Docker环境

首先自己在任意机器上准备好docker环境,详细步骤见官网。

Docker 镜像文件

准备 yolo8 模型,并转换为onnx格式。

下载yolov8n.pt

将PyTorch模型格式转为onnx模型格式。yolo mode=export model=yolov8n.pt format=onnx dynamic=False

这里需要有yolo的环境,自己安装 pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple,有其他需要的依赖包,接着继续安装。

image-3.png

转换完了之后,会生成一个yolov8n.onnx文件。

axmodel模型转换

version=1.9_enc

docker run -it --net host --rm -v **PWD:/data pulsar2:**{version}

预先已使用 onnxsim 将 mobilenetv2.onnx 进行计算图优化

如果用docker 环境,可能会遇到以下错误

onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Failed to load model with error: /onnxruntime_src/onnxruntime/core/graph/model_load_utils.h:47 void onnxruntime::model_load_utils::ValidateOpsetForDomain(const std::unordered_map[std::basic_string](), int>&, const onnxruntime::logging::Logger&, bool, const string&, int) ONNX Runtime only *guarantees* support for models stamped with official released onnx opset versions. Opset 17 is under development and support for this is limited. The operator schemas and or other functionality may change before next ONNX release and in this case ONNX Runtime will not guarantee backward compatibility. Current official support for domain ai.onnx is till opset 16.

image-4.png

主要是onnx和onnxruntime版本不对,更新一下就可以了

pip install onnxruntime==1.15 -i  https://pypi.tuna.tsinghua.edu.cn/simple

然后再运行 onnxsim yolov8n.onnx yolov8nsim.onnx

image-5.png

axmodel转换

准备好config.json文件,然后运行命令。pulsar2 build --input yolov8nsim.onnx --output_dir output --config config.json, 将会得到output/compiled.axmodel文件。

开发板上运行模型评测

通过开发板上预制的ax_run_model 工具,测试模型速度和精度。

image-6.png

示例都是yolov5的,没有yolov8,模型怎么运行还需进一步研究。

更多回帖

发帖
×
20
完善资料,
赚取积分