daquexian / onnx-simplifier

Simplify your onnx model
Apache License 2.0
3.79k stars 380 forks source link

[BUG] Shape not supported yet! Tile not supported yet! #323

Open minushuang opened 7 months ago

minushuang commented 7 months ago

Describe the bug I trained an ocr model with paddlepaddle-2.6, and export the model to onnx, then I convert the original onnx model to ncnn, it reported error:

Shape not supported yet!
Tile not supported yet!
Shape not supported yet!
Tile not supported yet!

so, i try to use the python3 -m onnx2sim src.onnx sim.onnx to simplifier the onnx model, and it shows as below,

Your model contains "Tile" ops or/and "ConstantOfShape" ops. Folding these ops can make the simplified model much larger. If it is not expected, please specify "--no-large-tensor"(which will lose some optimization chances)

Finish! Here is the difference:
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃                    ┃ Original Model ┃ Simplified Model ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ Add                │ 26             │ 26               │
│ BatchNormalization │ 35             │ 0                │
│ Clip               │ 18             │ 18               │
│ Concat             │ 20             │ 1                │
│ Constant           │ 397            │ 124              │
│ Conv               │ 53             │ 53               │
│ Div                │ 18             │ 18               │
│ GlobalAveragePool  │ 9              │ 9                │
│ HardSigmoid        │ 9              │ 9                │
│ LSTM               │ 2              │ 2                │
│ MatMul             │ 1              │ 1                │
│ MaxPool            │ 1              │ 1                │
│ Mul                │ 27             │ 27               │
│ Relu               │ 15             │ 15               │
│ Reshape            │ 2              │ 2                │
│ Shape              │ 2              │ 1                │
│ Slice              │ 30             │ 3                │
│ Softmax            │ 1              │ 1                │
│ Squeeze            │ 1              │ 1                │
│ Tile               │ 2              │ 1                │
│ Transpose          │ 7              │ 6                │
│ Model Size         │ 1.8MiB         │ 1.7MiB           │
└────────────────────┴────────────────┴──────────────────┘

the table show that the shape ops from 2 to 1, the tile ops from 2 to 1, not we expect the 0. and the convert error is not eliminated when convert the simplified onnx model to ncnn with onnx2ncnn tool.

Model https://drive.google.com/file/d/1ixsUIE3rwwUzmldavvZHr5TxtmBKg94r/view?usp=sharing

minushuang commented 7 months ago

the input is dynamic with dynamic_batch x 3 x 32 x dynamic