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

Commit

Permalink
ONNX export - Clip operator
Browse files Browse the repository at this point in the history
  • Loading branch information
vandanavk committed Sep 6, 2018
1 parent e290623 commit 744435b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,30 @@ def convert_flatten(node, **kwargs):
)
return [flatten_node]

@mx_op.register("clip")
def convert_clip(node, **kwargs):
"""Map MXNet's Clip operator attributes to onnx's Clip operator
and return the created node.
"""
helper, _, _ = import_onnx_modules()
name = node["name"]
input_idx = kwargs["index_lookup"][node["inputs"][0][0]]
proc_nodes = kwargs["proc_nodes"]
input_node = proc_nodes[input_idx].name
attrs = node["attrs"]
a_min = np.float(attrs.get('a_min', -np.inf))
a_max = np.float(attrs.get('a_max', np.inf))

clip_node = helper.make_node(
"Clip",
[input_node],
[name],
name=name,
min=a_min,
max=a_max
)
return [clip_node]


def scalar_op_helper(node, op_name, **kwargs):
"""Helper function for scalar arithmetic operations"""
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 @@ -89,7 +89,8 @@
'test_operator_exp',
'test_operator_maxpool',
'test_operator_params',
'test_operator_permute2'
'test_operator_permute2',
'test_clip'
]

BASIC_MODEL_TESTS = [
Expand Down

0 comments on commit 744435b

Please sign in to comment.