def __init__(self, ch_in, ch_out, norm_type='bn'): super(DeConv, self).__init__() self.deconv = nn.Sequential() conv1 = ConvNormLayer(ch_in=ch_in, ch_out=ch_out, stride=1, filter_size=1, norm_type=norm_type, initializer=XavierUniform()) conv2 = nn.Conv2DTranspose( in_channels=ch_out, out_channels=ch_out, kernel_size=4, padding=1, stride=2, groups=ch_out, weight_attr=ParamAttr(initializer=XavierUniform()), bias_attr=False) bn = batch_norm(ch_out, norm_type=norm_type, norm_decay=0.) conv3 = ConvNormLayer(ch_in=ch_out, ch_out=ch_out, stride=1, filter_size=1, norm_type=norm_type, initializer=XavierUniform()) self.deconv.add_sublayer('conv1', conv1) self.deconv.add_sublayer('relu6_1', nn.ReLU6()) self.deconv.add_sublayer('conv2', conv2) self.deconv.add_sublayer('bn', bn) self.deconv.add_sublayer('relu6_2', nn.ReLU6()) self.deconv.add_sublayer('conv3', conv3) self.deconv.add_sublayer('relu6_3', nn.ReLU6())
def __init__(self, ch_in, ch_out, filter_size=3, stride=1, groups=1, padding=0, norm_type='bn', norm_decay=0., act="leaky", name=None): super(ConvBNLayer, self).__init__() self.conv = nn.Conv2D( in_channels=ch_in, out_channels=ch_out, kernel_size=filter_size, stride=stride, padding=padding, groups=groups, weight_attr=ParamAttr(name=name + '.conv.weights'), bias_attr=False) self.batch_norm = batch_norm( ch_out, norm_type=norm_type, norm_decay=norm_decay, name=name) self.act = act
def __init__(self, ch_in, ch_out, filter_size=3, stride=1, groups=1, padding=0, norm_type='bn', norm_decay=0., act="leaky", freeze_norm=False, data_format='NCHW', name=''): """ conv + bn + activation layer Args: ch_in (int): input channel ch_out (int): output channel filter_size (int): filter size, default 3 stride (int): stride, default 1 groups (int): number of groups of conv layer, default 1 padding (int): padding size, default 0 norm_type (str): batch norm type, default bn norm_decay (str): decay for weight and bias of batch norm layer, default 0. act (str): activation function type, default 'leaky', which means leaky_relu freeze_norm (bool): whether to freeze norm, default False data_format (str): data format, NCHW or NHWC """ super(ConvBNLayer, self).__init__() self.conv = nn.Conv2D( in_channels=ch_in, out_channels=ch_out, kernel_size=filter_size, stride=stride, padding=padding, groups=groups, data_format=data_format, bias_attr=False) self.batch_norm = batch_norm( ch_out, norm_type=norm_type, norm_decay=norm_decay, freeze_norm=freeze_norm, data_format=data_format) self.act = act
def __init__(self, ch_in, ch_out, norm_type='bn'): super(Upsample, self).__init__() fan_in = ch_in * 3 * 3 stdv = 1. / math.sqrt(fan_in) self.dcn = DeformableConvV2( ch_in, ch_out, kernel_size=3, weight_attr=ParamAttr(initializer=Uniform(-stdv, stdv)), bias_attr=ParamAttr(initializer=Constant(0), regularizer=L2Decay(0.), learning_rate=2.), lr_scale=2., regularizer=L2Decay(0.)) self.bn = batch_norm(ch_out, norm_type=norm_type, initializer=Constant(1.))