Exemple #1
0
    def __init__(self,
                 inplanes,
                 planes,
                 dilation=1,
                 downsample=None,
                 norm_type="BN"):
        """Residual Block for DarkNet.

        This module has the dowsample layer (optional),
        1x1 conv layer and 3x3 conv layer.
        """
        super(DarkBlock, self).__init__()

        self.downsample = downsample

        self.bn1 = get_norm(norm_type, inplanes, eps=1e-4, momentum=0.03)
        self.bn2 = get_norm(norm_type, planes, eps=1e-4, momentum=0.03)

        self.conv1 = nn.Conv2d(planes,
                               inplanes,
                               kernel_size=1,
                               stride=1,
                               padding=0,
                               bias=False)

        self.conv2 = nn.Conv2d(inplanes,
                               planes,
                               kernel_size=3,
                               stride=1,
                               padding=dilation,
                               dilation=dilation,
                               bias=False)

        self.activation = Mish()
    def __init__(self, in_channels, out_channels, kernel_size, stride=1, activation=Mish()):
        super(Conv, self).__init__()

        self.conv = nn.Sequential(
            nn.Conv2d(in_channels, out_channels, kernel_size, stride, kernel_size//2, bias=False),
            nn.BatchNorm2d(out_channels),
            activation,
        )
Exemple #3
0
 def __init__(self, c1, c2, n=1, shortcut=False, g=1, e=0.5):  # ch_in, ch_out, number, shortcut, groups, expansion
     super(BottleneckCSP2, self).__init__()
     c_ = int(c2)  # hidden channels
     self.cv1 = Conv(c1, c_, 1, 1)
     self.cv2 = nn.Conv2d(c_, c_, 1, 1, bias=False)
     self.cv3 = Conv(2 * c_, c2, 1, 1)
     self.bn = nn.BatchNorm2d(2 * c_) 
     self.act = Mish()
     self.m = nn.Sequential(*[Bottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n)])
Exemple #4
0
 def _make_stem_layer(self):
     self.conv1 = nn.Conv2d(3,
                            self.inplanes,
                            kernel_size=3,
                            stride=1,
                            padding=1,
                            bias=False)
     self.bn1 = get_norm(self.norm_type,
                         self.inplanes,
                         eps=1e-4,
                         momentum=0.03)
     self.act1 = Mish()
Exemple #5
0
 def __init__(self, c1, c2, n=1, shortcut=False, g=1, e=0.5, k=(5, 9, 13)):
     super(SPPCSP, self).__init__()
     c_ = int(2 * c2 * e)  # hidden channels
     self.cv1 = Conv(c1, c_, 1, 1)
     self.cv2 = nn.Conv2d(c1, c_, 1, 1, bias=False)
     self.cv3 = Conv(c_, c_, 3, 1)
     self.cv4 = Conv(c_, c_, 1, 1)
     self.m = nn.ModuleList([nn.MaxPool2d(kernel_size=x, stride=1, padding=x // 2) for x in k])
     self.cv5 = Conv(4 * c_, c_, 1, 1)
     self.cv6 = Conv(c_, c_, 3, 1)
     self.bn = nn.BatchNorm2d(2 * c_) 
     self.act = Mish()
     self.cv7 = Conv(2 * c_, c2, 1, 1)
 def __init__(self,
              c1,
              c2,
              k=1,
              s=1,
              p=None,
              g=1,
              act=True):  # ch_in, ch_out, kernel, stride, padding, groups
     super(ConvSqu, self).__init__()
     self.conv = nn.Conv2d(c1,
                           c2,
                           k,
                           s,
                           autopad(k, p),
                           groups=g,
                           bias=False)
     self.act = Mish() if act else nn.Identity()
Exemple #7
0
 def __init__(
     self,
     c1,
     c2,
     n=1,
     shortcut=False,
     g=1,
     e=0.5,
     activation_type='hardswish',
 ):  # ch_in, ch_out, number, shortcut, groups, expansion
     super(BottleneckCSP2, self).__init__()
     Conv_ = functools.partial(Conv, activation_type=activation_type)
     Bottleneck_ = functools.partial(Bottleneck,
                                     activation_type=activation_type)
     c_ = int(c2)  # hidden channels
     self.cv1 = Conv_(c1, c_, 1, 1)
     self.cv2 = nn.Conv2d(c_, c_, 1, 1, bias=False)
     self.cv3 = Conv_(2 * c_, c2, 1, 1)
     self.bn = nn.BatchNorm2d(2 * c_)
     self.act = Mish()
     self.m = nn.Sequential(
         *[Bottleneck_(c_, c_, shortcut, g, e=1.0) for _ in range(n)])
Exemple #8
0
 def __init__(self,
              c1,
              c2,
              n=1,
              shortcut=False,
              g=1,
              e=0.5,
              k=(5, 9, 13),
              activation_type='hardswish'):
     super(SPPCSP, self).__init__()
     Conv_ = functools.partial(Conv, activation_type=activation_type)
     c_ = int(2 * c2 * e)  # hidden channels
     self.cv1 = Conv_(c1, c_, 1, 1)
     self.cv2 = nn.Conv2d(c1, c_, 1, 1, bias=False)
     self.cv3 = Conv_(c_, c_, 3, 1)
     self.cv4 = Conv_(c_, c_, 1, 1)
     self.m = nn.ModuleList(
         [nn.MaxPool2d(kernel_size=x, stride=1, padding=x // 2) for x in k])
     self.cv5 = Conv_(4 * c_, c_, 1, 1)
     self.cv6 = Conv_(c_, c_, 3, 1)
     self.bn = nn.BatchNorm2d(2 * c_)
     self.act = Mish()
     self.cv7 = Conv_(2 * c_, c2, 1, 1)
Exemple #9
0
def ConvNormActivation(inplanes,
                       planes,
                       kernel_size=3,
                       stride=1,
                       padding=0,
                       dilation=1,
                       groups=1,
                       norm_type="BN"):
    """
    A help function to build a 'conv-bn-activation' module
    """
    layers = []
    layers.append(nn.Conv2d(inplanes,
                            planes,
                            kernel_size=kernel_size,
                            stride=stride,
                            padding=padding,
                            dilation=dilation,
                            groups=groups,
                            bias=False))
    layers.append(get_norm(norm_type, planes, eps=1e-4, momentum=0.03))
    layers.append(Mish())
    return nn.Sequential(*layers)