From 07330e0e42c3d1461140d02b3c62cdf960a9e4fd Mon Sep 17 00:00:00 2001 From: littletomatodonkey <2120160898@bit.edu.cn> Date: Mon, 30 Nov 2020 12:52:58 +0800 Subject: [PATCH] fix resnest typo (#380) fix resnest, ghostnet typo --- .../{ShuffleNetV2.yaml => ShuffleNetV2_x1_0.yaml} | 2 +- ppcls/modeling/architectures/__init__.py | 3 +-- ppcls/modeling/architectures/ghostnet.py | 5 +---- ppcls/modeling/architectures/resnest.py | 14 +++++++------- ppcls/modeling/architectures/shufflenet_v2.py | 4 ++-- 5 files changed, 12 insertions(+), 16 deletions(-) rename configs/ShuffleNet/{ShuffleNetV2.yaml => ShuffleNetV2_x1_0.yaml} (98%) diff --git a/configs/ShuffleNet/ShuffleNetV2.yaml b/configs/ShuffleNet/ShuffleNetV2_x1_0.yaml similarity index 98% rename from configs/ShuffleNet/ShuffleNetV2.yaml rename to configs/ShuffleNet/ShuffleNetV2_x1_0.yaml index c097afae..f248cace 100644 --- a/configs/ShuffleNet/ShuffleNetV2.yaml +++ b/configs/ShuffleNet/ShuffleNetV2_x1_0.yaml @@ -1,6 +1,6 @@ mode: 'train' ARCHITECTURE: - name: "ShuffleNetV2" + name: "ShuffleNetV2_x1_0" pretrained_model: "" model_save_dir: "./output/" diff --git a/ppcls/modeling/architectures/__init__.py b/ppcls/modeling/architectures/__init__.py index 73d9646e..741bde96 100644 --- a/ppcls/modeling/architectures/__init__.py +++ b/ppcls/modeling/architectures/__init__.py @@ -32,14 +32,13 @@ from .ghostnet import GhostNet_x0_5, GhostNet_x1_0, GhostNet_x1_3 from .mobilenet_v1 import MobileNetV1_x0_25, MobileNetV1_x0_5, MobileNetV1_x0_75, MobileNetV1 from .mobilenet_v2 import MobileNetV2_x0_25, MobileNetV2_x0_5, MobileNetV2_x0_75, MobileNetV2, MobileNetV2_x1_5, MobileNetV2_x2_0 from .mobilenet_v3 import MobileNetV3_small_x0_35, MobileNetV3_small_x0_5, MobileNetV3_small_x0_75, MobileNetV3_small_x1_0, MobileNetV3_small_x1_25, MobileNetV3_large_x0_35, MobileNetV3_large_x0_5, MobileNetV3_large_x0_75, MobileNetV3_large_x1_0, MobileNetV3_large_x1_25 -from .shufflenet_v2 import ShuffleNetV2_x0_25, ShuffleNetV2_x0_33, ShuffleNetV2_x0_5, ShuffleNetV2, ShuffleNetV2_x1_5, ShuffleNetV2_x2_0, ShuffleNetV2_swish +from .shufflenet_v2 import ShuffleNetV2_x0_25, ShuffleNetV2_x0_33, ShuffleNetV2_x0_5, ShuffleNetV2_x1_0, ShuffleNetV2_x1_5, ShuffleNetV2_x2_0, ShuffleNetV2_swish from .alexnet import AlexNet from .inception_v3 import InceptionV3 from .inception_v4 import InceptionV4 from .xception import Xception41, Xception65, Xception71 from .xception_deeplab import Xception41_deeplab, Xception65_deeplab, Xception71_deeplab from .resnext101_wsl import ResNeXt101_32x8d_wsl, ResNeXt101_32x16d_wsl, ResNeXt101_32x32d_wsl, ResNeXt101_32x48d_wsl -from .shufflenet_v2 import ShuffleNetV2_x0_25, ShuffleNetV2_x0_33, ShuffleNetV2_x0_5, ShuffleNetV2, ShuffleNetV2_x1_5, ShuffleNetV2_x2_0, ShuffleNetV2_swish from .squeezenet import SqueezeNet1_0, SqueezeNet1_1 from .vgg import VGG11, VGG13, VGG16, VGG19 from .darknet import DarkNet53 diff --git a/ppcls/modeling/architectures/ghostnet.py b/ppcls/modeling/architectures/ghostnet.py index 090f0c44..6edd4184 100644 --- a/ppcls/modeling/architectures/ghostnet.py +++ b/ppcls/modeling/architectures/ghostnet.py @@ -44,7 +44,6 @@ class ConvBNLayer(nn.Layer): bias_attr=False) bn_name = name + "_bn" - # In the old version, moving_variance_name was name + "_variance" self._batch_norm = BatchNorm( num_channels=out_channels, act=act, @@ -53,9 +52,7 @@ class ConvBNLayer(nn.Layer): bias_attr=ParamAttr( name=bn_name + "_offset", regularizer=L2Decay(0.0)), moving_mean_name=bn_name + "_mean", - moving_variance_name=name + - "_variance" # wrong due to an old typo, will be fixed later. - ) + moving_variance_name=bn_name + "_variance") def forward(self, inputs): y = self._conv(inputs) diff --git a/ppcls/modeling/architectures/resnest.py b/ppcls/modeling/architectures/resnest.py index eb6f8bef..1a2984ff 100644 --- a/ppcls/modeling/architectures/resnest.py +++ b/ppcls/modeling/architectures/resnest.py @@ -120,7 +120,7 @@ class SplatConv(nn.Layer): stride=stride, groups=groups * radix, act="relu", - name=name + "_splat1") + name=name + "_1_weights") self.avg_pool2d = AdaptiveAvgPool2D(1) @@ -134,7 +134,7 @@ class SplatConv(nn.Layer): stride=1, groups=groups, act="relu", - name=name + "_splat2") + name=name + "_2_weights") # to calc atten self.conv3 = Conv2D( @@ -145,7 +145,7 @@ class SplatConv(nn.Layer): padding=0, groups=groups, weight_attr=ParamAttr( - name=name + "_splat_weights", initializer=KaimingNormal()), + name=name + "_weights", initializer=KaimingNormal()), bias_attr=False) self.rsoftmax = rSoftmax(radix=radix, cardinality=groups) @@ -233,7 +233,7 @@ class BottleneckBlock(nn.Layer): bias=False, radix=radix, rectify_avg=rectify_avg, - name=name + "_splatconv") + name=name + "_splat") else: self.conv2 = ConvBNLayer( num_channels=group_width, @@ -403,10 +403,10 @@ class ResNeStLayer(nn.Layer): self.inplanes = planes * 4 self.bottleneck_block_list = [bottleneck_func] for i in range(1, blocks): - name = name + "_bottleneck_" + str(i) + curr_name = name + "_bottleneck_" + str(i) bottleneck_func = self.add_sublayer( - name, + curr_name, BottleneckBlock( inplanes=self.inplanes, planes=planes, @@ -419,7 +419,7 @@ class ResNeStLayer(nn.Layer): dilation=dilation, rectify_avg=rectify_avg, last_gamma=last_gamma, - name=name)) + name=curr_name)) self.bottleneck_block_list.append(bottleneck_func) def forward(self, x): diff --git a/ppcls/modeling/architectures/shufflenet_v2.py b/ppcls/modeling/architectures/shufflenet_v2.py index e344a142..3eb2e006 100644 --- a/ppcls/modeling/architectures/shufflenet_v2.py +++ b/ppcls/modeling/architectures/shufflenet_v2.py @@ -23,7 +23,7 @@ from paddle.nn.functional import swish __all__ = [ "ShuffleNetV2_x0_25", "ShuffleNetV2_x0_33", "ShuffleNetV2_x0_5", - "ShuffleNetV2", "ShuffleNetV2_x1_5", "ShuffleNetV2_x2_0", + "ShuffleNetV2_x1_0", "ShuffleNetV2_x1_5", "ShuffleNetV2_x2_0", "ShuffleNetV2_swish" ] @@ -299,7 +299,7 @@ def ShuffleNetV2_x0_5(**args): return model -def ShuffleNetV2(**args): +def ShuffleNetV2_x1_0(**args): model = ShuffleNet(scale=1.0, **args) return model -- GitLab