V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
MekoPan
V2EX  ›  问与答

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

  •  
  •   MekoPan · 2020-05-15 16:19:17 +08:00 · 1421 次点击
    这是一个创建于 1413 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在执行 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)
    	
    

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

    8 条回复    2020-05-15 19:08:55 +08:00
    wutiantong
        1
    wutiantong  
       2020-05-15 17:03:36 +08:00
    搞过一段时间 onnx,后来发现它代码质量真的不太行就弃坑了
    MekoPan
        2
    MekoPan  
    OP
       2020-05-15 17:21:48 +08:00
    @wutiantong 感觉 snpe 对 onnx 转 dlc 也是一堆坑,基本都需要在原基础上修改。心累的要死。
    minami
        3
    minami  
       2020-05-15 17:39:06 +08:00
    不了解 SNPE,不过你可以检查下 keep_dims 属性
    MekoPan
        4
    MekoPan  
    OP
       2020-05-15 18:03:55 +08:00
    @minami 问题是 不知道为什么缺失 keep_dims 这个属性了
    minami
        5
    minami  
       2020-05-15 18:05:24 +08:00
    @MekoPan #4 多半是 onnx 导出时的问题。keepdims 和 keep_dims 是两个名字
    MekoPan
        6
    MekoPan  
    OP
       2020-05-15 18:10:12 +08:00
    @minami 网上查`keepdims`是保持矩阵二维特性的意思,现在在研究什么情况下 keepdims 才会等于 0 。另外听你这么说感觉问题出现在 onnx 模型本身上
    MekoPan
        7
    MekoPan  
    OP
       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
        8
    minami  
       2020-05-15 19:08:55 +08:00   ❤️ 1
    @MekoPan #7 你搜的时候最好加上版本,你是 tensorflow 转 onnx 然后再转 dlc 吗? tensorflow 经历过 keep_dims 到 keepdims 的更名。你那样改肯定不对啊,我不懂 snpe 看注释也知道不对,你起码应该改成
    if hasattr(node.op, "keepdims") and (not node.op.keepdims):
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1001 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 19:59 · PVG 03:59 · LAX 12:59 · JFK 15:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.