Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

onnx.optimizer.optimize fails on converted ResNet50 #337

Closed
uncommoncode opened this issue Jan 8, 2020 · 3 comments
Closed

onnx.optimizer.optimize fails on converted ResNet50 #337

uncommoncode opened this issue Jan 8, 2020 · 3 comments

Comments

@uncommoncode
Copy link

Error

I'm attempting to use the onnx optimizer on the example ResNet50 network in Keras.

However despite the onnx checker succeeding on a model loaded by keras2onnx, the optimizer fails.

The error message I get fails somewhere in the C++ code running the onnx optimizer:

Traceback (most recent call last):
  File "test_onnx_optimize.py", line 9, in <module>
    optimized_model = onnx.optimizer.optimize(onnx_model)
  File "venv/lib/python3.7/site-packages/onnx/optimizer.py", line 55, in optimize
    optimized_model_str = C.optimize(model_str, passes)
IndexError: unordered_map::at: key not found

Steps to Reproduce

This code reproduces the issue:

import keras2onnx
import onnx
import onnx.optimizer
from keras.applications.resnet50 import ResNet50

model = ResNet50(include_top=True, weights='imagenet')
onnx_model = keras2onnx.convert_keras(model, model.name)
onnx.checker.check_model(onnx_model)
optimized_model = onnx.optimizer.optimize(onnx_model)
@jiafatom
Copy link
Collaborator

jiafatom commented Jan 8, 2020

onnx.optimizer.optimize is a legacy code, just use onnx_model directly.

@uncommoncode
Copy link
Author

onnx.optimizer supports several optimizer passes not implemented here, such as fuse_bn_into_conv (see https://github.com/onnx/onnx/blob/master/onnx/optimizer/passes/fuse_bn_into_conv.h).

@jiafatom
Copy link
Collaborator

jiafatom commented Feb 7, 2020

We have done ConvBatchNorm fusion in onnxconverter-common recently here. For ResNet50, it is already highly optimized now. Please try using keras2onnx and onnxconverter-common master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants