XiaoMi/mace

Torch -> ONNX -> libMace : AttributeError: module 'onnx.utils' has no attribute 'polish_model'

vyi opened this issue · 4 comments

vyi commented

System information

  • Ubuntu 16.04 :
  • NDK r15c :
  • MACE version tried : 0.9.0, 1.0.0, 1.0.3:
  • Python 3.7:
  • Bazel 0.13.0:

Model deploy file (*.yml)

library_name: resnet_model
target_abis: [arm64-v8a]
model_graph_format: file
model_data_format: file
models:
    resnet_model: 
        platform: onnx
        model_file_path: /home/user/anaconda3/envs/myEnv/opt/resnet50.onnx
        model_sha256_checksum: f64042291b3a6f4501adfb4c306d9fbaaa94a1c125d3432e0d78ba0b76254943 
        subgraphs:
            - input_tensors:
                - input
              input_shapes:
                - 1,3,256,256
              output_tensors:
                - output
              output_shapes:
                - 1,1000
              input_data_formats:
                - NCHW
              backend: pytorch
        runtime: cpu+gpu
        winograd: 0

Describe the problem

I was following this tutorial to deploy a PyTorch NN model on Android. Following the steps of the tutorial I was able to successfully create ONNX model using torch.onnx.export. I was able to load this model on Neutron and I believe the model is alright. I then tried to convert the ONNX model to Mace model but was not able to, using tools/converter.py script throws the following error trace:

onnx model IR version:  6
constains ops domain:   version: 9
Traceback (most recent call last):
  File "tools/converter.py", line 1220, in <module>
    flags.func(flags)
  File "tools/converter.py", line 860, in convert_func
    convert.convert(configs, MODEL_CODEGEN_DIR, flags.enable_micro)
  File "tools/python/convert.py", line 78, in convert
    mace_model = convert_model(model_conf, quantize_stat)
  File "tools/python/convert.py", line 190, in convert_model
    conf["model_file_path"])
  File "tools/python/transform/onnx_converter.py", line 442, in __init__
    onnx_model = onnx.utils.polish_model(onnx_model)
AttributeError: module 'onnx.utils' has no attribute 'polish_model'

To Reproduce

Steps to reproduce the problem:

  • Follow the steps of this tutorial for converting RESNET50 model into Mace
  • After the ONNX model creation, the conversion step does not go through
python tools/converter.py convert --config ../model/resnet_model.yml 

Additional context

The error appears to be associated with ONNX module. But sadly I couldn't find any resolution to the above issue. While searching for error keywords I saw somewhat relevant discussion at the following page and it suggests something.
I don't know how to/where to apply that something patch in the last link. I don't know if this something patch will resolve the issue at hand.

Please help me out!

lu229 commented

@vyi Is your version of ONNX 1.8.0 or above? Please refer to this document.

vyi commented

Indeed, my ONNX is 1.9.0. I will try with 1.8.0 and update here.

Update

The conversion is working fine with ONNX 1.8.0.
Thank you so much @lu229

vyi commented

Resolved using the correct library version ONNX==1.8,0

lu229 commented

Resolved using the correct library version ONNX==1.8,0

OK,Thanks for your report, we will resolve this issue for 1.9.0 and above.