Ejemplo n.º 1
0
    def __init__(self, stride=32, *args, **kwargs):
        super(Resnet101, self).__init__()
        assert stride in (8, 16, 32)
        dils = [1, 1
                ] if stride == 32 else [el * (16 // stride) for el in (1, 2)]
        strds = [2 if el == 1 else 1 for el in dils]

        self.conv1 = nn.Conv2d(3,
                               64,
                               kernel_size=7,
                               stride=2,
                               padding=3,
                               bias=False)
        self.bn1 = BatchNorm2d(64)
        self.maxpool = nn.MaxPool2d(kernel_size=3,
                                    stride=2,
                                    padding=1,
                                    dilation=1,
                                    ceil_mode=False)
        self.layer1 = create_stage(64, 256, 3, stride=1, dilation=1)
        self.layer2 = create_stage(256, 512, 4, stride=2, dilation=1)
        self.layer3 = create_stage(512,
                                   1024,
                                   23,
                                   stride=strds[0],
                                   dilation=dils[0])
        self.layer4 = create_stage(1024,
                                   2048,
                                   3,
                                   stride=strds[1],
                                   dilation=dils[1])
        self.init_weight()
Ejemplo n.º 2
0
    def __init__(self,
                 in_chan,
                 out_chan,
                 stride=1,
                 stride_at_1x1=False,
                 dilation=1,
                 *args,
                 **kwargs):
        super(Bottleneck, self).__init__(*args, **kwargs)

        stride1x1, stride3x3 = (stride, 1) if stride_at_1x1 else (1, stride)
        assert out_chan % 4 == 0
        mid_chan = int(out_chan / 4)

        self.conv1 = nn.Conv2d(in_chan,
                               mid_chan,
                               kernel_size=1,
                               stride=stride1x1,
                               bias=False)
        self.bn1 = BatchNorm2d(mid_chan)
        self.conv2 = nn.Conv2d(mid_chan,
                               mid_chan,
                               kernel_size=3,
                               stride=stride3x3,
                               padding=dilation,
                               dilation=dilation,
                               bias=False)
        self.bn2 = BatchNorm2d(mid_chan)
        self.conv3 = nn.Conv2d(mid_chan, out_chan, kernel_size=1, bias=False)
        self.bn3 = BatchNorm2d(out_chan, activation='none')
        self.relu = nn.ReLU(inplace=True)

        self.downsample = None
        if in_chan != out_chan or stride != 1:
            self.downsample = nn.Sequential(
                nn.Conv2d(in_chan,
                          out_chan,
                          kernel_size=1,
                          stride=stride,
                          bias=False), BatchNorm2d(out_chan,
                                                   activation='none'))
        self.init_weight()
Ejemplo n.º 3
0
 def __init__(self, in_chan, out_chan, ks=3, stride=1, padding=1, dilation=1, *args, **kwargs):
     super(ConvBNReLU, self).__init__()
     self.conv = nn.Conv2d(in_chan,
             out_chan,
             kernel_size = ks,
             stride = stride,
             padding = padding,
             dilation = dilation,
             bias = True)
     self.bn = BatchNorm2d(out_chan)
     self.init_weight()
    def __init__(self,
                 in_chan,
                 out_chan,
                 ks=3,
                 stride=1,
                 pad=0,
                 dilation=1,
                 slope=0.1,
                 *args,
                 **kwargs):
        super(ConvBNLeaky, self).__init__()

        self.conv = nn.Conv2d(in_chan,
                              out_chan,
                              kernel_size=ks,
                              padding=pad,
                              dilation=dilation,
                              stride=stride,
                              bias=False)
        self.bn = BatchNorm2d(out_chan, slope=slope)
        self._init_weight()
    def __init__(self,
                 in_chan,
                 out_chan,
                 ks=3,
                 stride=1,
                 padding=1,
                 dilation=1,
                 bias=False,
                 *args,
                 **kwargs):
        super(SepConvBNReLU, self).__init__()

        self.conv = nn.Conv2d(in_chan,
                              in_chan,
                              kernel_size=ks,
                              stride=stride,
                              padding=dilation,
                              dilation=dilation,
                              groups=in_chan,
                              bias=bias)
        self.bn = BatchNorm2d(in_chan)
        self.pairwise = nn.Conv2d(in_chan, out_chan, kernel_size=1, bias=bias)

        self.init_weight()