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

Commit

Permalink
ONNX export: Instance Normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
vandanavk committed Oct 16, 2018
1 parent 0e3129d commit 7b0217c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
35 changes: 35 additions & 0 deletions python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,41 @@ def convert_identity(node, **kwargs):
)
return [node]

@mx_op.register("InstanceNorm")
def convert_instancenorm(node, **kwargs):
"""Map MXNet's InstanceNorm operator attributes to onnx's InstanceNormalization operator
based on the input node's attributes and return the created node.
"""
onnx = import_onnx_modules()
name = node["name"]
proc_nodes = kwargs["proc_nodes"]
inputs = node["inputs"]
inputs = node["inputs"]

input_node_id = kwargs["index_lookup"][inputs[0][0]]
gamma_node_id = kwargs["index_lookup"][inputs[1][0]]
beta_node_id = kwargs["index_lookup"][inputs[2][0]]

proc_nodes = kwargs["proc_nodes"]
input_node = proc_nodes[input_node_id]
gamma_node = proc_nodes[gamma_node_id]
beta_node = proc_nodes[beta_node_id]

input_name = input_node.name
gamma_name = gamma_node.name
beta_name = beta_node.name

attrs = node.get("attrs", {})
eps = float(attrs.get("eps", 0.001))

node = onnx.helper.make_node(
'InstanceNormalization',
inputs=[input_name, gamma_name, beta_name],
outputs=[name],
name=name,
epsilon=eps)

return [node]

@mx_op.register("LeakyReLU")
def convert_leakyrelu(node, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion tests/python-pytest/onnx/export/onnx_backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
'test_operator_permute2',
'test_clip',
'test_cast',
'test_hardsigmoid'
'test_hardsigmoid',
'test_instancenorm'
]

BASIC_MODEL_TESTS = [
Expand Down

0 comments on commit 7b0217c

Please sign in to comment.