Giter VIP home page Giter VIP logo

onnx-simplifier's Introduction

ONNX Simplifier

PyPI version PyPI pyversions PyPI license PRs Welcome

ONNX is great, but sometimes too complicated.

Background

One day I wanted to export the following simple reshape operation to ONNX:

import torch


class JustReshape(torch.nn.Module):
    def __init__(self):
        super(JustReshape, self).__init__()

    def forward(self, x):
        return x.view((x.shape[0], x.shape[1], x.shape[3], x.shape[2]))


net = JustReshape()
model_name = 'just_reshape.onnx'
dummy_input = torch.randn(2, 3, 4, 5)
torch.onnx.export(net, dummy_input, model_name, input_names=['input'], output_names=['output'])

The input shape in this model is static, so what I expected is

simple_reshape

However, I got the following complicated model instead:

complicated_reshape

Our solution

ONNX Simplifier is presented to simplify the ONNX model. It infers the whole computation graph and then replaces the redundant operators with their constant outputs (a.k.a. constant folding).

Web version

We have published ONNX Simplifier on convertmodel.com. It works out of the box and doesn't need any installation. Note that it runs in the browser locally and your model is completely safe.

Python version

pip3 install -U pip && pip3 install onnxsim

Then

onnxsim input_onnx_model output_onnx_model

For more advanced features, try the following command for help message

onnxsim -h

Demonstration

An overall comparison between a complicated model and its simplified version:

Comparison between old model and new model

In-script workflow

If you would like to embed ONNX simplifier python package in another script, it is just that simple.

import onnx
from onnxsim import simplify

# load your predefined ONNX model
model = onnx.load(filename)

# convert model
model_simp, check = simplify(model)

assert check, "Simplified ONNX model could not be validated"

# use model_simp as a standard ONNX model object

You can see more details of the API in onnxsim/onnx_simplifier.py

Projects Using ONNX Simplifier

Chat

We created a Chinese QQ group for ONNX!

ONNX QQ Group (Chinese): 1021964010, verification code: nndab. Welcome to join!

For English users, I'm active on the ONNX Slack. You can find and chat with me (daquexian) there.

onnx-simplifier's People

Contributors

alwaysssssss avatar arnaudbrejeon avatar brian14708 avatar cristifati avatar daquexian avatar geekadalovelace avatar haoyzhong avatar tangjicheng46 avatar tangyanf avatar wheest avatar xyzhao1999 avatar zengqingfu1442 avatar zhiqwang avatar zylo117 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

onnx-simplifier's Issues

[BUG] Run onnx-simplifier by onnxruntime-gpu

Hi all,
I can run the onnx-simplifier by onnxruntime cpu version without any issue.
However, when I run by onnxruntime gpu version, it got stuck.

Command:

python3 -m onnxsim ./model.onnx ./model_simplifier.onnx  

Output:

Simplifying...
2020-03-26 10:49:43.826186091 [E:onnxruntime:, sequential_executor.cc:183 Execute] Non-zero status code returned while running Add node. Name:'' Status Message: /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:97 bool onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*) [with ERRTYPE = cudaError; bool THRW = true] /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:91 bool onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*) [with ERRTYPE = cudaError; bool THRW = true] CUDA failure 2: out of memory ; GPU=0 ; hostname=chieh-Z97X-UD3H ; expr=cudaMalloc((void**)&p, size); 
Stacktrace:

Stacktrace:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/dist-packages/onnx_simplifier-0.0.0-py3.6.egg/onnxsim/__main__.py", line 42, in <module>
  File "/usr/local/lib/python3.6/dist-packages/onnx_simplifier-0.0.0-py3.6.egg/onnxsim/__main__.py", line 31, in main
  File "/usr/local/lib/python3.6/dist-packages/onnx_simplifier-0.0.0-py3.6.egg/onnxsim/onnx_simplifier.py", line 303, in simplify
  File "/usr/local/lib/python3.6/dist-packages/onnx_simplifier-0.0.0-py3.6.egg/onnxsim/onnx_simplifier.py", line 158, in forward_all
  File "/usr/local/lib/python3.6/dist-packages/onnx_simplifier-0.0.0-py3.6.egg/onnxsim/onnx_simplifier.py", line 149, in forward
  File "/home/chieh/.local/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 142, in run
    return self._sess.run(output_names, input_feed, run_options)
onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Add node. Name:'' Status Message: /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:97 bool onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*) [with ERRTYPE = cudaError; bool THRW = true] /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:91 bool onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*) [with ERRTYPE = cudaError; bool THRW = true] CUDA failure 2: out of memory ; GPU=0 ; hostname=chieh-Z97X-UD3H ; expr=cudaMalloc((void**)&p, size); 
Stacktrace:

Stacktrace:

I try to install both versions (cpu and gpu) in the same time, but my onnxruntime-gpu cannot be used after I install the cpu version.
I need to use onnxruntime by gpu, so I have to uninstall cpu version.
Is there any method to assign running cpu by onnxruntime-gpu? Or how can I solve this issue?

Thank you.

System information

  • OS Platform and Distribution : Linux Ubuntu 18.04)
  • ONNX Runtime installed from (source or binary): install by pip
  • ONNX Runtime GPU version: 1.1.2
  • Python version: 3.6.9
  • CUDA/cuDNN version: 10.0 / 7.6.5
  • GPU model and memory: GTX 1060 / 6G

ONNXRuntimeError

Hello,

I tried to convert my model but got error

onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Squeeze node. Name:'' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/squeeze.h:47 static std::vector<long int> onnxruntime::SqueezeBase::ComputeOutputShape(const onnxruntime::TensorShape&, const onnxruntime::TensorShape&) input_shape[i] == 1 was false. Dimension of input 0 must be 1 instead of 2. shape={2,20,128}
Stacktrace:

I just follow your README to install onnx-simplifier, so the version of onnxruntime version shows 1.0.0 and version of onnx-simplifier is 0.2.2.

If I comment out https://github.com/daquexian/onnx-simplifier/blob/master/onnxsim/onnx_simplifier.py#L257 and https://github.com/daquexian/onnx-simplifier/blob/master/onnxsim/onnx_simplifier.py#L258. The error becomes

  File "/PATH.../onnxruntime/capi/session.py", line 37, in _load_model
    self._sess.read_bytes(self._path_or_bytes, providers)
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : [ShapeInferenceError] Dimension of input 0 must be 1 instead of 2

How can I get rid of this error? Thank you.

onnx-simplify ssd model failed

I generated onnx ssd model from here, according to the tutorial.
https://github.com/onnx/tensorflow-onnx/blob/master/tutorials/ConvertingSSDMobilenetToONNX.ipynb
Then I run the simplify procedure, and the error is as follows:

Simplifying...
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/xiao/.local/lib/python3.7/site-packages/onnxsim/main.py", line 24, in
main()
File "/home/xiao/.local/lib/python3.7/site-packages/onnxsim/main.py", line 17, in main
model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
File "/home/xiao/.local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 193, in simplify
model_opt = optimize(model_opt)
File "/home/xiao/.local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 155, in optimize
fixed_point=True)
File "/home/xiao/.local/lib/python3.7/site-packages/onnx/optimizer.py", line 53, in optimize
optimized_model_str = C.optimize_fixedpoint(model_str, passes)
IndexError: _Map_base::at

I want to know what is the error.

Output mismatch between pytorch and onnx

Hi,

I converted pytorch (.pt) model to onnx using torch.onnx.export, during inference first four values which is bbox values are different and rest looks same.
I converted using,
self.model.cuda().eval()
dummy_input = torch.rand(1, 3,416, 416).cuda()
torch.onnx.export(self.model, dummy_input, "trk.onnx", export_params=True, verbose=True)

converted using onnx-simplifier
python3 -m onnxsim input_model output_model

and ran it using
model = onnxruntime.InferenceSession("trk.onnx")
input_name = sess.get_inputs()[0].name
label_name = sess.get_outputs()[0].name
pred = sess.run(None, {input_name: im_blob})

Actual output (onnx):
pred11 = [[[ 0.0429871 0.10708108 -0.15831867 ... -0.05099011 0.04215946 0.03529864]

[ 0.15205492 0.14381851 -0.4134867 ... -0.02547888 0.02003362 0.05678646]
[ 0.11788099 0.21649244 -0.49855745 ... -0.03875189 -0.00112192 0.05244121]
...
[-0.02988242 -0.02718411 0.17555043 ... -0.05482839 -0.03526874 -0.01705099]
[-0.02175785 -0.01682113 0.20047602 ... -0.04242673 0.00226362 0.00717632]
[-0.01177015 -0.02307639 0.05427436 ... -0.03097095 0.00717672 0.00656337]]] 218 float32

Expected output (.pt):
pred22 = [[[ 4.3859973e+00 3.2662495e+01 8.7064598e+01 ... -5.0997593e-02 4.2160533e-02 3.5292290e-02]
[ 4.7508678e+01 4.3868427e+01 6.7454163e+01 ... -2.5484795e-02 2.0031789e-02 5.6778252e-02]
[ 7.6021790e+01 6.6031555e+01 6.1953438e+01 ... -3.8754154e-02 -1.1225204e-03 5.2439131e-02]
...
[ 3.9146216e+02 4.0653235e+02 2.1454182e+01 ... -5.4829646e-02 -3.5270575e-02 -1.7050508e-02]
[ 3.9960834e+02 4.0709204e+02 2.1995722e+01 ... -4.2428117e-02 2.2626489e-03 7.1746223e-03]
[ 4.0778818e+02 4.0675439e+02 1.9004044e+01 ... -3.0972414e-02 7.1776402e-03 6.5612365e-03]]] 218 float32

model (pytorch model)

Environment
PyTorch Version (e.g., 1.0): 1.4.0
OS (e.g., Linux): ubuntu 18.04 LTS
How you installed PyTorch (conda, pip, source): pip
Python version: 3.60.2.2
CUDA/cuDNN version:10.0/7.6
GPU models and configuration: gtx - 1080 -8GB
onnx version - 1.6.0
onnxsim.version - 0.2.2

[ONNXRuntimeError] : 1 : FAIL : Node () Op (Concat) [ShapeInferenceError] rank must be greater than axis

Hi, thanks for your simplifier.
I've met an error like this when I run command python3 -m onnxsim model.onnx model_slim.onnx
Simplifying...

Traceback (most recent call last):
File "/home/tangym/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/tangym/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/tangym/anaconda3/lib/python3.6/site-packages/onnxsim/main.py", line 42, in
main()
File "/home/tangym/anaconda3/lib/python3.6/site-packages/onnxsim/main.py", line 31, in main
args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization, input_shapes=input_shapes)
File "/home/tangym/anaconda3/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 303, in simplify
res = forward_all(model, input_shapes=input_shapes)
File "/home/tangym/anaconda3/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 158, in forward_all
res = forward(model, input_shapes=input_shapes)
File "/home/tangym/anaconda3/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 143, in forward
sess = rt.InferenceSession(model.SerializeToString(), sess_options=sess_options)
File "/home/tangym/anaconda3/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 25, in init
self._load_model(providers)
File "/home/tangym/anaconda3/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 43, in _load_model
self._sess.load_model(providers)
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Node () Op (Concat) [ShapeInferenceError] rank must be greater than axis

I am actually transform my object detection model in pytorch into onnx. Here's some useful information (hope so). I am sure that my origin pytorch model has no error in concat operation (as described in the error message above)
Here is how I transform. I use command below in python script.
torch.onnx.export(model, dummy_input, "alexnet.onnx", verbose=True, input_names=input_names, output_names=output_names)

RuntimeError: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Exception during initialization: /onnxruntime_src/onnxruntime/core/providers/cpu/nn/batch_norm.h:39 onnxruntime::BatchNorm<T>::BatchNorm(const onnxruntime::OpKernelInfo&) [with T = float] spatial == 1 was false. BatchNormalization kernel for CPU provider does not support non-spatial cases Stacktrace:

mxnet resnet50 to onnx
then simplifier the onnx model, have this error,
I dont know why ,could you some suggests?
could you have some message to learn principles?

RuntimeError: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Exception during initialization: /onnxruntime_src/onnxruntime/core/providers/cpu/nn/batch_norm.h:39 onnxruntime::BatchNorm::BatchNorm(const onnxruntime::OpKernelInfo&) [with T = float] spatial == 1 was false. BatchNormalization kernel for CPU provider does not support non-spatial cases Stacktrace:

Not all data was converted

Hi, I want to transfer onnx model to tensorrt model, but in the original generated onnx model, there are gather operation which is not supported. So I try to use onnx-simplifier to generate the corresponding onnx model, but there is an error:

Not all data was converted
google.protobuf.message.DecodeError: Protobuf decoding consumed too few bytes: 5 out of 50190117

It seems that if I use original onnx that I will get gather operation and if I use onnx-simplifier that I can't convert all data. Do you have any advice?

SegFault using Onnxsim embedded in a script

I am looking at embedded Onnx sim in a script, rather than using the command line approach described in the README.

However, in this small script I have made, following the same code as onnxsim/main.py, but fails with a Segmentation fault.

It is successful when running python3 -m onnxsim inception_v3.onnx inception_v3_opt.onnx.

You can see the script here.

Any idea why there would be a segfault when using Onnxsim in this way?

ONNXRuntimeError

when I run python3 -m onnxsim mobile_facenet.onnx mobile_facenet_sim.onnx, a error occurred

RuntimeError: Method run failed due to: [ONNXRuntimeError] : 1 : GENERAL ERROR : /Users/vsts/agent/2.155.1/work/1/s/onnxruntime/core/providers/cpu/math/element_wise_ops.h:324 void onnxruntime::BroadcastIterator::Init(int64_t, int64_t) axis == 1 || axis == largest was false. Attempting to broadcast an axis by a dimension other than 1. 56 by 64
Stacktrace:

How can I solve this problem?

[pytorch to onnx run in tengine error] :Tengine-master/core/lib/graph_executor.cpp:357 infer shape failed on node: 454 due to input: 453 size is zero

Describe the bug
The bug is :
/home/ff/Tengine-master/core/lib/graph_executor.cpp:357 infer shape failed on node: 454 due to input: 453 size is zero

I trained my model with Pytorch and then transfered to onnx,using Ubuntu16.04.
When I use Tengine to run my model, bug appeared,like following:
These 3op are not supported
{shape, Gather, Unsqueeze}

Then I try onnx_simplifier,here is the new bug:
/home/ff/Tengine-master/core/lib/graph_executor.cpp:357 infer shape failed on node: 454 due to input: 453 size is zero

I don't know how to solve this problem~

[BUG]

Describe the bug
Checking 0/3...
Tensor scores changes after simplifying. The max diff is 0.37125229835510254.
Note that the checking is not always correct.
After simplifying:
[[[9.3386704e-01 2.9077111e-03 2.2453293e-03 ... 1.6835716e-03
1.1354900e-03 1.8100661e-03]
[9.4730669e-01 1.0944547e-03 1.0280557e-03 ... 2.2252749e-03
3.2085853e-03 3.3723232e-03]
[9.1126448e-01 4.0056766e-03 2.4932963e-03 ... 5.8777770e-04
2.2106536e-03 1.0412371e-03]
...
[2.5697947e-01 3.6060717e-02 2.1950582e-03 ... 9.7272865e-02
2.8366329e-02 8.7439425e-02]
[2.8084219e-01 2.3728541e-01 3.0571911e-02 ... 7.2766706e-02
1.6120823e-02 6.8334460e-02]
[1.5737572e-01 1.9133696e-03 9.7480938e-03 ... 7.4628435e-02
6.2059723e-03 3.0124951e-02]]]
Before simplifying:
[[[0.86023927 0.00735333 0.00441171 ... 0.00390399 0.00354641 0.00487716]
[0.89039016 0.00274161 0.00309724 ... 0.00576726 0.00513357 0.00982196]
[0.8634894 0.00552442 0.00474672 ... 0.00136774 0.00317875 0.00178858]
...
[0.5530022 0.02890183 0.00509811 ... 0.03678409 0.03503098 0.03874877]
[0.54851794 0.07100447 0.02439926 ... 0.03236982 0.02336247 0.02174926]
[0.508326 0.00574843 0.01278591 ... 0.0319036 0.01349589 0.02038678]]]

Check failed, please be careful to use the simplified model.

Model
已发邮箱

tuple indices must be integers or slices, not NoneType

Hi @daquexian!
I met this problem, "tuple indices must be integers or slices, not NoneType". Can you give me some advices ?
Thank you so much !

D:\tools\pytorch2onnx>python -m onnxsim srnn.onnx srnn-sim.onnx D:\3rdparty\Anaconda3\envs\torch1.2\lib\site-packages\onnxruntime\capi\onnxruntime_validation.py:29: UserWarning: Unsupported Windows version (7). ONNX Runtime supports Windows 10 and above, only .warnings.warn('Unsupported Windows version (%s). ONNX Runtime supports Windows 10 and above, only.' % __my_distro_ver__) Simplifying... Traceback (most recent call last): File "D:\3rdparty\Anaconda3\envs\torch1.2\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "D:\3rdparty\Anaconda3\envs\torch1.2\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "D:\3rdparty\Anaconda3\envs\torch1.2\lib\site-packages\onnxsim\__main__.py", line 24, in <module> main() File "D:\3rdparty\Anaconda3\envs\torch1.2\lib\site-packages\onnxsim\__main__.py", line 17, in main model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization) File "D:\3rdparty\Anaconda3\envs\torch1.2\lib\site-packages\onnxsim\onnx_simplifier.py", line 202, in simplify model_opt = eliminate_const_nodes(model_opt, const_nodes, res) File "D:\3rdparty\Anaconda3\envs\torch1.2\lib\site-packages\onnxsim\onnx_simplifier.py", line 131, in eliminate_const_nodes vals=np.array(res[node.output[0]]).flatten().astype(get_np_type_from_elem_type(elem_type)) File "D:\3rdparty\Anaconda3\envs\torch1.2\lib\site-packages\onnxsim\onnx_simplifier.py", line 67, in get_np_type_from_elem_type size = sizes[elem_type] TypeError: tuple indices must be integers or slices, not NoneType

[BUG] Sim failed

I wanna simplify my onnx model, but I got this error message:

onnx.onnx_cpp2py_export.checker.ValidationError: Graph must be in single static assignment (SSA) form, however '592' has been used as output names multiple times.

I have send my model to [email protected].

[BUG] Resize simplifier behavior should be change

Now the model simplified like this:

image

But, we need convert to tensorrt, and when convert to trt, we gots:

----------------------------------------------------------------
Input filename:   model_upsample_sim.onnx
ONNX IR version:  0.0.4
Opset version:    11
Producer name:    pytorch
Producer version: 1.3
Domain:           
Model version:    0
Doc string:       
----------------------------------------------------------------
Parsing model


onnx-tensorrt/ModelImporter.cpp:98 In function importInputs:
[8] Assertion failed: convert_onnx_weights(initializer, &weights)

ValidationError: Your model ir_version is higher than the checker's.

Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.6/dist-packages/onnxsim/main.py", line 18, in
main()
File "/usr/local/lib/python3.6/dist-packages/onnxsim/main.py", line 12, in main
model_opt = onnxsim.simplify(args.input_model)
File "/usr/local/lib/python3.6/dist-packages/onnxsim/onnx_simplifier.py", line 179, in simplify
model_opt = eliminate_const_nodes(model_ori, get_constant_nodes(model_ori), forward_all(model_ori))
File "/usr/local/lib/python3.6/dist-packages/onnxsim/onnx_simplifier.py", line 103, in forward_all
model = onnx.utils.polish_model(model)
File "/usr/local/lib/python3.6/dist-packages/onnx/utils.py", line 18, in polish_model
onnx.checker.check_model(model)
File "/usr/local/lib/python3.6/dist-packages/onnx/checker.py", line 82, in check_model
C.check_model(model.SerializeToString())
onnx.onnx_cpp2py_export.checker.ValidationError: Your model ir_version is higher than the checker's.

KeyError: '73'

I get the following error on my model:
Simplifying...
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.7/site-packages/onnxsim/main.py", line 24, in
main()
File "/usr/local/lib/python3.7/site-packages/onnxsim/main.py", line 17, in main
model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
File "/usr/local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 187, in simplify
model_opt = eliminate_const_nodes(model_opt, get_constant_nodes(model_opt), forward_all(model_opt))
File "/usr/local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 122, in eliminate_const_nodes
shape = res[node.output[0]].shape
KeyError: '73'

upsample output size missing?

Hi, @daquexian Thanks for the greate project. It helps to solve a problem in my recent work.

However, I noticed one function was cancelled in a more recent commit. I was updating a model with upsample layer. Its output size was computed and recorded in the graph in your last commit. Today I sychnoized your code, and found the output size was on longer computed.
Screenshot from 2019-05-31 15-57-45

Was there any reason for not computing the output size dynamically?

RuntimeError: Method run failed due to: [ONNXRuntimeError]

python3 -m onnxsim ~/code/tensorflow-onnx/tf_model/vgg16/vgg16.onnx ~/code/tensorflow-onnx/tf_model/vgg16/vgg16_sim.onnx
Simplifying...
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message. If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 553438759
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message. If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 553438717
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message. If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 553440831
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message. If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 553440837
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message. If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 553440837
2019-05-15 16:42:00.053336347 [W:onnxruntime:Default, bfc_arena.cc:201 AllocateRawInternal] tried to allocate 0 bytes
2019-05-15 16:42:00.053393721 [W:onnxruntime:Default, bfc_arena.cc:201 AllocateRawInternal] tried to allocate 0 bytes
2019-05-15 16:42:00.053407540 [W:onnxruntime:Default, bfc_arena.cc:201 AllocateRawInternal] tried to allocate 0 bytes
2019-05-15 16:42:00.053416950 [W:onnxruntime:Default, bfc_arena.cc:201 AllocateRawInternal] tried to allocate 0 bytes
2019-05-15 16:42:00.053424564 [W:onnxruntime:Default, bfc_arena.cc:201 AllocateRawInternal] tried to allocate 0 bytes
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/cxjin/.local/lib/python3.6/site-packages/onnxsim/main.py", line 22, in
main()
File "/home/cxjin/.local/lib/python3.6/site-packages/onnxsim/main.py", line 15, in main
model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n)
File "/home/cxjin/.local/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 182, in simplify
model_opt = eliminate_const_nodes(model_opt, get_constant_nodes(model_opt), forward_all(model_opt))
File "/home/cxjin/.local/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 105, in forward_all
res = forward(model)
File "/home/cxjin/.local/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 97, in forward
res = OrderedDict(zip(outputs, sess.run(outputs, inputs)))
File "/home/cxjin/.local/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 72, in run
return self._sess.run(output_names, input_feed, run_options)
RuntimeError: Method run failed due to: [ONNXRuntimeError] : 1 : GENERAL ERROR : /onnxruntime_src/onnxruntime/core/providers/cpu/nn/pool_base.h:163 std::vector onnxruntime::PoolBase::SetOutputSize(const onnxruntime::TensorShape&, int64_t, std::vector*, const std::vector&, int64_t) const input_shape.Size() > 0 was false.
Stacktrace:

TypeError: 0 has type numpy.int64, but expected one of: int

Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.6/dist-packages/onnxsim/main.py", line 18, in
main()
File "/usr/local/lib/python3.6/dist-packages/onnxsim/main.py", line 12, in main
model_opt = onnxsim.simplify(args.input_model)
File "/usr/local/lib/python3.6/dist-packages/onnxsim/onnx_simplifier.py", line 179, in simplify
model_opt = eliminate_const_nodes(model_ori, get_constant_nodes(model_ori), forward_all(model_ori))
File "/usr/local/lib/python3.6/dist-packages/onnxsim/onnx_simplifier.py", line 130, in eliminate_const_nodes
vals=np.array(res[node.output[0]]).flatten().astype(get_np_type_from_elem_type(elem_type))
File "/usr/local/lib/python3.6/dist-packages/onnx/helper.py", line 173, in make_tensor
getattr(tensor, field).extend(vals)
TypeError: 0 has type numpy.int64, but expected one of: int

import order cause core dump

pytorch1.3.0, onnx1.6.0, onnxsim0.2.0

a simple test case



import torch
import onnx     # type: ignore
import onnxsim


def main():
    class TestNet(torch.nn.Module):
        def __init__(self):
            super(TestNet, self).__init__()
            self.conv = torch.nn.Conv1d(2, 3, kernel_size=(1,))
            return
        def forward(self, x):
            res = self.conv(x)
            return res
    net = TestNet()
    it = torch.randn(1, 2, 3)
    torch.onnx.export(net, it, "test_sim.onnx", export_params=True, verbose=True, input_names=["data"])
    model_opt = onnxsim.simplify(
        "test_sim.onnx"
        )
    print("export done")

    onnx.save(model_opt, "test_sim_simple.onnx")
    print("Ok!")


if __name__ == '__main__':
    main()

outputs

graph(%data : Float(1, 2, 3),
      %conv.weight : Float(3, 2, 1),
      %conv.bias : Float(3)):
  %3 : Float(1, 3, 3) = onnx::Conv[dilations=[1], group=1, kernel_shape=[1], pads=[0, 0], strides=[1]](%data, %conv.weight, %conv.bias), scope: TestNet/Conv1d[conv] # /usr/local/lib/python3.5/dist-packages/torch/nn/modules/conv.py:202:0
  return (%3)

Segmentation fault (core dumped)

but it works after i import torch after onnx

import torch
import onnx     # type: ignore
import onnxsim

change to

import onnx     # type: ignore
# import torch after onnx
import torch
import onnxsim

Attempting to broadcast an axis by a dimension other than 1. 16 by 96

Here's the error message:
Simplifying...
Traceback (most recent call last):
File "/home/mywp/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/mywp/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/mywp/anaconda3/lib/python3.6/site-packages/onnxsim/main.py", line 24, in
main()
File "/home/mywp/anaconda3/lib/python3.6/site-packages/onnxsim/main.py", line 17, in main
model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
File "/home/mywp/anaconda3/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 187, in simplify
model_opt = eliminate_const_nodes(model_opt, get_constant_nodes(model_opt), forward_all(model_opt))
File "/home/mywp/anaconda3/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 105, in forward_all
res = forward(model)
File "/home/mywp/anaconda3/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 97, in forward
res = OrderedDict(zip(outputs, sess.run(outputs, inputs)))
File "/home/mywp/anaconda3/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 72, in run
return self._sess.run(output_names, input_feed, run_options)
RuntimeError: Method run failed due to: [ONNXRuntimeError] : 1 : GENERAL ERROR : /onnxruntime_src/onnxruntime/core/providers/cpu/math/element_wise_ops.h:341 void onnxruntime::BroadcastIterator::Init(int64_t, int64_t) axis == 1 || axis == largest was false. Attempting to broadcast an axis by a dimension other than 1. 16 by 96
Stacktrace:

About the failure while simplifying

Hello, daquanxian dalao,
I'm the one who has asked the issue by email. Lat time, you helped me with your own process and send the correct model to me. But I meet this problem again, so I wanna know how to sovle this throughly!

Thanks!
报错

[BUG] About the ONNX concat order

Describe the bug
when the onnx-simplier simplify the onnx model, the operater concat order look like will be change, and it will leading data dimension different original pytorch dimension.

here is the original onnx model structure and the simplified onnx model:

image
image

optimization failed on missing input nodes

git clone master,源码编译的版本
pytorch e4f5224ebde7a4490c8d42aa7032cc89ece68271
onnx ca1d5b7e0a3290a1419cb2020511df07d11287fe

tmp.onnx.zip

Traceback (most recent call last):
  File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/nihui/.local/lib/python3.7/site-packages/onnxsim/__main__.py", line 24, in <module>
    main()
  File "/home/nihui/.local/lib/python3.7/site-packages/onnxsim/__main__.py", line 17, in main
    model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
  File "/home/nihui/.local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 197, in simplify
    model_opt = optimize(model_opt)
  File "/home/nihui/.local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 157, in optimize
    fixed_point=True)
  File "/home/nihui/.local/lib/python3.7/site-packages/onnx-1.6.0-py3.7-linux-x86_64.egg/onnx/optimizer.py", line 53, in optimize
    optimized_model_str = C.optimize_fixedpoint(model_str, passes)
IndexError: _Map_base::at

在这里,unordered_map key 不存在
https://github.com/onnx/onnx/blob/ca1d5b7e0a3290a1419cb2020511df07d11287fe/onnx/common/ir_pb_converter.cc#L284

发现是因为 key 是 0.weight,input nodes 里没有找到,于是 hack 下,将 initializer node 也放在 input nodes 里面,但是又出现以下问题

似乎是因为 pytorch 导出的时候,没有把 weight 放在 input 里面?

Traceback (most recent call last):
  File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/nihui/.local/lib/python3.7/site-packages/onnxsim/__main__.py", line 24, in <module>
    main()
  File "/home/nihui/.local/lib/python3.7/site-packages/onnxsim/__main__.py", line 17, in main
    model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
  File "/home/nihui/.local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 202, in simplify
    model_opt = eliminate_const_nodes(model_opt, const_nodes, res)
  File "/home/nihui/.local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 131, in eliminate_const_nodes
    vals=np.array(res[node.output[0]]).flatten().astype(get_np_type_from_elem_type(elem_type))
  File "/home/nihui/.local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 67, in get_np_type_from_elem_type
    size = sizes[elem_type]
TypeError: tuple indices must be integers or slices, not NoneType

[E:onnxruntime:, sequential_executor.cc:125 Execute] Non-zero status code returned while running Node: Status Message: 'repeat' input tensor must have the same length as the 'input' tensor

Hi, @daquexian ,thanks for your excellect work.
I ran into a problem like this
Simplifying...
2019-06-25 20:00:41.557868123 [E:onnxruntime:, sequential_executor.cc:125 Execute] Non-zero status code returned while running Node: Status Message: 'repeat' input tensor must have the same length as the 'input' tensor
Traceback (most recent call last):
File "/home/gwl/anaconda3/envs/pytorch1/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/gwl/anaconda3/envs/pytorch1/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/gwl/.local/lib/python3.6/site-packages/onnxsim/main.py", line 24, in
main()
File "/home/gwl/.local/lib/python3.6/site-packages/onnxsim/main.py", line 17, in main
model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
File "/home/gwl/.local/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 187, in simplify
model_opt = eliminate_const_nodes(model_opt, get_constant_nodes(model_opt), forward_all(model_opt))
File "/home/gwl/.local/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 105, in forward_all
res = forward(model)
File "/home/gwl/.local/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 97, in forward
res = OrderedDict(zip(outputs, sess.run(outputs, inputs)))
File "/home/gwl/.local/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 72, in run
return self._sess.run(output_names, input_feed, run_options)
RuntimeError: Method run failed due to: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Non-zero status code returned while running Node: Status Message: 'repeat' input tensor must have the same length as the 'input' tensor

Onnx model has been sent to your email.

Field 'shape' of type is required but missing.

use onnx-simplifier-0.2.4 to simplify a cnn model, as follows:
python -m onnxsim cnn.onnx cnn_s.onnx
the result is failed, because the issue "onnx.onnx_cpp2py_export.checker.ValidationError: Field 'shape' of type is required but missing."

[BUG] max_unpool2d not supported

Hi,
I am seeing:
onnx.onnx_cpp2py_export.checker.ValidationError: No Op registered for max_unpool2d with domain_version of 9

==> Context: Bad node spec: input: "276" input: "281" input: "284" output: "285" op_type: "max_unpool2d"

The model is plain pytorch segnet

[BUG] Can not simplify models with dynamic input?

Describe the bug

Simplifying...
2019-09-23 23:08:05.474371187 [E:onnxruntime:, sequential_executor.cc:127 Execute] Non-zero status code returned while running Node: 2 Status Message: Invalid input shape: {0,0}
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/dist-packages/onnxsim/__main__.py", line 24, in <module>
    main()
  File "/usr/local/lib/python3.6/dist-packages/onnxsim/__main__.py", line 17, in main
    model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
  File "/usr/local/lib/python3.6/dist-packages/onnxsim/onnx_simplifier.py", line 200, in simplify
    res = forward_all(model_opt)
  File "/usr/local/lib/python3.6/dist-packages/onnxsim/onnx_simplifier.py", line 107, in forward_all
    res = forward(model)
  File "/usr/local/lib/python3.6/dist-packages/onnxsim/onnx_simplifier.py", line 99, in forward
    res = OrderedDict(zip(outputs, sess.run(outputs, inputs)))
  File "/usr/local/lib/python3.6/dist-packages/onnxruntime/capi/session.py", line 72, in run
    return self._sess.run(output_names, input_feed, run_options)
RuntimeError: Method run failed due to: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Non-zero status code returned while running Node: 2 Status Message: Invalid input shape: {0,0}

** Model **

fasterrcnn.onnx

Any suggestions?

INDICES OUT OF DATA BOUNDS while simplifing an onnx model of mobilebnetv2ssd

Hi, I got this following error when executing the simplification. The .onnx model has been sent to your email. Can you share some solutions or ideas with it? Thx.


root@5277c7e46d46:/home/SSD_Lite# python -m onnxsim mobilenetv2ssd.onnx mobilenetv2ssd-sim.onnx
Simplifying...
2020-02-12 09:22:51.490512832 [E:onnxruntime:, sequential_executor.cc:183 Execute] Non-zero status code returned while running Gather node. Name:'' Status Message: indices element out of data bounds, idx=94386739683648 must be within the inclusive range [-3234,3233]
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/opt/conda/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/conda/lib/python3.6/site-packages/onnxsim/main.py", line 42, in
main()
File "/opt/conda/lib/python3.6/site-packages/onnxsim/main.py", line 31, in main
args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization, input_shapes=input_shapes)
File "/opt/conda/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 303, in simplify
res = forward_all(model, input_shapes=input_shapes)
File "/opt/conda/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 158, in forward_all
res = forward(model, input_shapes=input_shapes)
File "/opt/conda/lib/python3.6/site-packages/onnxsim/onnx_simplifier.py", line 149, in forward
res = OrderedDict(zip(outputs, sess.run(outputs, inputs, run_options=run_options)))
File "/opt/conda/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 142, in run
return self._sess.run(output_names, input_feed, run_options)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Non-zero status code returned while running Gather node. Name:'' Status Message: indices element out of data bounds, idx=94386739683648 must be within the inclusive range [-3234,3233]

KeyError: '271' when simplifying SSD based face detection onnx model

Hi,

I am using the onnx-simplifier to process the SSD onnx model. The model is originally from pytorch. I convert it from pytorch to onnx using torch.onnx._export. Then I use python -m onnxsim faceboxes.onnx faceboxes-sim.onnx to simplify the onnx model, and get the following error:

image

The original pytorch code is : https://github.com/zisianw/FaceBoxes.PyTorch
The original pytorch model file (save with all information: "torch.save(model,'model_all.pkl')") is uploaded to the BaiduNetDisk.
The onnx file converted from pytorch model is also uploaded.

Model file address: 链接:https://pan.baidu.com/s/1HA-ONKXtRrxa6v5cDlL5UQ
提取码:arrs
复制这段内容后打开百度网盘手机App,操作更方便哦

精度是否会受影响

你好,我用代码将onnx简化以后转ncnn,在分类任务中NCNN出来的logit和pytorch出来的结果精度在小数点后一位存在不一致,请问下是不是简化过程中比如合BN什么的影响了精度。

ONNX optimizers are broken for PyTorch 1.3 and so on

I got this "IndexError: _Map_base::at" when simliplify my onnx model.
python3 -m onnxsim model.onnx model_sim.onnx
Simplifying...
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/.local/lib/python3.5/site-packages/onnxsim/main.py", line 24, in
main()
File "/.local/lib/python3.5/site-packages/onnxsim/main.py", line 17, in main
model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
File "/.local/lib/python3.5/site-packages/onnxsim/onnx_simplifier.py", line 197, in simplify
model_opt = optimize(model_opt)
File "/.local/lib/python3.5/site-packages/onnxsim/onnx_simplifier.py", line 157, in optimize
fixed_point=True)
File "/.local/lib/python3.5/site-packages/onnx/optimizer.py", line 53, in optimize
optimized_model_str = C.optimize_fixedpoint(model_str, passes)
IndexError: _Map_base::at


From daquexian:

It is a bug of ONNX and we have to wait for ONNX maintainers to fix it.

Some workarounds: #25 (comment)

ONNXRuntimeError

MAC python3, onnx-simplifier 1.8 onnxruntime 0.5.0

File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.7/site-packages/onnxsim/main.py", line 24, in
main()
File "/usr/local/lib/python3.7/site-packages/onnxsim/main.py", line 17, in main
model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
File "/usr/local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 200, in simplify
res = forward_all(model_opt)
File "/usr/local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 107, in forward_all
res = forward(model)
File "/usr/local/lib/python3.7/site-packages/onnxsim/onnx_simplifier.py", line 99, in forward
res = OrderedDict(zip(outputs, sess.run(outputs, inputs)))
File "/usr/local/lib/python3.7/site-packages/onnxruntime/capi/session.py", line 72, in run
return self._sess.run(output_names, input_feed, run_options)
RuntimeError: Method run failed due to: [ONNXRuntimeError] : 1 : GENERAL ERROR : /Users/vsts/agent/2.155.1/work/1/s/onnxruntime/core/providers/cpu/nn/pool_base.h:169 std::vector<int64_t> onnxruntime::PoolBase::SetOutputSize(const onnxruntime::TensorShape &, int64_t, std::vector<int64_t> *, const std::vector<int64_t> &, int64_t) const input_shape.Size() > 0 was false.

[BUG] Gather not supported yet!

I use onnx-simplifier to get a mynet-sim.onnx
but when I use onnx2ncnn to convert mynet-sim.onnx, it still says that:
Gather not supported yet!

axis=1

Gather not supported yet!

axis=1

Gather not supported yet!

axis=1

google.protobuf.message.DecodeError: Protobuf decoding consumed too few bytes: 5 out of 105151288[BUG]

Thank you for your contribution!
I want ssd-pytorch2onnx, but there is error:
Simplifying...
D:\anaconda\lib\site-packages\onnx_init_.py:94: RuntimeWarning: Unexpected end-group tag: Not all data was converted
decoded = cast(Optional[int], proto.ParseFromString(s))
Traceback (most recent call last):
File "D:\anaconda\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "D:\anaconda\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "D:\anaconda\lib\site-packages\onnxsim_main
.py", line 24, in
main()
File "D:\anaconda\lib\site-packages\onnxsim_main
.py", line 17, in main
model_opt = onnxsim.simplify(args.input_model, check_n=args.check_n, perform_optimization=not args.skip_optimization)
File "D:\anaconda\lib\site-packages\onnxsim\onnx_simplifier.py", line 192, in simplify
model_ori = onnx.load(model_ori)
File "D:\anaconda\lib\site-packages\onnx_init_.py", line 114, in load_model
model = load_model_from_string(s, format=format)
File "D:\anaconda\lib\site-packages\onnx_init_.py", line 151, in load_model_from_string
return deserialize(s, ModelProto())
File "D:\anaconda\lib\site-packages\onnx_init
.py", line 98, in _deserialize
decoded, len(s)))
google.protobuf.message.DecodeError: Protobuf decoding consumed too few bytes: 5 out of 105151288

IndexError: unordered_map::at: key not found

python3 -m onnxsim alexnet.onnx alexnet_sim.onnx 

File "/Users/zhanglu/miniconda3/lib/python3.7/site-packages/onnx/optimizer.py", line 53, in optimize
    optimized_model_str = C.optimize_fixedpoint(model_str, passes)
IndexError: unordered_map::at: key not found

envs:
python3.7 macos pytorch1.3 onnx 1.6.0

alexnet

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.