Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert coreml to onnx error on apply_prelu??? #331

Open
sharepointer opened this issue Aug 14, 2019 · 10 comments
Open

convert coreml to onnx error on apply_prelu??? #331

sharepointer opened this issue Aug 14, 2019 · 10 comments

Comments

@sharepointer
Copy link

onnx_model = onnxmltools.convert_coreml(coreml_model)

File "/usr/local/lib/python3.6/dist-packages/onnxmltools/convert/main.py", line 18, in convert_coreml
custom_conversion_functions, custom_shape_calculators)
File "/usr/local/lib/python3.6/dist-packages/onnxmltools/convert/coreml/convert.py", line 80, in convert
onnx_model = convert_topology(topology, name, doc_string, target_opset, targeted_onnx)
File "/usr/local/lib/python3.6/dist-packages/onnxconverter_common/topology.py", line 729, in convert_topology
registration.get_converter(operator.type)(scope, operator, container)
File "/usr/local/lib/python3.6/dist-packages/onnxmltools/convert/coreml/operator_converters/neural_network/Activation.py", line 27, in convert_activation
apply_prelu(scope, inputs, outputs, container, operator_name=attrs['name'], slope=[params.PReLU.alpha])
File "/usr/local/lib/python3.6/dist-packages/onnxconverter_common/onnx_ops.py", line 440, in apply_prelu
s_shape = slope.shape
AttributeError: 'list' object has no attribute 'shape'

@sharepointer
Copy link
Author

error on apply_prelu???

@sharepointer sharepointer changed the title convert coreml to onnx convert coreml to onnx error on apply_prelu??? Aug 14, 2019
@jiafatom
Copy link
Collaborator

Can you provide the model for us to debug?

@KeunwooPark
Copy link

KeunwooPark commented Dec 10, 2019

I had the same issue. I was trying to convert Openpose to an ONNX model. I used their body_25 models. The below is my code.

# Convert Caffe model to CoreML
coreml_model = coremltools.converters.caffe.convert((args.caffemodel, args.protofile))
# Convert the Core ML model into ONNX
onnx_model = onnxmltools.convert_coreml(coreml_model)
# Save as protobuf
onnxmltools.utils.save_model(onnx_model, args.output)

And here is the error I got.

Traceback (most recent call last):
  File "caffe2onnx.py", line 27, in <module>
    main(args)
  File "caffe2onnx.py", line 21, in main
    onnx_model = onnxmltools.convert_coreml(coreml_model)
  File "[home]/.virtualenvs/caffe2pytorch/lib/python3.5/site-packages/onnxmltools/convert/main.py", line 18, in convert_coreml
    custom_conversion_functions, custom_shape_calculators)
  File "[home]/.virtualenvs/caffe2pytorch/lib/python3.5/site-packages/onnxmltools/convert/coreml/convert.py", line 80, in convert
    onnx_model = convert_topology(topology, name, doc_string, target_opset, targeted_onnx)
  File "[home]/.virtualenvs/caffe2pytorch/lib/python3.5/site-packages/onnxconverter_common/topology.py", line 729, in convert_topology
    registration.get_converter(operator.type)(scope, operator, container)
  File "[home]/.virtualenvs/caffe2pytorch/lib/python3.5/site-packages/onnxmltools/convert/coreml/operator_converters/neural_network/Activation.py", line 27, in convert_activation
    apply_prelu(scope, inputs, outputs, container, operator_name=attrs['name'], slope=[params.PReLU.alpha])
  File "[home]/.virtualenvs/caffe2pytorch/lib/python3.5/site-packages/onnxconverter_common/onnx_ops.py", line 522, in apply_prelu
    s_shape = slope.shape
AttributeError: 'list' object has no attribute 'shape'

@OuHangKresnik
Copy link

I just encounter the same issue here.

@orsveri
Copy link

orsveri commented Apr 9, 2020

Hello! I was trying to convert openpose model from Caffe to ONNX too and got the same error.

SCRIPT:

import os
import coremltools
import onnxmltools

# Update your input name and path for your caffe model
dir = "/media/sveta/DATASTORE/AI_ML_DL/Projects/PoseEstimation/CMU-PCL_OpenPose/openpose/models/pose/body_25/"
proto_file = 'pose_deploy.prototxt'
input_caffe_path = 'pose_iter_584000.caffemodel'

# Update the output name and path for intermediate coreml model, or leave as is
output_coreml_model = 'temp/model.mlmodel'

# Change this path to the output name and path for the onnx model
output_onnx_model = 'pose_body25_model.onnx'

# Convert Caffe model to CoreML
coreml_model = coremltools.converters.caffe.convert((os.path.join(dir, input_caffe_path), os.path.join(dir, proto_file)))

# Save CoreML model
coreml_model.save(output_coreml_model)

# Load a Core ML model
coreml_model = coremltools.utils.load_spec(output_coreml_model)

# Convert the Core ML model into ONNX
onnx_model = onnxmltools.convert_coreml(coreml_model)

# Save as protobuf
onnxmltools.utils.save_model(onnx_model, output_onnx_model)

print("Successfully done!")

ERROR:

Traceback (most recent call last):
  File "/media/sveta/DATASTORE/AI_ML_DL/Projects/PoseEstimation/CMU-PCL_OpenPose/convert_openpose/openpose2onnx.py", line 33, in <module>
    onnx_model = onnxmltools.convert_coreml(coreml_model)
  File "/home/sveta/.local/envs/pytorch_env/lib/python3.6/site-packages/onnxmltools/convert/main.py", line 18, in convert_coreml
    custom_conversion_functions, custom_shape_calculators)
  File "/home/sveta/.local/envs/pytorch_env/lib/python3.6/site-packages/onnxmltools/convert/coreml/convert.py", line 80, in convert
    onnx_model = convert_topology(topology, name, doc_string, target_opset, targeted_onnx)
  File "/home/sveta/.local/envs/pytorch_env/lib/python3.6/site-packages/onnxconverter_common/topology.py", line 737, in convert_topology
    registration.get_converter(operator.type)(scope, operator, container)
  File "/home/sveta/.local/envs/pytorch_env/lib/python3.6/site-packages/onnxmltools/convert/coreml/operator_converters/neural_network/Activation.py", line 27, in convert_activation
    apply_prelu(scope, inputs, outputs, container, operator_name=attrs['name'], slope=[params.PReLU.alpha])
  File "/home/sveta/.local/envs/pytorch_env/lib/python3.6/site-packages/onnxconverter_common/onnx_ops.py", line 522, in apply_prelu
    s_shape = slope.shape
AttributeError: 'list' object has no attribute 'shape'

MODEL:
prototxt
caffemodel

@milesxu
Copy link

milesxu commented May 10, 2020

I have got exactly the same error.

@Rajrup
Copy link

Rajrup commented May 20, 2020

Encountered the same error.
@jiafatom Can you please help us in coverting openpose model?

@parameciumvance
Copy link

Also met the error.
Why is this issue not receiving a response since?

@Zhivago-Sizov
Copy link

Zhivago-Sizov commented Aug 6, 2020

the list object [slope] which passed to the func apply_prelu in onnxconverter_common/onnx_ops.py do not have shape attribute cause it's a list, without dive in too much, I make a quick fix simply turn the list into a NumPy array

# onnxconverter_common/onnx_ops.py
def apply_prelu(scope, input_name, output_name, container, operator_name=None, slope=None):
    slope=np.array(slope[0].floatValue)
    ...

@jiafatom
Copy link
Collaborator

jiafatom commented Aug 6, 2020

@vuvalini thanks for your change. Generally please make changes on onnxmltools, not on onnxconverter_common. Because onnxconverter_common is shared by other converters. This will break other converters if the change is made.

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

No branches or pull requests

9 participants