1 * 1卷积核转模型之后位置与源模型不一致,输入有所改变

用户您好,请详细描述您所遇到的问题。

1.硬件获取渠道:

2.当前系统镜像版本:1.1.21i_en

3.当前天工开物版本:

2022-08-03 17:43:40,099 INFO ########################################

2022-08-03 17:43:40,099 INFO ----------- dependency info ------------

2022-08-03 17:43:40,100 INFO hb mapper version: 1.1.58

2022-08-03 17:43:40,100 INFO hbdk version: 3.16.6

2022-08-03 17:43:40,100 INFO hbdk runtime version: 3.10.8

2022-08-03 17:43:40,100 INFO horizon_nn version: 0.9.7

2022-08-03 17:43:40,101 INFO -------- model parameters info ---------

4.问题定位:运行时报错,node[model_1/model/channel_padding/Pad] input size:2 is not equal to according op[model_1/model/channel_padding/Pad] input size,结合转换前后模型差异,定位问题所在:

5.开发的demo/案例:

6.需要提供的解决方案:处理该问题

WX20220808-171550@2x_20220808171813.png

您好,建议更新编译环境至最新版本看看是否为已修复的问题。

OE发布包:-
wget -c ftp://vrftp.horizon.ai/Open\_Explorer/1.14.3/horizon\_xj3\_open\_explorer\_v1.14.3\_20220727.tar.gz-

文档:-
wget -c ftp://vrftp.horizon.ai/Open\_Explorer/1.14.3/horizon\_xj3\_open\_explorer\_v1.14.3\_doc.zip-

Docker:-
wget -c ftp://vrftp.horizon.ai/Open\_Explorer/1.14.3/docker\_openexplorer\_centos\_7\_xj3\_v1.14.3.tar.gz

或者直接在线拉取docker:docker pull openexplorer/ai_toolchain_centos_7_xj3:v1.14.3

用了新版本,在checker的时候报错,报错信息如下:

2022-08-09 18:55:35,191 INFO [Tue Aug 9 18:55:35 2022] Start to calibrate the model.

2022-08-09 18:55:35,192 INFO There are 1 samples in the calibration data set.

2022-08-09 18:55:35,258 INFO Run calibration model with max method.

2022-08-09 18:55:35,506 INFO [Tue Aug 9 18:55:35 2022] End to calibrate the model.

2022-08-09 18:55:35,506 INFO [Tue Aug 9 18:55:35 2022] Start to quantize the model.

2022-08-09 18:55:35,598 ERROR There is an error in pass:quantize_pad. Error message:/home/jenkins/workspace/model_convert/onnx/onnx/common/ir.h:252: find: Assertion `!required || it != values_.end()` failed: /home/jenkins/workspace/model_convert/onnx/onnx/common/ir.h:252: find: required undefined attribute ‘pads’

2022-08-09 18:55:35,599 INFO [Tue Aug 9 18:55:35 2022] End to quantize the model.

2022-08-09 18:55:35,599 INFO [Tue Aug 9 18:55:35 2022] End to Horizon NN Model Convert.

请问是算子不支持吗?

现在看起来新版本不支持channel padiing,旧版本转模型会对网络结构做一些改变

您好,我们支持H、W维度的pad,不支持channel维度的pad。

但是,我在之前旧版本的转模型工具链,是可以正常处理的,只是转模型后的算子发生了改变。在新的工具链我用concat代替了channel padding,替代后的onnx模型是可以本地跑的,但是在转模型的时候报这个错误,能帮忙看下什么问题吗?

2022-08-11 18:23:53,953 INFO Model input names: [‘input_1’]

2022-08-11 18:23:53,953 INFO Create a preprocessing operator for input_name input_1 with means=[128.], std=[128.], original_input_layout=NCHW, color convert from ‘RGB’ to ‘BGR’.

2022-08-11 18:23:53,974 INFO Saving the original float model: mediapipep_hand_original_float_model.onnx.

2022-08-11 18:23:53,975 INFO [Thu Aug 11 18:23:53 2022] Start to optimize the model.

2022-08-11 18:23:54,179 INFO [Thu Aug 11 18:23:54 2022] End to optimize the model.

2022-08-11 18:23:54,186 INFO Saving the optimized model: mediapipep_hand_optimized_float_model.onnx.

2022-08-11 18:23:54,186 INFO [Thu Aug 11 18:23:54 2022] Start to calibrate the model.

2022-08-11 18:23:54,188 INFO There are 100 samples in the calibration data set.

2022-08-11 18:23:54,222 INFO Run calibration model with default calibration method.

2022-08-11 18:23:55.205554198 [E:onnxruntime:, sequential_executor.cc:183 Execute] Non-zero status code returned while running Concat node. Name:‘onnx_graphsurgeon_node_0’ Status Message: Not satisfied: dim_value == inputs_0_dims[axis_index]

concat.cc:79 PrepareForComputeNon concat axis dimensions must match: Axis 0 has mismatched dimensions of 1 and 8

2022-08-11 18:23:55,206 INFO Reset batch_size=1 and execute calibration again..

你好,从报错信息看,concat维度是Axis 0,也就是batch维度,而不是期望的channel维度,您在模型转换期间应该会生成一个xxx_original_float_model.onnx,用netron可视化一下,麻烦您提供一下截图哈,辅助我们进一步分析问题。

我在concat的时候,为实现channel padding,做了如下处理

这里是batchsize为1,转模型的时候报了上面的问题,然后我在yaml.config文件中配置了batchsize为1,如图

校准图片100张,转模型时的报错信息为:

模型截图为:

另外还有一个疑问,为什么我最开始的工具链版本,channel_padding是支持的?

最开始支持的工具链版本,quantized_model.onnx模型的截图为:

由图得,最初始的工具链版本,是通过transpose,padding,transpose三个过程实现了channel_padding算子,但是就是1 * 1的conv位置出现了偏移。

想转的onnx模型截图为:

相关信息都在这里了,麻烦帮忙看一下,谢谢了哈

原来不支持推测也是因为C维度padding的原因,老版本pad是跑在cpu上的。

您这个concat的模型方便提供吗?

我们搭建了一个类似的子结构,未能复现您的问题:

可以啊,我发原始模型给你可以吗,怎么发给你呢

可以的,可以加:Horizon_robot,发给我们。

该问题可以忽略,不影响模型转换结果哈