Comments (13)
我也遇到resize转换出来一堆乱七八糟东西的情况,没搞定,于是就直接改ncnn模型了
https://zhuanlan.zhihu.com/p/93017149
from onnx-simplifier.
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.
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.
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.
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.
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.
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:
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.
What if to change this param of sizes
into type of anything else rather than initializer?
from onnx-simplifier.
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.
That doesn't help. the intializers were generated after simplified.
Sorry, I didn't understand you.
from onnx-simplifier.
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.
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.
nihui 大佬... 向大佬低头。
BTW, 我发现可以通过手动移花接木化解它,需要对ONNX做一些更加精细的外科手术
from onnx-simplifier.
@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)
- [BUG] after simplifing the model swin_tiny_patch4_window7_224 which was created by timm, onnxruntime got errors HOT 1
- [BUG] Message onnx.ModelProto exceeds maximum protobuf size of 2GB error from the latest version HOT 1
- [BUG] After simplification using onnxsim, the model size increased ten times HOT 2
- How to prohibit constant reuse HOT 1
- resnet18 and inception cannot use simplify method HOT 1
- How to prohibit constant reuse HOT 3
- 是否存在选项让simplify只做部分操作,比如只推理shape不做op优化
- Cannot remove shape of ch_PP-OCRv4_rec
- Consecutive squeeze unsqueeze layers could be simplified
- [BUG] unable to install onnxsim 0.4.34/0.4.35 from pypi HOT 5
- [Q&A] 请问可以支持 ConvTranspose + BatchNormalization 的融合吗? HOT 1
- 3 concatenations at the same time? [Request]
- [Request] "ConstantOfShape + Mul(B=0)" is not simplified HOT 1
- [BUG] Simplify removes local functions from the ONNX model HOT 1
- [BUG] onnx.onnx_cpp2py_export.checker.ValidationError: The model does not have an ir_version set properly.
- [BUG] onnx-simplifier==0.4.25 cannot do shape inference in some onnx HOT 3
- [BUG] Shape not supported yet! Tile not supported yet! HOT 1
- ERROR: Could not build wheels for onnxsim, which is required to install pyproject.toml-based projects[BUG]
- [Disscussion] Would mechanism like onnx "register_schema" be helpful in optimizing models with user-defined operators?
- [Request] Preserve input value_info for custom ops
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onnx-simplifier.