未验证 提交 36b48e9e 编写于 作者: W wangguanzhong 提交者: GitHub

clean param name (#3799)

上级 4ea5b435
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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(
......
......@@ -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)):
......
......@@ -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)
......
......@@ -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)
......
......@@ -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))
......
......@@ -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
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册