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

[MXNET-885] ONNX export - Clip operator #12457

Merged
merged 1 commit into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
anirudhacharya marked this conversation as resolved.
Show resolved Hide resolved
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