Open gitathrun opened 4 years ago
@gitathrun Hi, I have exactly the same issue, do you solve your issue ?
Any solutions?
i am also facing similar issue: "constantOfShape", any resolutions?
I fixed it with creating converter for constanOfShape ConstantOfShape creates a constant with value stored in node of shape passed as input so np.full is basically what it does ref https://github.com/onnx/onnx/blob/master/docs/Operators.md#Constant https://github.com/onnx/onnx/blob/master/docs/Operators.md#ConstantOfShape
Got other errors too, so not sure if it is working properly
from onnx2keras import onnx_to_keras
from onnx2keras.layers import AVAILABLE_CONVERTERS
import numpy as np
def convert_constant_of_shape(node, params, layers, lambda_func, node_name, keras_name):
"""
Convert Constant layer
:param node: current operation node
:param params: operation attributes
:param layers: available keras layers
:param lambda_func: function for keras Lambda layer
:param node_name: internal converter name
:param keras_name: resulting layer name
:return: None
"""
layers[node_name] = np.full(layers[node.input[0]], params["value"])
AVAILABLE_CONVERTERS["ConstantOfShape"] = convert_constant_of_shape
onnx_model = onnx.load_model(onnx_path)
onnx.checker.check_model(onnx_model)
k_model = onnx_to_keras(onnx_model, ["input_1"])
You can also try exporting to onnx opset_version=9. In my case it avoided creation of constantOfShape
I'm still working on this so I don't know if this will generally work but I had a shape of the form [none, 3]
and the np.full
method broke down with this. Here is a modified version that seems to work when there is a none
in the shape:
from keras import initializers
...
def convert_constant_of_shape(node, params, layers, lambda_func, node_name, keras_name):
"""
Convert Constant layer
:param node_name: current operation node
:param params: operation attributes
:param layers: available keras layers
:param lambda_func: function for keras Lambda layer
:param node_name: internal converter name
:param keras_name: resulting layer name
:return: None
"""
import numpy as np
layers[node_name] = initializers.Constant(value = params["value"][0])(layers[node.input[0]])
#layers[node_name] = np.full(layers[node.input[0]], params["value"][0])
AVAILABLE_CONVERTERS["ConstantOfShape"] = convert_constant_of_shape
I put these modifications in
(this actually isn't working yet, I was mistaken. I went a different direction that involved more targeted exports of submodules, eliminating the need for me to figure this out.)converter.py
in onnx2keras.
Hi, I am working on the conversion of onnx to keras, until I got this error message:
There is no any other indications, is there any ideas about how to solve this problem?
onnx version 1.6 onnx2keras version 0.0.18