From 960fb85f0650ac51b272272c34a1b1afd126aede Mon Sep 17 00:00:00 2001 From: "Liu, Hao" Date: Wed, 10 Jun 2020 18:32:23 +0800 Subject: [PATCH 1/3] fix pooling_convention warning --- .../contrib/onnx/mx2onnx/_op_translations.py | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py index 247b39301b78..2772b5271d77 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py +++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py @@ -759,12 +759,12 @@ def convert_pooling(node, **kwargs): p_value = attrs.get('p_value', 'None') pooling_convention = attrs.get('pooling_convention', 'valid') - + ceil_mode = False if pooling_convention == 'full': - pooling_warning = "Pooling: ONNX currently doesn't support pooling_convention. " \ + pooling_warning = "Pooling: ONNX lower than 1.5.0 doesn't support pooling_convention. " \ "This might lead to shape or accuracy issues. " \ - "https://github.com/onnx/onnx/issues/549" - + "https://github.com/onnx/onnx/issues/549, fixed in onnx 1.5.0" + ceil_mode=True logging.warning(pooling_warning) pad_dims = list(parse_helper(attrs, "pad", [0, 0])) @@ -805,15 +805,27 @@ def convert_pooling(node, **kwargs): name=name ) else: - node = onnx.helper.make_node( - pool_types[pool_type], - input_nodes, # input - [name], - kernel_shape=kernel, - pads=pad_dims, - strides=stride, - name=name - ) + if onnx.__version__>="1.5.0": + node = onnx.helper.make_node( + pool_types[pool_type], + input_nodes, # input + [name], + kernel_shape=kernel, + pads=pad_dims, + strides=stride, + name=name, + ceil_mode=ceil_mode + ) + else: + node = onnx.helper.make_node( + pool_types[pool_type], + input_nodes, # input + [name], + kernel_shape=kernel, + pads=pad_dims, + strides=stride, + name=name + ) return [node] From c057afcf82eaf3db12d1050148c1b2ef42d2fd15 Mon Sep 17 00:00:00 2001 From: "Liu, Hao" Date: Wed, 10 Jun 2020 18:38:57 +0800 Subject: [PATCH 2/3] fix pooling_convention warning --- python/mxnet/contrib/onnx/mx2onnx/_op_translations.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py index 2772b5271d77..c580526d8e28 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py +++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py @@ -761,9 +761,10 @@ def convert_pooling(node, **kwargs): pooling_convention = attrs.get('pooling_convention', 'valid') ceil_mode = False if pooling_convention == 'full': - pooling_warning = "Pooling: ONNX lower than 1.5.0 doesn't support pooling_convention. " \ - "This might lead to shape or accuracy issues. " \ - "https://github.com/onnx/onnx/issues/549, fixed in onnx 1.5.0" + if onnx.__version__<"1.5.0": + pooling_warning = "Pooling: ONNX lower than 1.5.0 doesn't support pooling_convention. " \ + "This might lead to shape or accuracy issues. " \ + "https://github.com/onnx/onnx/issues/549" ceil_mode=True logging.warning(pooling_warning) From 0deb50b33f29a19bbe4bdc6ff14658afc5000d50 Mon Sep 17 00:00:00 2001 From: JackieWu Date: Wed, 10 Jun 2020 19:35:52 +0800 Subject: [PATCH 3/3] fix lint --- python/mxnet/contrib/onnx/mx2onnx/_op_translations.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py index c580526d8e28..a9832a115e3d 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py +++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py @@ -761,11 +761,11 @@ def convert_pooling(node, **kwargs): pooling_convention = attrs.get('pooling_convention', 'valid') ceil_mode = False if pooling_convention == 'full': - if onnx.__version__<"1.5.0": + if onnx.__version__ < "1.5.0": pooling_warning = "Pooling: ONNX lower than 1.5.0 doesn't support pooling_convention. " \ "This might lead to shape or accuracy issues. " \ "https://github.com/onnx/onnx/issues/549" - ceil_mode=True + ceil_mode = True logging.warning(pooling_warning) pad_dims = list(parse_helper(attrs, "pad", [0, 0])) @@ -806,7 +806,7 @@ def convert_pooling(node, **kwargs): name=name ) else: - if onnx.__version__>="1.5.0": + if onnx.__version__ >= "1.5.0": node = onnx.helper.make_node( pool_types[pool_type], input_nodes, # input