Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
identity operator added
Browse files Browse the repository at this point in the history
  • Loading branch information
Roshrini committed Jun 13, 2018
1 parent cc04a35 commit 6a7f412
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions python/mxnet/contrib/onnx/_export/op_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def parse_helper(attrs, attrs_name, alt_value=None):
tuple_re = re.compile('\([0-9L|,| ]+\)')
if attrs is None:
return alt_value
attrs_str = str(attrs.get(attrs_name))
attrs_str = None if attrs.get(attrs_name) is None else str(attrs.get(attrs_name))
if attrs_str is None:
return alt_value
attrs_match = tuple_re.search(attrs_str)
Expand Down Expand Up @@ -601,6 +601,28 @@ def convert_exp(node, **kwargs):
return [node]


@mx_op.register("_copy")
def convert_identity(node, **kwargs):
"""Map MXNet's _copy operator attributes to onnx's Identity operator
and return the created node.
"""
helper, _, _ = import_onnx_modules()
name = node["name"]
proc_nodes = kwargs["proc_nodes"]
inputs = node["inputs"]

input_node_id = kwargs["index_lookup"][inputs[0][0]]
input_node = proc_nodes[input_node_id].name

node = helper.make_node(
"Identity",
[input_node],
[name],
name=name,
)
return [node]


@mx_op.register("LeakyReLU")
def convert_leakyrelu(node, **kwargs):
"""Map MXNet's LeakyReLU operator attributes to onnx's Elu/LeakyRelu/PRelu operators
Expand Down Expand Up @@ -833,12 +855,15 @@ def convert_mul_scalar(node, **kwargs):

initializer = kwargs["initializer"]
flag = True
# If the input value is in initializer, just multiply with scalar input
# and create a new initializer
for i in initializer:
if i.name == input_node:
new_initializer = scalar_mul_value[0]*numpy_helper.to_array(i)
new_initializer = scalar_mul_value[0] * numpy_helper.to_array(i)
flag = False
break

# else create a new tensor of the scalar value, add it in initializer
if flag is True:
np_arr = np.array(scalar_mul_value)
data_type = mapping.NP_TYPE_TO_TENSOR_TYPE[np_arr.dtype]
Expand Down

0 comments on commit 6a7f412

Please sign in to comment.