From 36b48e9eb9e8f05bf3a95bdaca9342d30581f209 Mon Sep 17 00:00:00 2001 From: wangguanzhong Date: Wed, 28 Jul 2021 15:21:50 +0800 Subject: [PATCH] clean param name (#3799) --- ppdet/modeling/backbones/blazenet.py | 17 +++----------- ppdet/modeling/backbones/ghostnet.py | 14 ++++------- ppdet/modeling/backbones/hrnet.py | 26 ++++++--------------- ppdet/modeling/backbones/mobilenet_v3.py | 26 +++++---------------- ppdet/modeling/backbones/vgg.py | 9 ++------ ppdet/modeling/heads/fcos_head.py | 27 +++++++--------------- ppdet/modeling/necks/blazeface_fpn.py | 17 +++----------- ppdet/modeling/necks/hrfpn.py | 4 ---- ppdet/modeling/reid/jde_embedding_head.py | 4 +--- ppdet/modeling/reid/pyramidal_embedding.py | 10 +++----- ppdet/modeling/reid/resnet.py | 14 ++--------- 11 files changed, 39 insertions(+), 129 deletions(-) diff --git a/ppdet/modeling/backbones/blazenet.py b/ppdet/modeling/backbones/blazenet.py index b8e040804..425f2a86e 100644 --- a/ppdet/modeling/backbones/blazenet.py +++ b/ppdet/modeling/backbones/blazenet.py @@ -55,25 +55,14 @@ class ConvBNLayer(nn.Layer): padding=padding, groups=num_groups, weight_attr=ParamAttr( - learning_rate=conv_lr, - initializer=KaimingNormal(), - name=name + "_weights"), + learning_rate=conv_lr, initializer=KaimingNormal()), bias_attr=False) - param_attr = ParamAttr(name=name + "_bn_scale") - bias_attr = ParamAttr(name=name + "_bn_offset") if norm_type == 'sync_bn': - self._batch_norm = nn.SyncBatchNorm( - out_channels, weight_attr=param_attr, bias_attr=bias_attr) + self._batch_norm = nn.SyncBatchNorm(out_channels) else: self._batch_norm = nn.BatchNorm( - out_channels, - act=None, - param_attr=param_attr, - bias_attr=bias_attr, - use_global_stats=False, - moving_mean_name=name + '_bn_mean', - moving_variance_name=name + '_bn_variance') + out_channels, act=None, use_global_stats=False) def forward(self, x): x = self._conv(x) diff --git a/ppdet/modeling/backbones/ghostnet.py b/ppdet/modeling/backbones/ghostnet.py index 91fa43d18..cd333b4fe 100644 --- a/ppdet/modeling/backbones/ghostnet.py +++ b/ppdet/modeling/backbones/ghostnet.py @@ -100,21 +100,15 @@ class SEBlock(nn.Layer): num_channels, med_ch, weight_attr=ParamAttr( - learning_rate=lr_mult, - initializer=Uniform(-stdv, stdv), - name=name + "_1_weights"), - bias_attr=ParamAttr( - learning_rate=lr_mult, name=name + "_1_offset")) + learning_rate=lr_mult, initializer=Uniform(-stdv, stdv)), + bias_attr=ParamAttr(learning_rate=lr_mult)) stdv = 1.0 / math.sqrt(med_ch * 1.0) self.excitation = Linear( med_ch, num_channels, weight_attr=ParamAttr( - learning_rate=lr_mult, - initializer=Uniform(-stdv, stdv), - name=name + "_2_weights"), - bias_attr=ParamAttr( - learning_rate=lr_mult, name=name + "_2_offset")) + learning_rate=lr_mult, initializer=Uniform(-stdv, stdv)), + bias_attr=ParamAttr(learning_rate=lr_mult)) def forward(self, inputs): pool = self.pool2d_gap(inputs) diff --git a/ppdet/modeling/backbones/hrnet.py b/ppdet/modeling/backbones/hrnet.py index b74002cec..62f94002f 100644 --- a/ppdet/modeling/backbones/hrnet.py +++ b/ppdet/modeling/backbones/hrnet.py @@ -51,31 +51,23 @@ class ConvNormLayer(nn.Layer): stride=stride, padding=(filter_size - 1) // 2, groups=1, - weight_attr=ParamAttr( - name=name + "_weights", initializer=Normal( - mean=0., std=0.01)), + weight_attr=ParamAttr(initializer=Normal( + mean=0., std=0.01)), bias_attr=False) norm_lr = 0. if freeze_norm else 1. - norm_name = name + '_bn' param_attr = ParamAttr( - name=norm_name + "_scale", - learning_rate=norm_lr, - regularizer=L2Decay(norm_decay)) + learning_rate=norm_lr, regularizer=L2Decay(norm_decay)) bias_attr = ParamAttr( - name=norm_name + "_offset", - learning_rate=norm_lr, - regularizer=L2Decay(norm_decay)) + learning_rate=norm_lr, regularizer=L2Decay(norm_decay)) global_stats = True if freeze_norm else False if norm_type in ['bn', 'sync_bn']: self.norm = nn.BatchNorm( ch_out, param_attr=param_attr, bias_attr=bias_attr, - use_global_stats=global_stats, - moving_mean_name=norm_name + '_mean', - moving_variance_name=norm_name + '_variance') + use_global_stats=global_stats) elif norm_type == 'gn': self.norm = nn.GroupNorm( num_groups=norm_groups, @@ -375,17 +367,13 @@ class SELayer(nn.Layer): self.squeeze = Linear( num_channels, med_ch, - weight_attr=ParamAttr( - initializer=Uniform(-stdv, stdv), name=name + "_sqz_weights"), - bias_attr=ParamAttr(name=name + '_sqz_offset')) + weight_attr=ParamAttr(initializer=Uniform(-stdv, stdv))) stdv = 1.0 / math.sqrt(med_ch * 1.0) self.excitation = Linear( med_ch, num_filters, - weight_attr=ParamAttr( - initializer=Uniform(-stdv, stdv), name=name + "_exc_weights"), - bias_attr=ParamAttr(name=name + '_exc_offset')) + weight_attr=ParamAttr(initializer=Uniform(-stdv, stdv))) def forward(self, input): pool = self.pool2d_gap(input) diff --git a/ppdet/modeling/backbones/mobilenet_v3.py b/ppdet/modeling/backbones/mobilenet_v3.py index d7178c913..02021e87c 100644 --- a/ppdet/modeling/backbones/mobilenet_v3.py +++ b/ppdet/modeling/backbones/mobilenet_v3.py @@ -62,21 +62,17 @@ class ConvBNLayer(nn.Layer): padding=padding, groups=num_groups, weight_attr=ParamAttr( - learning_rate=lr_mult, - regularizer=L2Decay(conv_decay), - name=name + "_weights"), + learning_rate=lr_mult, regularizer=L2Decay(conv_decay)), bias_attr=False) norm_lr = 0. if freeze_norm else lr_mult param_attr = ParamAttr( learning_rate=norm_lr, regularizer=L2Decay(norm_decay), - name=name + "_bn_scale", trainable=False if freeze_norm else True) bias_attr = ParamAttr( learning_rate=norm_lr, regularizer=L2Decay(norm_decay), - name=name + "_bn_offset", trainable=False if freeze_norm else True) global_stats = True if freeze_norm else False if norm_type == 'sync_bn': @@ -88,9 +84,7 @@ class ConvBNLayer(nn.Layer): act=None, param_attr=param_attr, bias_attr=bias_attr, - use_global_stats=global_stats, - moving_mean_name=name + '_bn_mean', - moving_variance_name=name + '_bn_variance') + use_global_stats=global_stats) norm_params = self.bn.parameters() if freeze_norm: for param in norm_params: @@ -203,13 +197,9 @@ class SEModule(nn.Layer): stride=1, padding=0, weight_attr=ParamAttr( - learning_rate=lr_mult, - regularizer=L2Decay(conv_decay), - name=name + "_1_weights"), + learning_rate=lr_mult, regularizer=L2Decay(conv_decay)), bias_attr=ParamAttr( - learning_rate=lr_mult, - regularizer=L2Decay(conv_decay), - name=name + "_1_offset")) + learning_rate=lr_mult, regularizer=L2Decay(conv_decay))) self.conv2 = nn.Conv2D( in_channels=mid_channels, out_channels=channel, @@ -217,13 +207,9 @@ class SEModule(nn.Layer): stride=1, padding=0, weight_attr=ParamAttr( - learning_rate=lr_mult, - regularizer=L2Decay(conv_decay), - name=name + "_2_weights"), + learning_rate=lr_mult, regularizer=L2Decay(conv_decay)), bias_attr=ParamAttr( - learning_rate=lr_mult, - regularizer=L2Decay(conv_decay), - name=name + "_2_offset")) + learning_rate=lr_mult, regularizer=L2Decay(conv_decay))) def forward(self, inputs): outputs = self.avg_pool(inputs) diff --git a/ppdet/modeling/backbones/vgg.py b/ppdet/modeling/backbones/vgg.py index 9311efa23..e05753209 100755 --- a/ppdet/modeling/backbones/vgg.py +++ b/ppdet/modeling/backbones/vgg.py @@ -30,9 +30,7 @@ class ConvBlock(nn.Layer): out_channels=out_channels, kernel_size=3, stride=1, - padding=1, - weight_attr=ParamAttr(name=name + "1_weights"), - bias_attr=ParamAttr(name=name + "1_bias")) + padding=1) self.conv_out_list = [] for i in range(1, groups): conv_out = self.add_sublayer( @@ -42,10 +40,7 @@ class ConvBlock(nn.Layer): out_channels=out_channels, kernel_size=3, stride=1, - padding=1, - weight_attr=ParamAttr( - name=name + "{}_weights".format(i + 1)), - bias_attr=ParamAttr(name=name + "{}_bias".format(i + 1)))) + padding=1)) self.conv_out_list.append(conv_out) self.pool = MaxPool2D( diff --git a/ppdet/modeling/heads/fcos_head.py b/ppdet/modeling/heads/fcos_head.py index 3b8fd7f78..1d61feed6 100644 --- a/ppdet/modeling/heads/fcos_head.py +++ b/ppdet/modeling/heads/fcos_head.py @@ -151,12 +151,9 @@ class FCOSHead(nn.Layer): kernel_size=3, stride=1, padding=1, - weight_attr=ParamAttr( - name=conv_cls_name + "_weights", - initializer=Normal( - mean=0., std=0.01)), + weight_attr=ParamAttr(initializer=Normal( + mean=0., std=0.01)), bias_attr=ParamAttr( - name=conv_cls_name + "_bias", initializer=Constant(value=bias_init_value)))) conv_reg_name = "fcos_head_reg" @@ -168,13 +165,9 @@ class FCOSHead(nn.Layer): kernel_size=3, stride=1, padding=1, - weight_attr=ParamAttr( - name=conv_reg_name + "_weights", - initializer=Normal( - mean=0., std=0.01)), - bias_attr=ParamAttr( - name=conv_reg_name + "_bias", - initializer=Constant(value=0)))) + weight_attr=ParamAttr(initializer=Normal( + mean=0., std=0.01)), + bias_attr=ParamAttr(initializer=Constant(value=0)))) conv_centerness_name = "fcos_head_centerness" self.fcos_head_centerness = self.add_sublayer( @@ -185,13 +178,9 @@ class FCOSHead(nn.Layer): kernel_size=3, stride=1, padding=1, - weight_attr=ParamAttr( - name=conv_centerness_name + "_weights", - initializer=Normal( - mean=0., std=0.01)), - bias_attr=ParamAttr( - name=conv_centerness_name + "_bias", - initializer=Constant(value=0)))) + weight_attr=ParamAttr(initializer=Normal( + mean=0., std=0.01)), + bias_attr=ParamAttr(initializer=Constant(value=0)))) self.scales_regs = [] for i in range(len(self.fpn_stride)): diff --git a/ppdet/modeling/necks/blazeface_fpn.py b/ppdet/modeling/necks/blazeface_fpn.py index c992e0408..18d7f3cf1 100644 --- a/ppdet/modeling/necks/blazeface_fpn.py +++ b/ppdet/modeling/necks/blazeface_fpn.py @@ -51,25 +51,14 @@ class ConvBNLayer(nn.Layer): padding=padding, groups=num_groups, weight_attr=ParamAttr( - learning_rate=conv_lr, - initializer=KaimingNormal(), - name=name + "_weights"), + learning_rate=conv_lr, initializer=KaimingNormal()), bias_attr=False) - param_attr = ParamAttr(name=name + "_bn_scale") - bias_attr = ParamAttr(name=name + "_bn_offset") if norm_type == 'sync_bn': - self._batch_norm = nn.SyncBatchNorm( - out_channels, weight_attr=param_attr, bias_attr=bias_attr) + self._batch_norm = nn.SyncBatchNorm(out_channels) else: self._batch_norm = nn.BatchNorm( - out_channels, - act=None, - param_attr=param_attr, - bias_attr=bias_attr, - use_global_stats=False, - moving_mean_name=name + '_bn_mean', - moving_variance_name=name + '_bn_variance') + out_channels, act=None, use_global_stats=False) def forward(self, x): x = self._conv(x) diff --git a/ppdet/modeling/necks/hrfpn.py b/ppdet/modeling/necks/hrfpn.py index 8df7cb1d6..eb4768b8e 100644 --- a/ppdet/modeling/necks/hrfpn.py +++ b/ppdet/modeling/necks/hrfpn.py @@ -14,7 +14,6 @@ import paddle import paddle.nn.functional as F -from paddle import ParamAttr import paddle.nn as nn from ppdet.core.workspace import register from ..shape_spec import ShapeSpec @@ -53,7 +52,6 @@ class HRFPN(nn.Layer): in_channels=in_channel, out_channels=out_channel, kernel_size=1, - weight_attr=ParamAttr(name='hrfpn_reduction_weights'), bias_attr=False) if share_conv: @@ -62,7 +60,6 @@ class HRFPN(nn.Layer): out_channels=out_channel, kernel_size=3, padding=1, - weight_attr=ParamAttr(name='fpn_conv_weights'), bias_attr=False) else: self.fpn_conv = [] @@ -75,7 +72,6 @@ class HRFPN(nn.Layer): out_channels=out_channel, kernel_size=3, padding=1, - weight_attr=ParamAttr(name=conv_name + "_weights"), bias_attr=False)) self.fpn_conv.append(conv) diff --git a/ppdet/modeling/reid/jde_embedding_head.py b/ppdet/modeling/reid/jde_embedding_head.py index 0935e3949..c3a5584e2 100644 --- a/ppdet/modeling/reid/jde_embedding_head.py +++ b/ppdet/modeling/reid/jde_embedding_head.py @@ -92,9 +92,7 @@ class JDEEmbeddingHead(nn.Layer): kernel_size=3, stride=1, padding=1, - weight_attr=ParamAttr(name=name + '.conv.weights'), - bias_attr=ParamAttr( - name=name + '.conv.bias', regularizer=L2Decay(0.)))) + bias_attr=ParamAttr(regularizer=L2Decay(0.)))) self.identify_outputs.append(identify_output) loss_p_cls = self.add_sublayer('cls.{}'.format(i), LossParam(-4.15)) diff --git a/ppdet/modeling/reid/pyramidal_embedding.py b/ppdet/modeling/reid/pyramidal_embedding.py index f099a9655..10bb92b4c 100644 --- a/ppdet/modeling/reid/pyramidal_embedding.py +++ b/ppdet/modeling/reid/pyramidal_embedding.py @@ -89,16 +89,12 @@ class PCBPyramid(nn.Layer): if idx_branches >= sum(self.num_in_each_level[0:idx_levels + 1]): idx_levels += 1 - name = "Linear_branch_id_{}".format(idx_branches) fc = nn.Linear( in_features=num_conv_out_channels, out_features=self.num_classes, - weight_attr=ParamAttr( - name=name + "_weights", - initializer=Normal( - mean=0., std=0.001)), - bias_attr=ParamAttr( - name=name + "_bias", initializer=Constant(value=0.))) + weight_attr=ParamAttr(initializer=Normal( + mean=0., std=0.001)), + bias_attr=ParamAttr(initializer=Constant(value=0.))) pyramid_fc_list.append(fc) return pyramid_conv_list, pyramid_fc_list diff --git a/ppdet/modeling/reid/resnet.py b/ppdet/modeling/reid/resnet.py index 02d70f737..968fe9774 100644 --- a/ppdet/modeling/reid/resnet.py +++ b/ppdet/modeling/reid/resnet.py @@ -50,23 +50,13 @@ class ConvBNLayer(nn.Layer): dilation=dilation, groups=groups, weight_attr=ParamAttr( - name=name + "_weights", learning_rate=lr_mult, initializer=Normal(0, math.sqrt(2. / conv_stdv))), bias_attr=False, data_format=data_format) - if name == "conv1": - bn_name = "bn_" + name - else: - bn_name = "bn" + name[3:] + self._batch_norm = nn.BatchNorm( - num_filters, - act=act, - param_attr=ParamAttr(name=bn_name + "_scale"), - bias_attr=ParamAttr(bn_name + "_offset"), - moving_mean_name=bn_name + "_mean", - moving_variance_name=bn_name + "_variance", - data_layout=data_format) + num_filters, act=act, data_layout=data_format) def forward(self, inputs): y = self._conv(inputs) -- GitLab