Tengine icon indicating copy to clipboard operation
Tengine copied to clipboard

interp op attributes error when converting onnx resize op.

Open un-knight opened this issue 4 years ago • 1 comments

错误描述

将onnx resize op转换成tengine interp op之后tengine interp op attributes数值不正确。

待转换的onnx模型: image

转换后的tengine interp op attributes: image

可以发现转换后的tengine interp op的output_widthwidth_scale均出现错误。预期的output_width是20,而预期的width_scale是2。

环境

python == 3.8.12
pytorch == 1.10.0
tengine: https://github.com/OAID/Tengine/commit/91db3706e772568e022fcfcbef66d1998251988f

相关代码

resize 模型导出代码:

import torch
import torch.nn as nn

class MyModule(torch.nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.resize = nn.Upsample(scale_factor=2, mode='nearest')

    def forward(self, x):
        return self.resize(x)

model = MyModule()
torch.onnx.export(
                model,
                torch.randn((1, 3, 10, 10)),
                './toy.onnx',
                input_names=['input'],
                output_names=["output"],
                opset_version=10
            )

分析

经过debug发现在onnx2tengine的load_graph_nodeload_resize步骤中正确写入了height_scale与width_scale。 https://github.com/OAID/Tengine/blob/91db3706e772568e022fcfcbef66d1998251988f/tools/convert_tool/onnx/onnx2tengine.cpp#L2123-L2131

但是在后续的optimize_graph的interp infer_shape环节再次读取op.param_mem发现其中的width_scale数据就出现异常。

所以推测在load_graph_nodeoptimize_graph之间某些操作影响到了interp op param_mem中的width_scale数据。

un-knight avatar Dec 14 '21 10:12 un-knight

这不是tengine的bug,是netron的bug,https://github.com/lutzroeder/netron/issues/973 已经修了。

Gitkingly avatar Sep 28 '22 09:09 Gitkingly