onnx / tutorials

Tutorials for creating and using ONNX models
Apache License 2.0
3.33k stars 626 forks source link

IndexError: unordered_map::at: key not found #164

Open InternetExplorer9 opened 4 years ago

InternetExplorer9 commented 4 years ago

Code:

def run_onnx_in_caffe2(args, message_tensor):
    # Load the ONNX ModelProto object. model is a standard Python protobuf object
    model_onnx = onnx.load(args.output_path)

    # prepare the caffe2 backend for executing the model_onnx this converts the ONNX model into a
    # Caffe2 NetDef that can execute it. Other ONNX backends, like one for CNTK will be
    # availiable soon.
    prepared_backend = onnx_caffe2_backend.prepare(model_onnx)

    # Construct a map from input names to Tensor data.
    # The graph of the model itself contains inputs for all weight parameters, after the input image.
    # Since the weights are already embedded, we just need to pass the input image.
    # Set the first input.
    W = {model_onnx.graph.input[0].name: message_tensor.data.numpy()}

    # Run the Caffe2 net:
    caffe2_out = prepared_backend.run(W)[0]
    return caffe2_out

This method produces the following stack trace, which is triggered after a call to onnx_caffe2_backend.prepare:

Model saved to model.onnx
Traceback (most recent call last):
  File "/Users/IdeaProjects/export-pytorch-to-caffe2/export_pytorch_to_caffe2.py", line 86, in <module>
    main(args)
  File "/Users/IdeaProjects/export-pytorch-to-caffe2/export_pytorch_to_caffe2.py", line 69, in main
    caffe2_out = run_onnx_in_caffe2(args, random_message_tensor)
  File "/Users/IdeaProjects/export-pytorch-to-caffe2/export_pytorch_to_caffe2.py", line 43, in run_onnx_in_caffe2
    prepared_backend = onnx_caffe2_backend.prepare(model_onnx)
  File "/Users/.local/share/virtualenvs/-KmYQrZv5/lib/python3.6/site-packages/caffe2/python/onnx/backend.py", line 713, in prepare
    init_net, predict_net = cls._onnx_model_to_caffe2_net(model, device, opset_version, False)
  File "/Users/.local/share/virtualenvs/-KmYQrZv5/lib/python3.6/site-packages/caffe2/python/onnx/backend.py", line 876, in _onnx_model_to_caffe2_net
    onnx_model = onnx.utils.polish_model(onnx_model)
  File "/Users/.local/share/virtualenvs/-KmYQrZv5/lib/python3.6/site-packages/onnx/utils.py", line 21, in polish_model
    model = onnx.optimizer.optimize(model)
  File "/Users/.local/share/virtualenvs/-KmYQrZv5/lib/python3.6/site-packages/onnx/optimizer.py", line 55, in optimize
    optimized_model_str = C.optimize(model_str, passes)
IndexError: unordered_map::at: key not found
askhade commented 4 years ago

@InternetExplorer9 : This is a known issue in ONNX Optimizers. There is discussion going on to decide the fate of optimizers. At the very least the call to optimize should be removed from polish_model See Issue https://github.com/onnx/steering-committee/issues/7 for more context