Code Monkey home page Code Monkey logo

Comments (13)

nihui avatar nihui commented on May 20, 2024 1

我也遇到resize转换出来一堆乱七八糟东西的情况,没搞定,于是就直接改ncnn模型了

https://zhuanlan.zhihu.com/p/93017149

from onnx-simplifier.

lucasjinreal avatar lucasjinreal commented on May 20, 2024

this can call python3 -m onnxsim to reproduce by:

class TinyModel(nn.Module):
    def __init__(self):
        super(TinyModel, self).__init__()
        self.expander = nn.Conv2d(3, 192, 1, 1)

        # upsample cause Gather error
        self.P4_upsampled = nn.Upsample(scale_factor=2, mode='nearest')

    def forward(self, x):
        x = self.expander(x)
        # a = self.P4_upsampled(x)  

        sh = torch.tensor(x.shape[-2:])
        print(sh)
        a = F.interpolate(x, (sh[0]*2, sh[1]*2))
        return a
        

def export_onnx():
    model = TinyModel().to(device)
    sample_input = torch.rand(1, 3, 544, 1920).to(device)
    model.eval()
    torch.onnx.export(model, sample_input, model_p, input_names=[
                      'img'], output_names=['values'], opset_version=11)
    print('onnx model exported. forward now...')
    # forward now


if __name__ == "__main__":
    export_onnx()

from onnx-simplifier.

daquexian avatar daquexian commented on May 20, 2024

I think it is a bug of onnx (onnx/onnx#2417) and not related to onnxsim itself. Please re-export your onnx model according to what onnx/onnx#1385 (comment) suggests

from onnx-simplifier.

lucasjinreal avatar lucasjinreal commented on May 20, 2024

thanks for reply, better to say, this is a pytorch exporting bug. I have posted an optimization issue in pytorch.

However, do u have any suggestions on the simplifier result of such situation?

Why it does failed when convert? (actually I think the simplify process is right and reasonable) Just can not convert to tensorrt

from onnx-simplifier.

daquexian avatar daquexian commented on May 20, 2024

thanks for reply, better to say, this is a pytorch exporting bug. I have posted an optimization issue in pytorch.

No, it's an onnx bug, please check out onnx/onnx#2198

from onnx-simplifier.

daquexian avatar daquexian commented on May 20, 2024

Why it does failed when convert? (actually I think the simplify process is right and reasonable) Just can not convert to tensorrt

Have you tried re-export your onnx model by adding keep_initializers_as_inputs=True?

from onnx-simplifier.

lucasjinreal avatar lucasjinreal commented on May 20, 2024

That doesn't help. the intializers were generated after simplified.

What I am concern is that, this is a common issue, if you call upsample, intepolate, resize etc operation in your model, you will get a graph which is complicated:

image

But actually, we only might need a single resize op with a sizes params, however, this is current can not be done, and I don't know the root reason for this.

image

What if to change this param of sizes into type of anything else rather than initializer?

from onnx-simplifier.

lucasjinreal avatar lucasjinreal commented on May 20, 2024

The initializer might be the root reason. this can be solve on pytorch side, onnx side, or onnxsimplifier side, or even onnx-tensorrt side.

But none of them do this.....

from onnx-simplifier.

daquexian avatar daquexian commented on May 20, 2024

That doesn't help. the intializers were generated after simplified.

Sorry, I didn't understand you.

from onnx-simplifier.

lucasjinreal avatar lucasjinreal commented on May 20, 2024

Sorry

Have you tried re-export your onnx model by adding keep_initializers_as_inputs=True?

this advise is not help.it's the same, and not the root reason for problem. Anyway, not related to onnxsimplifier. Since onnxsimpifier is just wrapper of onnx

from onnx-simplifier.

daquexian avatar daquexian commented on May 20, 2024

But actually, we only might need a single resize op with a sizes params, however, this is current can not be done

If you are asking about the roi<?> and scales<?> in the screenshot, onnx/onnx#2451 contains more information.

from onnx-simplifier.

lucasjinreal avatar lucasjinreal commented on May 20, 2024

nihui 大佬... 向大佬低头。

BTW, 我发现可以通过手动移花接木化解它,需要对ONNX做一些更加精细的外科手术

from onnx-simplifier.

luoduo21 avatar luoduo21 commented on May 20, 2024

@nihui 大佬,按照你的意思pytorch中x=F.interpolate(input=x,size=(self.up_size, self.up_size), mode='bilinear') 导出onnx再转ncnn单独修改ncnn模型就行了吗,我使用op9可以导出来的是upsample op,我想问的是直接将这个转ncnn再修改ncnn模型,输出结果会一致吗!

from onnx-simplifier.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.