关于 SNPE 平台上 onnx 模型转 dlc 模型

2020-05-15 16:19:17 +08:00
 MekoPan

在执行 snpe-onnx-to-dlc 命令时报错

AttributeError: op reduce_mean_0 has no attribute keepdims

原因好像是跟 keepdims 属性有关,对于 keepdims 这个属性我不太熟悉,于是我进行了以下处理:
old:

if input_buf.axis_format in format_to_permute_order:
   target_format = format_to_format[input_buf.axis_format]
   permute_order = format_to_permute_order[input_buf.axis_format]
   # If keep dims = 0 we must permute as it will remove dimensions
   if not node.op.keepdims:
   	AxisTracker.inject_implicit_permute(graph, input_name, target_format,
                    permute_order, [node.op.name])
	output_buf.axis_format = AxisTracker.AxisFormat.NONTRIVIAL
   else:
        AxisTracker.eltwise_to_spatial_first_order(node, graph)

new:

if input_buf.axis_format in format_to_permute_order:
   target_format = format_to_format[input_buf.axis_format]
   permute_order = format_to_permute_order[input_buf.axis_format]
   # If keep dims = 0 we must permute as it will remove dimensions
   if not hasattr(node.op, "keepdims"):
   	AxisTracker.inject_implicit_permute(graph, input_name, target_format,
                    permute_order, [node.op.name])
	output_buf.axis_format = AxisTracker.AxisFormat.NONTRIVIAL
   else:
        AxisTracker.eltwise_to_spatial_first_order(node, graph)
	

果不其然继续报错了,现在有点不知道怎么改了,网上也没相关信息。有没有熟悉这方面的老哥指点一二?

1449 次点击
所在节点    问与答
8 条回复
wutiantong
2020-05-15 17:03:36 +08:00
搞过一段时间 onnx,后来发现它代码质量真的不太行就弃坑了
MekoPan
2020-05-15 17:21:48 +08:00
@wutiantong 感觉 snpe 对 onnx 转 dlc 也是一堆坑,基本都需要在原基础上修改。心累的要死。
minami
2020-05-15 17:39:06 +08:00
不了解 SNPE,不过你可以检查下 keep_dims 属性
MekoPan
2020-05-15 18:03:55 +08:00
@minami 问题是 不知道为什么缺失 keep_dims 这个属性了
minami
2020-05-15 18:05:24 +08:00
@MekoPan #4 多半是 onnx 导出时的问题。keepdims 和 keep_dims 是两个名字
MekoPan
2020-05-15 18:10:12 +08:00
@minami 网上查`keepdims`是保持矩阵二维特性的意思,现在在研究什么情况下 keepdims 才会等于 0 。另外听你这么说感觉问题出现在 onnx 模型本身上
MekoPan
2020-05-15 18:12:03 +08:00
@minami 按照我上面修改完 keepdims 之后,又报这个错
```python
error_code=1004; error_message=Layer parameters combination is invalid. Layer fully_connected_0: mismatch between size of input 464 (7) and width of weight matrix (1280); error_component=Model Validation; line_no=1413; thread_id=139842232201088

```
快麻了
minami
2020-05-15 19:08:55 +08:00
@MekoPan #7 你搜的时候最好加上版本,你是 tensorflow 转 onnx 然后再转 dlc 吗? tensorflow 经历过 keep_dims 到 keepdims 的更名。你那样改肯定不对啊,我不懂 snpe 看注释也知道不对,你起码应该改成
if hasattr(node.op, "keepdims") and (not node.op.keepdims):

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/672075

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX