You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by zh...@apache.org on 2021/02/08 22:37:43 UTC
[incubator-mxnet] branch v1.x updated: [v1.x] Onnx Support for
Dropout (#19837)
This is an automated email from the ASF dual-hosted git repository.
zha0q1 pushed a commit to branch v1.x
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/v1.x by this push:
new 0066ccb [v1.x] Onnx Support for Dropout (#19837)
0066ccb is described below
commit 0066ccbc38036f29559f6632becb522da31b0b75
Author: Zhaoqi Zhu <zh...@gmail.com>
AuthorDate: Mon Feb 8 14:35:43 2021 -0800
[v1.x] Onnx Support for Dropout (#19837)
* Dropout
* Update _op_translations.py
* Update _op_translations.py
* Update _op_translations.py
* Update _op_translations.py
---
.../mxnet/contrib/onnx/mx2onnx/_op_translations.py | 22 +++++++++++-----------
tests/python-pytest/onnx/test_operators.py | 9 +++++++++
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
index f472e18..c804126 100644
--- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
+++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
@@ -1125,19 +1125,19 @@ def convert_dropout(node, **kwargs):
"""
from onnx.helper import make_node
name, input_nodes, attrs = get_inputs(node, kwargs)
- opset_version = kwargs["opset_version"]
- probability = float(attrs.get("p", 0.5))
+ _ = float(attrs.get("p", 0.5))
+ _ = convert_string_to_list(attrs.get("axes", "None"))
+ mode = attrs.get('mode', 'training')
- if opset_version >= 12:
- # opset >= 12 requires the ratio to be an input
- nodes = [
- create_const_scalar_node(name+"_ratio0", np.float32(probability), kwargs),
- make_node("Dropout", [input_nodes[0], name+"_ratio0"], [name], name=name)
- ]
- return nodes
- else:
- return [make_node("Dropout", input_nodes, [name], ratio=probability, name=name)]
+ if mode != 'training':
+ raise NotImplementedError("Dropout does not currently support mode!=\'training\'")
+
+ nodes = [
+ make_node('Identity', [input_nodes[0]], [name])
+ ]
+
+ return nodes
@mx_op.register("Flatten")
diff --git a/tests/python-pytest/onnx/test_operators.py b/tests/python-pytest/onnx/test_operators.py
index 7dc5b5c..97eae9f 100644
--- a/tests/python-pytest/onnx/test_operators.py
+++ b/tests/python-pytest/onnx/test_operators.py
@@ -1009,6 +1009,15 @@ def test_onnx_export_broadcast_mul(tmp_path, dtype):
op_export_test('broadcast_mul', M, [x, y], tmp_path)
+@pytest.mark.parametrize('dtype', ['float16', 'float32', 'float64'])
+@pytest.mark.parametrize('shape', [(3, 4, 5), (1, 2, 3, 2, 1)])
+@pytest.mark.parametrize('p', [0, 0.1, 0.5, 1])
+def test_onnx_export_dropout(tmp_path, dtype, shape, p):
+ x = mx.random.uniform(-100, 100, shape=shape).astype(dtype)
+ M = def_model('Dropout', p=p)
+ op_export_test('Dropuout', M, [x], tmp_path)
+
+
@pytest.mark.parametrize('dtype', ['float32'])
@pytest.mark.parametrize('shape', [(1, 3, 64, 64), (2, 6, 60, 60)])
@pytest.mark.parametrize('num_filter', [2, 4, 32])