From 0b7de6968fe1dcbc9c78f292bdc2b673502b5f2c Mon Sep 17 00:00:00 2001 From: zhaojichen Date: Thu, 16 Apr 2020 01:56:12 -0400 Subject: [PATCH] Add Group Normalization --- mindspore/nn/layer/normalization.py | 4 ++-- tests/ut/python/nn/test_batchnorm.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mindspore/nn/layer/normalization.py b/mindspore/nn/layer/normalization.py index 58f926cdc..b286eaae1 100644 --- a/mindspore/nn/layer/normalization.py +++ b/mindspore/nn/layer/normalization.py @@ -346,7 +346,7 @@ class GroupNorm(Cell): self.sqrt = P.Sqrt() def construct(self, x): - batch, channel, height,width = self.shape(x) + batch, channel, height, width = self.shape(x) 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) @@ -359,4 +359,4 @@ class GroupNorm(Cell): def extend_repr(self): """Display instance object as string.""" s = 'num_groups={}, num_channels={}'.format(self.num_groups, self.num_channels) - return s \ No newline at end of file + return s diff --git a/tests/ut/python/nn/test_batchnorm.py b/tests/ut/python/nn/test_batchnorm.py index efccfa4b3..4bd8c996d 100644 --- a/tests/ut/python/nn/test_batchnorm.py +++ b/tests/ut/python/nn/test_batchnorm.py @@ -67,4 +67,4 @@ class GroupNet(nn.Cell): def test_compile_groupnorm(): net = nn.GroupNorm(16, 64) input_data = Tensor(np.random.rand(1,64,256,256).astype(np.float32)) - _executor.compile(net, input_data) \ No newline at end of file + _executor.compile(net, input_data) -- GitLab