From d51cbb6e33b27524d9dfa62bc1705656f4d8ab8b Mon Sep 17 00:00:00 2001 From: zhaojichen Date: Sun, 26 Apr 2020 22:25:48 -0400 Subject: [PATCH 1/4] fix doc problems --- mindspore/nn/layer/normalization.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mindspore/nn/layer/normalization.py b/mindspore/nn/layer/normalization.py index 09a0b4bb27a..644604d6041 100644 --- a/mindspore/nn/layer/normalization.py +++ b/mindspore/nn/layer/normalization.py @@ -324,7 +324,7 @@ class GlobalBatchNorm(_BatchNorm): Args: num_features (int): `C` from an expected input of size (N, C, H, W). - device_num_each_group (int): The number of device in each group. + device_num_each_group (int): The number of devices in each group. eps (float): A value added to the denominator for numerical stability. Default: 1e-5. momentum (float): A floating hyperparameter of the momentum for the running_mean and running_var computation. Default: 0.9. @@ -350,7 +350,7 @@ class GlobalBatchNorm(_BatchNorm): Tensor, the normalized, scaled, offset tensor, of shape :math:`(N, C_{out}, H_{out}, W_{out})`. Examples: - >>> global_bn_op = nn.GlobalBatchNorm(num_features=3, group=4) + >>> global_bn_op = nn.GlobalBatchNorm(num_features=3, device_num_each_group=4) >>> input = Tensor(np.random.randint(0, 255, [1, 3, 224, 224]), mindspore.float32) >>> global_bn_op(input) """ From 4a79dde736f5323d4c13d84199e80cc08d7af7b4 Mon Sep 17 00:00:00 2001 From: zhaojichen Date: Sun, 26 Apr 2020 23:33:24 -0400 Subject: [PATCH 2/4] fix doc problems --- mindspore/nn/layer/normalization.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mindspore/nn/layer/normalization.py b/mindspore/nn/layer/normalization.py index 644604d6041..5faf046d185 100644 --- a/mindspore/nn/layer/normalization.py +++ b/mindspore/nn/layer/normalization.py @@ -17,6 +17,7 @@ from mindspore.ops import operations as P from mindspore.ops import functional as F from mindspore.common.parameter import Parameter from mindspore.common.initializer import initializer +from mindspore.ops.primitive import constexpr from mindspore.common.tensor import Tensor import mindspore.common.dtype as mstype import mindspore.context as context @@ -165,7 +166,9 @@ class _BatchNorm(Cell): def extend_repr(self): return 'num_features={}, eps={}, momentum={}, gamma={}, beta={}, moving_mean={}, moving_variance={}'.format( self.num_features, self.eps, self.momentum, self.gamma, self.beta, self.moving_mean, self.moving_variance) - +def _channel_check(channel, num_channel): + if channel != num_channel: + raise ValueError("the input channel is not equal with num_channels") class BatchNorm1d(_BatchNorm): r""" @@ -508,6 +511,7 @@ class GroupNorm(Cell): def construct(self, x): batch, channel, height, width = self.shape(x) + _channel_check(channel, self.num_channels) x = self.reshape(x, (batch, self.num_groups, channel*height*width/self.num_groups)) mean = self.reduce_mean(x, 2) var = self.reduce_sum(self.square(x - mean), 2) / (channel * height * width / self.num_groups - 1) From e49cd12d925cc0c15228b031919034cf34006099 Mon Sep 17 00:00:00 2001 From: zhaojichen Date: Sun, 26 Apr 2020 23:49:17 -0400 Subject: [PATCH 3/4] fix doc problems --- mindspore/nn/layer/normalization.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mindspore/nn/layer/normalization.py b/mindspore/nn/layer/normalization.py index 5faf046d185..ffde5cececc 100644 --- a/mindspore/nn/layer/normalization.py +++ b/mindspore/nn/layer/normalization.py @@ -166,6 +166,8 @@ class _BatchNorm(Cell): def extend_repr(self): return 'num_features={}, eps={}, momentum={}, gamma={}, beta={}, moving_mean={}, moving_variance={}'.format( self.num_features, self.eps, self.momentum, self.gamma, self.beta, self.moving_mean, self.moving_variance) + +@constexpr def _channel_check(channel, num_channel): if channel != num_channel: raise ValueError("the input channel is not equal with num_channels") From 89b797ae864b6dd98ff2f9d79ccb3707a334ad10 Mon Sep 17 00:00:00 2001 From: zhaojichen Date: Mon, 27 Apr 2020 02:55:56 -0400 Subject: [PATCH 4/4] fix doc problems --- mindspore/nn/layer/normalization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mindspore/nn/layer/normalization.py b/mindspore/nn/layer/normalization.py index ffde5cececc..d0bafec55ce 100644 --- a/mindspore/nn/layer/normalization.py +++ b/mindspore/nn/layer/normalization.py @@ -170,7 +170,7 @@ class _BatchNorm(Cell): @constexpr def _channel_check(channel, num_channel): if channel != num_channel: - raise ValueError("the input channel is not equal with num_channels") + raise ValueError("the input channel is not equal with num_channel") class BatchNorm1d(_BatchNorm): r"""