diff --git a/ppdet/modeling/backbones/blazenet.py b/ppdet/modeling/backbones/blazenet.py index b8e04080461d23557330e9bed774838e449dfd1b..425f2a86eb4c1a87ecbb8c0c40a169ce95d39223 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 91fa43d186d4034b1007250e589bb9c65d3414bb..cd333b4fe0f23be4df85974a7af5744d9641a1e7 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 b74002cec82e5246c13db99be25e19098d45f001..62f94002fd8ab37d11e40d5cd72ab0219415f317 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 d7178c9132e214392d3ad8d4cd70b7a4854c8c4e..02021e87c036fbc1bc20f8a27eed1f6d964c7738 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 9311efa238296cb111f5fd5b92e758c7ea524c76..e05753209a6235a33101fda669979990c3b225f0 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 3b8fd7f785d77ee8c18576cc4d7d71b44e86c509..1d61feed60334cffd5f82f4bcb99ad0fdd14e3c9 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 c992e04083dc9d3ee47b239c71921785a5663317..18d7f3cf19cb4eea5728698cd03362cec548a5d1 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 8df7cb1d68e1c73b64e04e76384f243ba98cb80f..eb4768b8ecba7c11dcd834265e1289db8d6ec7b0 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 0935e3949e0fdecba83dcd2180850f99c0a8213d..c3a5584e216c0ba187136b150174c715ec268655 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 f099a9655cb8080088ee69a517ceb2b441b81c9b..10bb92b4cfafa7e916eb94f6a35a8c98e647e831 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 02d70f73777b496b011b8aedba8f886394d95e2a..968fe9774f116c846cd372c7086dc9671d135b7c 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)