From 19138f676e33656c5fccc2fc0fde4db7bda26eb0 Mon Sep 17 00:00:00 2001 From: Vinitra Swamy Date: Thu, 27 Feb 2020 12:03:28 -0800 Subject: [PATCH 1/5] fixing spatial export for batchnorm --- 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 bfd905cbae6a..4060d4aa470f 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py +++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py @@ -350,9 +350,10 @@ def convert_batchnorm(node, **kwargs): name=name, epsilon=eps, momentum=momentum, - # MXNet computes mean and variance per feature for batchnorm - # Default for onnx is across all spatial features. So disabling the parameter. - spatial=0 + # MXNet computes mean and variance per channel for batchnorm + # Default for onnx is across all spatial features. Explicitly encoding + # spatial=1 for ONNX opset 8 and below. + spatial=1 ) return [bn_node] From 7825aabfc8138a9305db8dd43f9a9a49d774a6ce Mon Sep 17 00:00:00 2001 From: vinitra Date: Wed, 4 Mar 2020 11:32:29 -0800 Subject: [PATCH 2/5] retrigger CI --- python/mxnet/contrib/onnx/mx2onnx/_op_translations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py index 4060d4aa470f..52b520d6f3b1 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py +++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py @@ -352,7 +352,7 @@ def convert_batchnorm(node, **kwargs): momentum=momentum, # MXNet computes mean and variance per channel for batchnorm # Default for onnx is across all spatial features. Explicitly encoding - # spatial=1 for ONNX opset 8 and below. + # spatial=1 for ONNX opset 8 and below. spatial=1 ) return [bn_node] From 33fb1bdb4a47e3032bd681f961ada0134695ae98 Mon Sep 17 00:00:00 2001 From: vinitra Date: Wed, 4 Mar 2020 11:50:06 -0800 Subject: [PATCH 3/5] fixing broken pylint --- python/mxnet/contrib/onnx/mx2onnx/_op_translations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py index 52b520d6f3b1..4060d4aa470f 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py +++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py @@ -352,7 +352,7 @@ def convert_batchnorm(node, **kwargs): momentum=momentum, # MXNet computes mean and variance per channel for batchnorm # Default for onnx is across all spatial features. Explicitly encoding - # spatial=1 for ONNX opset 8 and below. + # spatial=1 for ONNX opset 8 and below. spatial=1 ) return [bn_node] From 04efda74e1ad94c14bda2a7923d7a08a227f36ce Mon Sep 17 00:00:00 2001 From: vinitra Date: Wed, 4 Mar 2020 15:57:31 -0800 Subject: [PATCH 4/5] retrigger build --- python/mxnet/contrib/onnx/mx2onnx/_op_translations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py index 4060d4aa470f..69974b4aae89 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py +++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py @@ -352,7 +352,7 @@ def convert_batchnorm(node, **kwargs): momentum=momentum, # MXNet computes mean and variance per channel for batchnorm # Default for onnx is across all spatial features. Explicitly encoding - # spatial=1 for ONNX opset 8 and below. + # spatial as 1 for ONNX opset 8 and below. spatial=1 ) return [bn_node] From 7acdf45ec59dc4c1b7bfed76f24a83b62ec28f64 Mon Sep 17 00:00:00 2001 From: vinitra Date: Fri, 6 Mar 2020 09:49:48 -0800 Subject: [PATCH 5/5] deprecating spatial attribute in exporter so default behavior of spatial=1 is conveyed --- python/mxnet/contrib/onnx/mx2onnx/_op_translations.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py index 69974b4aae89..b1ab40e1bf02 100644 --- a/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py +++ b/python/mxnet/contrib/onnx/mx2onnx/_op_translations.py @@ -349,11 +349,11 @@ def convert_batchnorm(node, **kwargs): [name], name=name, epsilon=eps, - momentum=momentum, - # MXNet computes mean and variance per channel for batchnorm - # Default for onnx is across all spatial features. Explicitly encoding - # spatial as 1 for ONNX opset 8 and below. - spatial=1 + momentum=momentum + # MXNet computes mean and variance per channel for batchnorm. + # Default for onnx is across all spatial features. Relying on default + # ONNX behavior of spatial=1 for ONNX opset 8 and below. As the spatial + # attribute is deprecated in opset 9 and above, not explicitly encoding it. ) return [bn_node]