You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/09/10 18:59:03 UTC

[GitHub] sandeep-krishnamurthy closed pull request #12457: [MXNET-885] ONNX export - Clip operator

sandeep-krishnamurthy closed pull request #12457: [MXNET-885] ONNX export - Clip operator
URL: https://github.com/apache/incubator-mxnet/pull/12457
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
index 0960776251c..3ffac96a14e 100644
--- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
+++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
@@ -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"""
diff --git a/tests/python-pytest/onnx/export/onnx_backend_test.py b/tests/python-pytest/onnx/export/onnx_backend_test.py
index 19bf6993e7c..01ae09402ef 100644
--- a/tests/python-pytest/onnx/export/onnx_backend_test.py
+++ b/tests/python-pytest/onnx/export/onnx_backend_test.py
@@ -89,7 +89,8 @@
     'test_operator_exp',
     'test_operator_maxpool',
     'test_operator_params',
-    'test_operator_permute2'
+    'test_operator_permute2',
+    'test_clip'
     ]
 
 BASIC_MODEL_TESTS = [


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services