Toybrick

标题: ONNX Slice转换报错 [打印本页]

作者: theantbully    时间: 2021-9-9 16:36
标题: ONNX Slice转换报错
--> Loading model
I Start importing onnx...
W Call onnx.optimizer.optimize fail, skip optimize
I Current ONNX Model use ir_version 6 opset_version 11
W Infer onnx shape: Meet empty shape tensor, reshape () to (1,)!
D Calc tensor Constant_426 (1,)
W Infer onnx shape: Meet empty shape tensor, reshape () to (1,)!
D Calc tensor Constant_423 (1,)
W Infer onnx shape: Meet empty shape tensor, reshape () to (1,)!
D Calc tensor Constant_420 (1,)
W Infer onnx shape: Meet empty shape tensor, reshape () to (1,)!
D Calc tensor Constant_406 (1,)
W Infer onnx shape: Meet empty shape tensor, reshape () to (1,)!
D Calc tensor Constant_403 (1,)
W Infer onnx shape: Meet empty shape tensor, reshape () to (1,)!
D Calc tensor Constant_400 (1,)
W Infer onnx shape: Meet empty shape tensor, reshape () to (1,)!
D Calc tensor Constant_386 (1,)
W Infer onnx shape: Meet empty shape tensor, reshape () to (1,)!
D Calc tensor Constant_383 (1,)
W Infer onnx shape: Meet empty shape tensor, reshape () to (1,)!
D Calc tensor Constant_380 (1,)

.....

I Try match Slice_Slice_39ut0
W Not match tensor Slice_Slice_39ut0
E Try match Slice_Slice_39ut0 failed, catch exception!
W ----------------Warning(12)----------------
E Catch exception when loading onnx model: yolov5s.onnx!
E Traceback (most recent call last):
E   File "rknn/base/RKNNlib/converter/convert_onnx.py", line 1152, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx.match_paragraph_and_param
E   File "rknn/base/RKNNlib/converter/convert_onnx.py", line 1054, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx._onnx_push_ready_tensor

使用Netron查看ONNX 模型, 存在节点 Slice_Slice_39
[attach]2047[/attach]


作者: theantbully    时间: 2021-9-9 19:47
out = self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1))
这里 Slice 操作的 Step = 2, 应该是RKNN不支持导致的问题,,, 有谁知道怎么处理吗?
作者: theantbully    时间: 2021-9-10 10:14
自问自答,解决方案:
使用其他操作替代原来步长为2的切片操作,如下修改测试时可以的:
        pooled = self.maxpool2d(x) #[N, 4*C, W/2, H/2]
        reutrn self.conv( torch.cat([pooled, pooled, pooled, pooled], 1))
作者: rakidis    时间: 2021-9-21 21:22
You changed the layer's operation like that though. The shape will be the same, but slice and maxpool do different operations, your network will behave wrong after that modification.
作者: zjleung    时间: 2021-9-22 09:25
rakidis 发表于 2021-9-21 21:22
You changed the layer's operation like that though. The shape will be the same, but slice and maxpoo ...

absolutely agree
作者: theantbully    时间: 2021-9-28 18:44
rakidis 发表于 2021-9-21 21:22
You changed the layer's operation like that though. The shape will be the same, but slice and maxpoo ...

Thanks for you reply.
That's true. Then I replace maxpool with conv operation and retrain the model. The mAP seems not degrade too much.
Just provide a guide for sb. who might encounter similar issue.
作者: rakidis    时间: 2021-9-30 16:22
May I ask which neural network you were trying to convert spesifically? I bumped into similiar situation and managed to solve it with another method




欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3