!5396 fix googlenet performance

Merge pull request !5396 from panfengfeng/fix_googlenet_performance
This commit is contained in:
mindspore-ci-bot 2020-08-28 11:48:05 +08:00 committed by Gitee
commit d24af4b181
1 changed files with 10 additions and 12 deletions

View File

@ -63,7 +63,7 @@ class Inception(nn.Cell):
Conv2dBlock(n3x3red, n3x3, kernel_size=3, padding=0)]) Conv2dBlock(n3x3red, n3x3, kernel_size=3, padding=0)])
self.b3 = nn.SequentialCell([Conv2dBlock(in_channels, n5x5red, kernel_size=1), self.b3 = nn.SequentialCell([Conv2dBlock(in_channels, n5x5red, kernel_size=1),
Conv2dBlock(n5x5red, n5x5, kernel_size=3, padding=0)]) Conv2dBlock(n5x5red, n5x5, kernel_size=3, padding=0)])
self.maxpool = P.MaxPoolWithArgmax(ksize=3, strides=1, padding="same") self.maxpool = nn.MaxPool2d(kernel_size=3, stride=1, pad_mode="same")
self.b4 = Conv2dBlock(in_channels, pool_planes, kernel_size=1) self.b4 = Conv2dBlock(in_channels, pool_planes, kernel_size=1)
self.concat = P.Concat(axis=1) self.concat = P.Concat(axis=1)
@ -71,9 +71,8 @@ class Inception(nn.Cell):
branch1 = self.b1(x) branch1 = self.b1(x)
branch2 = self.b2(x) branch2 = self.b2(x)
branch3 = self.b3(x) branch3 = self.b3(x)
cell, argmax = self.maxpool(x) cell = self.maxpool(x)
branch4 = self.b4(cell) branch4 = self.b4(cell)
_ = argmax
return self.concat((branch1, branch2, branch3, branch4)) return self.concat((branch1, branch2, branch3, branch4))
@ -85,22 +84,22 @@ class GoogleNet(nn.Cell):
def __init__(self, num_classes): def __init__(self, num_classes):
super(GoogleNet, self).__init__() super(GoogleNet, self).__init__()
self.conv1 = Conv2dBlock(3, 64, kernel_size=7, stride=2, padding=0) self.conv1 = Conv2dBlock(3, 64, kernel_size=7, stride=2, padding=0)
self.maxpool1 = P.MaxPoolWithArgmax(ksize=3, strides=2, padding="same") self.maxpool1 = nn.MaxPool2d(kernel_size=3, stride=2, pad_mode="same")
self.conv2 = Conv2dBlock(64, 64, kernel_size=1) self.conv2 = Conv2dBlock(64, 64, kernel_size=1)
self.conv3 = Conv2dBlock(64, 192, kernel_size=3, padding=0) self.conv3 = Conv2dBlock(64, 192, kernel_size=3, padding=0)
self.maxpool2 = P.MaxPoolWithArgmax(ksize=3, strides=2, padding="same") self.maxpool2 = nn.MaxPool2d(kernel_size=3, stride=2, pad_mode="same")
self.block3a = Inception(192, 64, 96, 128, 16, 32, 32) self.block3a = Inception(192, 64, 96, 128, 16, 32, 32)
self.block3b = Inception(256, 128, 128, 192, 32, 96, 64) self.block3b = Inception(256, 128, 128, 192, 32, 96, 64)
self.maxpool3 = P.MaxPoolWithArgmax(ksize=3, strides=2, padding="same") self.maxpool3 = nn.MaxPool2d(kernel_size=3, stride=2, pad_mode="same")
self.block4a = Inception(480, 192, 96, 208, 16, 48, 64) self.block4a = Inception(480, 192, 96, 208, 16, 48, 64)
self.block4b = Inception(512, 160, 112, 224, 24, 64, 64) self.block4b = Inception(512, 160, 112, 224, 24, 64, 64)
self.block4c = Inception(512, 128, 128, 256, 24, 64, 64) self.block4c = Inception(512, 128, 128, 256, 24, 64, 64)
self.block4d = Inception(512, 112, 144, 288, 32, 64, 64) self.block4d = Inception(512, 112, 144, 288, 32, 64, 64)
self.block4e = Inception(528, 256, 160, 320, 32, 128, 128) self.block4e = Inception(528, 256, 160, 320, 32, 128, 128)
self.maxpool4 = P.MaxPoolWithArgmax(ksize=2, strides=2, padding="same") self.maxpool4 = nn.MaxPool2d(kernel_size=2, stride=2, pad_mode="same")
self.block5a = Inception(832, 256, 160, 320, 32, 128, 128) self.block5a = Inception(832, 256, 160, 320, 32, 128, 128)
self.block5b = Inception(832, 384, 192, 384, 48, 128, 128) self.block5b = Inception(832, 384, 192, 384, 48, 128, 128)
@ -114,22 +113,22 @@ class GoogleNet(nn.Cell):
def construct(self, x): def construct(self, x):
x = self.conv1(x) x = self.conv1(x)
x, argmax = self.maxpool1(x) x = self.maxpool1(x)
x = self.conv2(x) x = self.conv2(x)
x = self.conv3(x) x = self.conv3(x)
x, argmax = self.maxpool2(x) x = self.maxpool2(x)
x = self.block3a(x) x = self.block3a(x)
x = self.block3b(x) x = self.block3b(x)
x, argmax = self.maxpool3(x) x = self.maxpool3(x)
x = self.block4a(x) x = self.block4a(x)
x = self.block4b(x) x = self.block4b(x)
x = self.block4c(x) x = self.block4c(x)
x = self.block4d(x) x = self.block4d(x)
x = self.block4e(x) x = self.block4e(x)
x, argmax = self.maxpool4(x) x = self.maxpool4(x)
x = self.block5a(x) x = self.block5a(x)
x = self.block5b(x) x = self.block5b(x)
@ -138,5 +137,4 @@ class GoogleNet(nn.Cell):
x = self.flatten(x) x = self.flatten(x)
x = self.classifier(x) x = self.classifier(x)
_ = argmax
return x return x