Ejemplo n.º 1
0
    def __init__(self,
                 in_channels,
                 out_channels,
                 kernel_size,
                 stride=1,
                 groups=1,
                 is_vd_mode=False,
                 act=None,
                 name=None, ):
        super(ConvBNLayer, self).__init__()

        self.is_vd_mode = is_vd_mode
        self.act = act
        self._pool2d_avg = nn.AvgPool2d(
            kernel_size=2, stride=2, padding=0, ceil_mode=True)
        self._conv = nn.Conv2d(
            in_channels=in_channels,
            out_channels=out_channels,
            kernel_size=kernel_size,
            stride=stride,
            padding=(kernel_size - 1) // 2,
            groups=groups,
            bias=False)
        if name == "conv1":
            bn_name = "bn_" + name
        else:
            bn_name = "bn" + name[3:]
        self._batch_norm = nn.BatchNorm2d(
            out_channels,
            track_running_stats=True,
            )

        if act is not None:
            self._act = Activation(act_type=act, inplace=True)
Ejemplo n.º 2
0
    def __init__(self,
                 in_channels,
                 out_channels,
                 kernel_size,
                 stride,
                 groups=1,
                 if_act=True,
                 act=None,
                 name=None):
        super(ConvBNLayer, self).__init__()
        self.if_act = if_act

        self.conv = nn.Conv2d(
            in_channels=in_channels,
            out_channels=out_channels,
            kernel_size=kernel_size,
            stride=stride,
            padding=(kernel_size - 1) // 2,
            groups=groups,
            bias=False)

        self.bn = nn.BatchNorm2d(
            out_channels,)
        self.act = act
        if act is not None:
            self._act = Activation(act)
Ejemplo n.º 3
0
    def __init__(self,
                 in_channels,
                 out_channels,
                 kernel_size=4,
                 stride=2,
                 padding=1,
                 groups=1,
                 if_act=True,
                 act=None,
                 name=None):
        super(DeConvBNLayer, self).__init__()

        self.if_act = if_act
        self.act = act
        self.deconv = nn.ConvTranspose2d(in_channels=in_channels,
                                         out_channels=out_channels,
                                         kernel_size=kernel_size,
                                         stride=stride,
                                         padding=padding,
                                         groups=groups,
                                         bias=False)
        self.bn = nn.BatchNorm2d(out_channels)
        self.act = act
        if self.act is not None:
            self._act = Activation(act_type=self.act, inplace=True)
Ejemplo n.º 4
0
 def __init__(self, in_channels, reduction=4, name=""):
     super(SEModule, self).__init__()
     self.avg_pool = nn.AdaptiveAvgPool2d(1)
     self.conv1 = nn.Conv2d(in_channels=in_channels,
                            out_channels=in_channels // reduction,
                            kernel_size=1,
                            stride=1,
                            padding=0,
                            bias=True)
     self.relu1 = Activation(act_type='relu', inplace=True)
     self.conv2 = nn.Conv2d(in_channels=in_channels // reduction,
                            out_channels=in_channels,
                            kernel_size=1,
                            stride=1,
                            padding=0,
                            bias=True)
     self.hard_sigmoid = Activation(act_type='hard_sigmoid', inplace=True)
Ejemplo n.º 5
0
    def __init__(self, in_channels, **kwargs):
        super(Head, self).__init__()
        self.conv1 = nn.Conv2d(in_channels=in_channels,
                               out_channels=in_channels // 4,
                               kernel_size=3,
                               padding=1,
                               bias=False)
        self.conv_bn1 = nn.BatchNorm2d(in_channels // 4)
        self.relu1 = Activation(act_type='relu')

        self.conv2 = nn.ConvTranspose2d(in_channels=in_channels // 4,
                                        out_channels=in_channels // 4,
                                        kernel_size=2,
                                        stride=2)
        self.conv_bn2 = nn.BatchNorm2d(in_channels // 4)
        self.relu2 = Activation(act_type='relu')

        self.conv3 = nn.ConvTranspose2d(in_channels=in_channels // 4,
                                        out_channels=1,
                                        kernel_size=2,
                                        stride=2)