airockchip / rknn_model_zoo

Apache License 2.0
1.05k stars 192 forks source link

yolov5转onnx #118

Closed moyu026 closed 6 months ago

moyu026 commented 6 months ago

使用yolov5项目中的export.py转出来的输出是shape是 (1,25200,85),但是rknn里提供的yolov5.onnx模型的输出的是一个list dd42f7f47f4276c957295b7401ce04a 怎么才能转成和rknn提供的一样的onnx模型

lllittleX commented 6 months ago

我也遇到这个问题了,两种格式都会报错,你解决了吗

moyu026 commented 6 months ago

用rknn项目里的yolov5项目就好了,https://github.com/airockchip/yolov5/tree/master

moyu026 commented 6 months ago

这个链接的项目是用来把yolo的pt文件转成rknn格式的,https://github.com/airockchip/yolov5/blob/master/README_rkopt.md

for detection model

python export.py --rknpu --weight yolov5s.pt

for segmentation model

python export.py --rknpu --weight yolov5s-seg.pt

lllittleX commented 6 months ago

我知道要让它一样,需要修改yolo里的forword,得到list[1,x,80,80],[1,x,40,40],[1,x,20,20]]。我的问题是我的ubuntu里跑那个yolo.py老是报形状有问题,不知道你有咩有遇到 Model-/home/xk/code/rknn_model_zoo-main/examples/yolov5/model/XHNQ01_V1.0.1_20240513.onnx is onnx model, starting val 3 Traceback (most recent call last): File "/home/xk/code/rknn_model_zoo-main/examples/yolov5/python/yolov5_mydataset.py", line 287, in boxes, classes, scores = post_process(outputs, anchors) File "/home/xk/code/rknn_model_zoo-main/examples/yolov5/python/yolov5_mydataset.py", line 124, in post_process input_data = [_in.reshape([len(anchors[0]), -1] + list(_in.shape[-2:])) for _in in input_data] File "/home/xk/code/rknn_model_zoo-main/examples/yolov5/python/yolov5_mydataset.py", line 124, in input_data = [_in.reshape([len(anchors[0]), -1] + list(_in.shape[-2:])) for _in in input_data] ValueError: cannot reshape array of size 409600 into shape (3,newaxis,40,40) (1, 399, 80, 80) (1, 256, 40, 40) (1, 512, 20, 20)

moyu026 commented 6 months ago

这个项目导出来的onnx文件就是你需要的shape的,按这个https://github.com/airockchip/yolov5/blob/master/README_rkopt.md 操作就好了,不用修改yolo.py文件

lllittleX commented 6 months ago

好嘟,非常感谢