Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yolov5s demo 报错 ValueError: cannot reshape array of size 7225 into shape (40,85,1,1) #90

Open
NiHe001 opened this issue Aug 26, 2021 · 3 comments

Comments

@NiHe001
Copy link

NiHe001 commented Aug 26, 2021

使用yolov5s的onnx转rknn时,参照examples\onnx\yolov5\test.py会报错如下:
--> Export RKNN model
done
--> Init runtime environment
librknn_runtime version 1.7.0 (9ad5c07 build: 2021-08-06 15:20:31 base: 1131)
done
--> Running model
Traceback (most recent call last):
File "test.py", line 298, in
boxes, classes, scores = yolov5_post_process(input_data)
File "test.py", line 139, in yolov5_post_process
b, c, s = process(input, mask, anchors)
File "test.py", line 56, in process
col = col.reshape(grid_h, grid_w, 1, 1).repeat(3, axis=-2)
ValueError: cannot reshape array of size 7225 into shape (40,85,1,1)

原因:
观察转换后的rknn模型,输出的通道顺序有问题,定位后发现输出节点选择不对。

解决方法:
将:ret = rknn.load_onnx(model=ONNX_MODEL,outputs=['396', '458', '520'])
改为:ret = rknn.load_onnx(model=ONNX_MODEL,outputs=['396', '457', '518'])

@zen-xingle
Copy link

The problem is probably caused by the different onnx opset_version setting when exporting onnx model. We check again that the example work well using opset_version_11.

Thank you for your testing.

@xcls1117
Copy link

xcls1117 commented Sep 28, 2021

@1753939775 真正的问题在这儿呢,

input_data.append(np.transpose(input0_data, (2, 3, 0, 1)))

把transpose的参数从2,3,0,1改成正确的就行啦。这个其实跟你的rknn模型输出有关系,按照你rknn的输出去调这个transpose的参数,比如正常yolov5的onnx输出最后一个featuremap维度是1x3x20x20x85,那么经过它这个你只要调成20x20x3x85就好,但是有时候转出来的rknn模型输出的维度顺序对不上,比如1x85x3x20x20,那么参数就是2,3,1,0(第一个维度已经干掉了前面),网上还有很多1,2,0,3的,他们的RKNN模型输出肯定是1x3x20x20x85。

@BJWillian
Copy link

如何查看我的onnx输出的featuremap 纬度呢?谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants