onnxmltools
onnxmltools copied to clipboard
convert coreml to onnx error on apply_prelu???
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'
error on apply_prelu???
Can you provide the model for us to debug?
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'
I just encounter the same issue here.
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
I have got exactly the same error.
Encountered the same error. @jiafatom Can you please help us in coverting openpose model?
Also met the error. Why is this issue not receiving a response since?
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)
...
@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.