コード例 #1
0
def odm_multibox(vgg, extra_layers, cfg, num_classes):
    odm_loc_layers = []
    odm_conf_layers = []
    odm_deform_loc_layers = []
    # odm_deform_conf_layers = []
    vgg_source = [21, 28, -2]
    for k, v in enumerate(vgg_source):
        odm_deform_loc_layers += [ConvOffset2D(256)]
        # odm_deform_conf_layers += [ConvOffset2D(256)]
        odm_loc_layers += [
            nn.Conv2d(256, cfg[k] * 4, kernel_size=3, padding=1)
        ]
        odm_conf_layers += [
            nn.Conv2d(256, cfg[k] * num_classes, kernel_size=3, padding=1)
        ]
    for k, v in enumerate(extra_layers[1::2], 3):
        odm_deform_loc_layers += [ConvOffset2D(256)]
        # odm_deform_conf_layers += [ConvOffset2D(256)]
        odm_loc_layers += [
            nn.Conv2d(256, cfg[k] * 4, kernel_size=3, padding=1)
        ]
        odm_conf_layers += [
            nn.Conv2d(256, cfg[k] * num_classes, kernel_size=3, padding=1)
        ]
    return (odm_loc_layers, odm_conf_layers, odm_deform_loc_layers)
コード例 #2
0
def arm_multibox(vgg, extra_layers, cfg):
    arm_loc_layers = []
    arm_conf_layers = []
    arm_deform_loc_layers = []
    arm_deform_loc_layers = [
        ConvOffset2D(512),
        ConvOffset2D(512),
        ConvOffset2D(1024)
    ]
    vgg_source = [21, 28, -2]
    for k, v in enumerate(vgg_source):

        arm_loc_layers += [
            nn.Conv2d(vgg[v].out_channels,
                      cfg[k] * 4,
                      kernel_size=3,
                      padding=1)
        ]
        arm_conf_layers += [
            nn.Conv2d(vgg[v].out_channels,
                      cfg[k] * 2,
                      kernel_size=3,
                      padding=1)
        ]
    for k, v in enumerate(extra_layers[1::2], 3):
        arm_deform_loc_layers += [ConvOffset2D(512)]
        arm_loc_layers += [
            nn.Conv2d(v.out_channels, cfg[k] * 4, kernel_size=3, padding=1)
        ]
        arm_conf_layers += [
            nn.Conv2d(v.out_channels, cfg[k] * 2, kernel_size=3, padding=1)
        ]
    return (arm_loc_layers, arm_conf_layers, arm_deform_loc_layers)
コード例 #3
0
ファイル: resnet.py プロジェクト: Karin-S/deeplab_modify
    def __init__(self, inplanes, planes, stride=1, dilation=1, downsample=None, BatchNorm=None):
        super(Deformblock, self).__init__()

        self.offset1 = ConvOffset2D(inplanes, planes)
        print("inplanes", inplanes)
        # self.conv1 = nn.Conv2d(planes, planes, kernel_size=1, bias=False)

        print("planes", planes)
        self.bn1 = BatchNorm(planes)

        self.offset2 = ConvOffset2D(planes, planes)
        # print("3", planes)
        # self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, dilation=dilation, padding=dilation, bias=False)
        # print("4", planes)
        self.bn2 = BatchNorm(planes)

        self.offset3 = ConvOffset2D(planes, planes*4)
        # print("5", planes)
        # self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False)
        # print("6", planes)
        self.bn3 = BatchNorm(planes * 4)
        self.relu = nn.ReLU(inplace=True)

        self.downsample = downsample
        self.stride = stride
        self.dilation = dilation
コード例 #4
0
 def __init__(self, inplanes, planes, stride=1, downsample=None):
     super(Bottleneck, self).__init__()
     self.deform1 = ConvOffset2D(inplanes)
     self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
     self.bn1 = nn.BatchNorm2d(planes)
     self.deform2 = ConvOffset2D(planes)
     self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride,
                            padding=1, bias=False)
     self.bn2 = nn.BatchNorm2d(planes)
     self.deform3 = ConvOffset2D(planes)
     self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False)
     self.bn3 = nn.BatchNorm2d(planes * 4)
     self.relu = nn.ReLU(inplace=True)
     self.downsample = downsample
     self.stride = stride
コード例 #5
0
ファイル: xception.py プロジェクト: Karin-S/deeplab_modify
    def __init__(self, inplanes, planes, bias=False, BatchNorm=None):
        super(SeparableConv2d_deform, self).__init__()

        self.relu = nn.ReLU(inplace=False)
        self.conv1 = ConvOffset2D(inplanes)
        self.bn = BatchNorm(inplanes)
        self.pointwise = nn.Conv2d(inplanes, planes, 1, 1, 0, 1, 1, bias=bias)
コード例 #6
0
    def __init__(self, in_channels, out_channels, stride, cardinality, widen_factor):
        """ Constructor
        Args:
            in_channels: input channel dimensionality
            out_channels: output channel dimensionality
            stride: conv stride. Replaces pooling layer.
            cardinality: num of convolution groups.
            widen_factor: factor to reduce the input dimensionality before convolution.
        """
        super(DeformResNeXtBottleneck, self).__init__()
        D = cardinality * out_channels // widen_factor
        self.conv_reduce = nn.Conv2d(in_channels, D, kernel_size=1, stride=1, padding=0, bias=False)
        self.bn_reduce = nn.BatchNorm2d(D)

        self.offset_2 = ConvOffset2D(D)

        self.conv_conv = nn.Conv2d(D, D, kernel_size=3, stride=stride, padding=1, groups=cardinality, bias=False)
        self.bn = nn.BatchNorm2d(D)

        self.conv_expand = nn.Conv2d(D, out_channels, kernel_size=1, stride=1, padding=0, bias=False)
        self.bn_expand = nn.BatchNorm2d(out_channels)

        self.shortcut = nn.Sequential()
        if in_channels != out_channels:
            self.shortcut.add_module('shortcut_conv', nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=stride, padding=0, bias=False))
            self.shortcut.add_module('shortcut_bn', nn.BatchNorm2d(out_channels))
コード例 #7
0
    def __init__(self, n_classes):
        super(back_end_deform, self).__init__()
        self.conv1 = nn.Sequential( ConvOffset2D(512),
                                      Conv2d(in_channels=512, out_channels=256, kernel_size=3, padding=1,  NL='relu'))
        self.conv2 = nn.Sequential( ConvOffset2D(256),
                                      Conv2d(in_channels=256, out_channels=128, kernel_size=3, padding=1,  NL='relu'))
        self.conv3 = nn.Sequential( ConvOffset2D(128),
                                      Conv2d(in_channels=128, out_channels=64, kernel_size=3, padding=1,  NL='relu'))
        self.conv4 = Conv2d(64, 32, 1, stride=1, padding=0)
        self.conv5 = Conv2d(32, 16, 1, stride=1, padding=0)
        self.conv6 = Conv2d(16, n_classes, 1, stride=1, padding=0)

        self.conv7 = Conv2d(3, 32, 1, stride=1, padding=0)
        self.conv8 = Conv2d(32, 16, 1, stride=1, padding=0)
        self.conv9 = Conv2d(16, n_classes, 1, stride=1, padding=0)
        self.agp = nn.AdaptiveAvgPool2d(1)
        self.OutputActivation = nn.Sigmoid()
        self._initialize_weights()
コード例 #8
0
    def __init__(self):
        super(Net, self).__init__()

        # branch 1
        self.conv11 = nn.Conv2d(3, 16, 5)
        self.bn11 = nn.BatchNorm2d(16)
        self.pool11 = nn.MaxPool2d(2, 2)
        self.conv12 = nn.Conv2d(16, 32, 5)
        self.bn12 = nn.BatchNorm2d(32)
        self.pool12 = nn.MaxPool2d(2, 2)
        self.conv13 = nn.Conv2d(32, 64, 3)
        self.bn13 = nn.BatchNorm2d(64)
        self.pool13 = nn.MaxPool2d(2, 2)
        self.conv14 = nn.Conv2d(64, 128, 3)
        self.bn14 = nn.BatchNorm2d(128)
        self.gap1 = nn.AvgPool2d(7, 7)

        # branch 2
        self.offset21 = ConvOffset2D(3)
        self.conv21 = nn.Conv2d(3, 8, 5)
        self.bn21 = nn.BatchNorm2d(8)
        self.pool21 = nn.MaxPool2d(2, 2)
        self.offset22 = ConvOffset2D(8)
        self.conv22 = nn.Conv2d(8, 16, 5)
        self.bn22 = nn.BatchNorm2d(16)
        self.pool22 = nn.MaxPool2d(2, 2)
        self.offset23 = ConvOffset2D(16)
        self.conv23 = nn.Conv2d(16, 32, 3)
        self.bn23 = nn.BatchNorm2d(32)
        self.pool23 = nn.MaxPool2d(2, 2)
        self.offset24 = ConvOffset2D(32)
        self.conv24 = nn.Conv2d(32, 64, 3)
        self.bn24 = nn.BatchNorm2d(64)
        self.gap2 = nn.AvgPool2d(7, 7)

        # mainstream
        # self.fc1 = nn.Linear(3 * 3 * 192, 1024)
        # self.fc2 = nn.Linear(1024, 64)
        # self.fc3 = nn.Linear(64, 4)
        self.conv5 = nn.Conv2d(192, 64, 1)
        self.conv6 = nn.Conv2d(64, 16, 1)
        self.conv7 = nn.Conv2d(16, 4, 1)
        self.softmax = nn.Softmax(dim=1)
コード例 #9
0
ファイル: model.py プロジェクト: bubo0/deblocking_pytorch
    def __init__(self):  #deleted upscale?
        super(NetARCNN_deform, self).__init__()
         
        self.relu = nn.ReLU()

        self.conv1 = nn.Conv2d(1, 64, 9, 1, 4) # does padding 0 means "same"?
        self.offset1 = ConvOffset2D(64)

        self.conv2 = nn.Conv2d(64, 32, 7, 1, 3)

        self.offset2 = ConvOffset2D(32)          

        self.conv3 = nn.Conv2d(32, 16, 1, 1, 0)

        self.offset3 = ConvOffset2D(16)

        self.conv4 = nn.Conv2d(16, 1, 5, 1, 2) # why is padding 9 necessary???? 

	self._initialize_weights()
コード例 #10
0
    def __init__(self, inplanes, planes, stride=1, downsample=None):
        super(DeformResNetBasicblock, self).__init__()

        self.conv_1 = conv3x3(inplanes, planes, stride)
        self.bn_1 = nn.BatchNorm2d(planes)

        self.offset_2 = ConvOffset2D(planes)
        self.conv_2 = conv3x3(planes, planes)
        self.bn_2 = nn.BatchNorm2d(planes)

        self.downsample = downsample
コード例 #11
0
    def __init__(self):
        super(DeformConvNet, self).__init__()

        # conv11
        self.conv11 = nn.Conv2d(1, 32, 3, padding=1)
        self.bn11 = nn.BatchNorm2d(32)

        # conv12
        self.offset12 = ConvOffset2D(32)
        self.conv12 = nn.Conv2d(32, 64, 3, padding=1, stride=2)
        self.bn12 = nn.BatchNorm2d(64)

        # conv21
        self.offset21 = ConvOffset2D(64)
        self.conv21 = nn.Conv2d(64, 128, 3, padding=1)
        self.bn21 = nn.BatchNorm2d(128)

        # conv22
        self.offset22 = ConvOffset2D(128)
        self.conv22 = nn.Conv2d(128, 128, 3, padding=1, stride=2)
        self.bn22 = nn.BatchNorm2d(128)

        # out
        self.fc = nn.Linear(128, 10)
コード例 #12
0
    def __init__(self,
                 inplanes,
                 outplanes,
                 innerplanes,
                 stride=1,
                 dilation=1,
                 group=1,
                 downsample=None):
        super().__init__()
        # In original resnet, stride=2 is on 1x1.
        # In fb.torch resnet, stride=2 is on 3x3.
        (str1x1, str3x3) = (stride, 1) if cfg.RESNETS.STRIDE_1X1 else (1,
                                                                       stride)
        self.stride = stride

        self.conv1 = nn.Conv2d(inplanes,
                               innerplanes,
                               kernel_size=1,
                               stride=str1x1,
                               bias=False)
        self.bn1 = mynn.AffineChannel2d(innerplanes)

        self.conv2_offset = ConvOffset2D(innerplanes,
                                         kernel_size=3,
                                         stride=str3x3,
                                         bias=False,
                                         padding=1 * dilation,
                                         dilation=dilation,
                                         groups=group)
        self.conv2 = nn.Conv2d(innerplanes,
                               innerplanes,
                               kernel_size=3,
                               stride=str3x3,
                               bias=False,
                               padding=1 * dilation,
                               dilation=dilation,
                               groups=group)
        self.bn2 = mynn.AffineChannel2d(innerplanes)

        self.conv3 = nn.Conv2d(innerplanes,
                               outplanes,
                               kernel_size=1,
                               stride=1,
                               bias=False)
        self.bn3 = mynn.AffineChannel2d(outplanes)

        self.downsample = downsample
        self.relu = nn.ReLU(inplace=True)
コード例 #13
0
def make_layers(cfg, batch_norm=False):
    layers = []
    in_channels = 3
    for v in cfg:
        if v == 'M':
            layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
        elif v == 'D':
            layers += [ConvOffset2D(in_channels)]
        else:
            conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1)
            if batch_norm:
                layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU(inplace=True)]
            else:
                layers += [conv2d, nn.ReLU(inplace=True)]
            in_channels = v
    return nn.Sequential(*layers)
コード例 #14
0
ファイル: deformable_crnn.py プロジェクト: Emmmmmaa/DTR
    def __init__(self, imgH, nc, nclass, nh=256):
        super(DeformableCRNN, self).__init__()
        assert imgH % 16 == 0, 'imgH has to be a multiple of 16'

        self.conv0 = nn.Conv2d(nc,
                               64,
                               kernel_size=(3, 3),
                               stride=(1, 1),
                               padding=(1, 1))
        self.pooling0 = nn.AdaptiveMaxPool2d(output_size=(32, 100))
        self.conv1 = nn.Conv2d(64,
                               128,
                               kernel_size=(3, 3),
                               stride=(1, 1),
                               padding=(1, 1))
        self.pooling1 = nn.AdaptiveMaxPool2d(output_size=(16, 50))
        self.conv2 = nn.Conv2d(128,
                               256,
                               kernel_size=(3, 3),
                               stride=(1, 1),
                               padding=(1, 1))
        self.bn2 = nn.BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
        self.deconv3 = ConvOffset2D(256, 1)
        self.conv3 = nn.Conv2d(256,
                               256,
                               kernel_size=(3, 3),
                               stride=(1, 1),
                               padding=(1, 1))
        self.pooling2 = nn.AdaptiveMaxPool2d(output_size=(8, 25))

        self.resblock1 = ResidualBlock(256)
        self.resblock2 = ResidualBlock(256)
        self.resblock3 = ResidualBlock(256)
        self.resblock4 = ResidualBlock(256)

        self.deconv4 = ConvOffset2D(256, 1)
        self.conv4 = nn.Conv2d(256,
                               512,
                               kernel_size=(3, 3),
                               stride=(1, 1),
                               padding=(1, 1))
        self.bn4 = nn.BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
        self.conv5 = nn.Conv2d(512,
                               512,
                               kernel_size=(3, 3),
                               stride=(1, 1),
                               padding=(1, 1))
        self.pooling3 = nn.AdaptiveMaxPool2d(output_size=(4, 26))
        self.conv6 = nn.Conv2d(512,
                               512,
                               kernel_size=(3, 3),
                               stride=(1, 1),
                               padding=(1, 1))
        self.pooling4 = nn.AdaptiveMaxPool2d(output_size=(2, 27))

        self.conv7 = nn.Conv2d(512, 512, kernel_size=(2, 2), stride=(1, 1))
        self.bn6 = nn.BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)

        self.relu = nn.ReLU(True)
        self.p_relu = nn.PReLU()

        self.rnn = nn.Sequential(BidirectionalLSTM(512, nh, nh),
                                 BidirectionalLSTM(nh, nh, nclass))
コード例 #15
0
 def __init__(self, num_filters):
     super(DeforConvolutionBlock, self).__init__()
     filters = num_filters
     self.offset12 = ConvOffset2D(filters // 2)
     self.conv1 = Conv2D_BN_Leaky(filters, filters // 2, kernel=1)
     self.conv2 = Conv2D_BN_Leaky(filters // 2, filters, kernel=3)
コード例 #16
0
 def __init__(self):
     super(Net, self).__init__()
     self.conv1 = nn.Conv2d(1, 1, 3)
     self.pool = nn.MaxPool2d(2, 2, return_indices=True)
     self.defconv = ConvOffset2D(1, return_offsets=True)
     self.conv2 = nn.Conv2d(1, 1, 3)
コード例 #17
0
ファイル: test.py プロジェクト: PaParaZz1/DCNpp
 def __init__(self, in_channels=128):
     super(TestDCN, self).__init__()
     self.deformable_conv = ConvOffset2D(in_channels)