Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pnnx] onnx的unsqueeze参数支持多个维度,torch的只能单个维度,pnnx转换onnx模型存在问题 #5660

Open
robvoid opened this issue Aug 29, 2024 · 0 comments

Comments

@robvoid
Copy link

robvoid commented Aug 29, 2024

error log | 日志或报错信息 | ログ

运行 python xxx_pnnx.py错误:
TypeError: unsqueeze(): argument 'dim' must be int, not tuple

运行 python xxx_ncnn.py不报错,但是输出tensor的shape错误

model | 模型 | モデル

  1. original model
    unsqueeze_error.sim.onnx.zip
import torch
import torch.nn as nn

class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(
            3,4,kernel_size=3,stride=4,
        )
        self.conv2 = nn.Conv2d(
            4,4,kernel_size=7,stride=4
        )
        self.bn = nn.BatchNorm2d(4)
        self.act = nn.ReLU()
        self.linear = nn.Linear(144,7)

    def forward(self,x):
        x = self.act(self.bn(self.conv1(x)))
        x = self.act(self.bn(self.conv2(x)))
        x = x.flatten(1)
        x = self.linear(x)
        x = torch.unsqueeze(x,-1)
        x = torch.unsqueeze(x,-1)
        return x

def main():
    model = Model()
    model.eval()
    x = torch.rand(1,3,112,112)
    
    torch.onnx.export(model, x, 'unsqueeze_error.onnx', verbose=True, opset_version=11,
            training=torch.onnx.TrainingMode.EVAL,
            do_constant_folding=True,
            input_names=["data"],
            output_names=["ouput"]
    )
    

if __name__ == '__main__':
    main()

onnxsim unsqueeze_error.onnx unsqueeze_error.sim.onnx

how to reproduce | 复现步骤 | 再現方法

  1. pnnx unsqueeze_error.sim.onnx inputshape=[1,3,112,112]
  2. 查看ncnn.param最后的ExpandDims,运行_pnnx.py
    预期输出shape [1, 7, 1, 1],ncnn输出shape [1, 1, 7]
@robvoid robvoid changed the title [pnnx] onnx的unsqueeze参数是axes支持多个维度,torch的只能单个维度,pnnx转出来的ncnn和pnnx都有一些问题 [pnnx] onnx的unsqueeze参数支持多个维度,torch的只能单个维度,pnnx转换onnx模型存在问题 Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant