def _make_convs(self):
        head_width = self._hyper_params['head_width']

        # feature adjustment
        self.r_z_k = conv_bn_relu(head_width,
                                  head_width,
                                  1,
                                  3,
                                  0,
                                  has_relu=False)
        self.c_z_k = conv_bn_relu(head_width,
                                  head_width,
                                  1,
                                  3,
                                  0,
                                  has_relu=False)
        self.r_x = conv_bn_relu(head_width,
                                head_width,
                                1,
                                3,
                                0,
                                has_relu=False)
        self.c_x = conv_bn_relu(head_width,
                                head_width,
                                1,
                                3,
                                0,
                                has_relu=False)
Ejemplo n.º 2
0
 def __init__(self, block=creat_residual_block):
     super(ResNet18_M, self).__init__()
     self.block = block
     self.stage1 = nn.Sequential(
         conv_bn_relu(3,
                      32,
                      stride=2,
                      kszie=3,
                      pad=3,
                      has_bn=True,
                      has_relu=True,
                      bias=False),
         conv_bn_relu(32,
                      32,
                      stride=1,
                      kszie=3,
                      pad=1,
                      has_bn=True,
                      has_relu=True,
                      bias=False),
         conv_bn_relu(32,
                      32,
                      stride=1,
                      kszie=3,
                      pad=1,
                      has_bn=True,
                      has_relu=True,
                      bias=False), nn.MaxPool2d(3, 2, 1, ceil_mode=False))
     self.stage2 = self.__make_stage(self.block, 32, 64, 2, 1)
     self.stage3 = self.__make_stage(self.block, 64, 128, 2, 2)
     self.stage4 = self.__make_stage(self.block, 128, 256, 2, 2)
     self.stage5 = self.__make_stage(self.block, 256, 256, 2, 2)
Ejemplo n.º 3
0
    def __init__(self):
        super(TinyConv, self).__init__()

        self.conv1 = conv_bn_relu(3, 32, stride=2, kszie=3, pad=0)
        self.pool1 = nn.MaxPool2d(3, stride=2, padding=0, ceil_mode=True)

        self.conv2a = conv_bn_relu(32, 64, stride=1, kszie=1, pad=0)
        self.conv2b = conv_bn_relu(64, 64, stride=2, kszie=7, pad=0, groups=64)

        self.conv3a = conv_bn_relu(64, 64, stride=1, kszie=3, pad=0)
        self.conv3b = conv_bn_relu(64,
                                   64,
                                   stride=1,
                                   kszie=1,
                                   pad=0,
                                   has_relu=False)

        # initialization
        for m in self.modules():
            if isinstance(m, nn.Conv2d) or isinstance(m, nn.Linear):
                import scipy.stats as stats
                stddev = m.stddev if hasattr(m, 'stddev') else 0.1
                X = stats.truncnorm(-2, 2, scale=stddev)
                values = torch.as_tensor(X.rvs(m.weight.numel()),
                                         dtype=m.weight.dtype)
                values = values.view(m.weight.size())
                with torch.no_grad():
                    m.weight.copy_(values)
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
Ejemplo n.º 4
0
    def __init__(self):
        super(DenseboxHead, self).__init__()
        self.cls_score_p5 = conv_bn_relu(256,
                                         1,
                                         stride=1,
                                         kszie=1,
                                         pad=0,
                                         has_relu=False)
        self.ctr_score_p5 = conv_bn_relu(256,
                                         1,
                                         stride=1,
                                         kszie=1,
                                         pad=0,
                                         has_relu=False)
        self.bbox_offsets_p5 = conv_bn_relu(256,
                                            4,
                                            stride=1,
                                            kszie=1,
                                            pad=0,
                                            has_relu=False)

        self.bi = torch.nn.Parameter(torch.tensor(0.).type(torch.Tensor))
        self.si = torch.nn.Parameter(torch.tensor(1.).type(torch.Tensor))

        self.cls_convs = []
        self.bbox_convs = []
Ejemplo n.º 5
0
    def __init__(self, inplanes, outplanes, stride, has_proj=False):
        super(creat_residual_block, self).__init__()
        self.has_proj = has_proj
        if self.has_proj:
            self.proj_conv = conv_bn_relu(inplanes,
                                          outplanes,
                                          stride=stride,
                                          kszie=1,
                                          pad=0,
                                          has_bn=True,
                                          has_relu=False,
                                          bias=False)

        self.conv1 = conv_bn_relu(inplanes,
                                  outplanes,
                                  stride=stride,
                                  kszie=3,
                                  pad=1,
                                  has_bn=True,
                                  has_relu=True,
                                  bias=False)
        self.conv2 = conv_bn_relu(outplanes,
                                  outplanes,
                                  stride=1,
                                  kszie=3,
                                  pad=1,
                                  has_bn=True,
                                  has_relu=False,
                                  bias=False)

        self.relu = nn.ReLU()
Ejemplo n.º 6
0
 def __init__(self):
     super(AlexNet, self).__init__()
     self.conv1 = conv_bn_relu(3, 96, stride=2, kszie=11, pad=0)
     self.pool1 = nn.MaxPool2d(3, 2, 0, ceil_mode=True)
     self.conv2 = conv_bn_relu(96, 256, 1, 5, 0)
     self.pool2 = nn.MaxPool2d(3, 2, 0, ceil_mode=True)
     self.conv3 = conv_bn_relu(256, 384, 1, 3, 0)
     self.conv4 = conv_bn_relu(384, 384, 1, 3, 0)
     self.conv5 = conv_bn_relu(384, 256, 1, 3, 0, has_relu=False)
Ejemplo n.º 7
0
 def __init__(self, backbone, head, loss):
     super(SiamTrack, self).__init__()
     self.basemodel = backbone
     # feature adjustment
     self.r_z_k = conv_bn_relu(256, 256, 1, 3, 0, has_relu=False)
     self.c_z_k = conv_bn_relu(256, 256, 1, 3, 0, has_relu=False)
     self.r_x = conv_bn_relu(256, 256, 1, 3, 0, has_relu=False)
     self.c_x = conv_bn_relu(256, 256, 1, 3, 0, has_relu=False)
     # head
     self.head = head
     # loss
     self.loss = loss
     # initialze head
     conv_list = [
         self.r_z_k.conv, self.c_z_k.conv, self.r_x.conv, self.c_x.conv
     ]
     for ith in range(len(conv_list)):
         conv = conv_list[ith]
         torch.nn.init.normal_(conv.weight, std=0.01)
Ejemplo n.º 8
0
 def _make_conv_output(self):
     head_width = self._hyper_params['head_width']
     self.cls_score_p5 = conv_bn_relu(head_width,
                                      1,
                                      stride=1,
                                      kszie=1,
                                      pad=0,
                                      has_relu=False)
     self.ctr_score_p5 = conv_bn_relu(head_width,
                                      1,
                                      stride=1,
                                      kszie=1,
                                      pad=0,
                                      has_relu=False)
     self.bbox_offsets_p5 = conv_bn_relu(head_width,
                                         4,
                                         stride=1,
                                         kszie=1,
                                         pad=0,
                                         has_relu=False)
Ejemplo n.º 9
0
 def _make_conv_output(self):
     head_width = self._hyper_params['head_width']
     self.cls_score_p5 = conv_bn_relu(head_width,
                                      1,
                                      stride=1,
                                      kszie=1,
                                      pad=0,
                                      has_relu=False)
     self.cls_score2_p5 = conv_bn_relu_withweight(256,
                                                  1,
                                                  stride=1,
                                                  kszie=1,
                                                  pad=0,
                                                  has_relu=False)
     self.ctr_score_p5 = conv_bn_relu(head_width,
                                      1,
                                      stride=1,
                                      kszie=1,
                                      pad=0,
                                      has_relu=False)
     '''
     self.ctr_score2_p5 = conv_bn_relu_withweight(256,
                                                  1,
                                                  stride=1,
                                                  kszie=1,
                                                  pad=0,
                                                  has_relu=False)
     '''
     self.bbox_offsets_p5 = conv_bn_relu(head_width,
                                         4,
                                         stride=1,
                                         kszie=1,
                                         pad=0,
                                         has_relu=False)
     self.bbox_offsets2_p5 = conv_bn_relu_withweight(256,
                                                     4,
                                                     stride=1,
                                                     kszie=3,
                                                     pad=1,
                                                     has_bn=True,
                                                     has_relu=False)
Ejemplo n.º 10
0
    def _make_convs(self):
        head_width = self._hyper_params['head_width']
        neck_conv_bias = self._hyper_params['neck_conv_bias']

        # feature adjustment
        self.r_z_k = conv_bn_relu(
            head_width,
            head_width,
            1,
            3,
            0,
            has_relu=False,
            bias=neck_conv_bias[0],
            #has_bn = False
        )

        self.r_x = conv_bn_relu(head_width,
                                head_width,
                                1,
                                3,
                                0,
                                has_relu=False,
                                bias=neck_conv_bias[1])

        self.c_z_k = conv_bn_relu(head_width,
                                  head_width,
                                  1,
                                  3,
                                  0,
                                  has_relu=False,
                                  bias=neck_conv_bias[2])

        self.c_x = conv_bn_relu(head_width,
                                head_width,
                                1,
                                3,
                                0,
                                has_relu=False,
                                bias=neck_conv_bias[3])
Ejemplo n.º 11
0
    def _make_conv3x3(self):
        num_conv3x3 = self._hyper_params['num_conv3x3']
        head_conv_bn = self._hyper_params['head_conv_bn']
        self.cls_conv3x3_list = []
        self.bbox_conv3x3_list = []
        for i in range(num_conv3x3):
            # is_last_conv = (i >= num_conv3x3)
            cls_conv3x3 = conv_bn_relu(256,
                                       256,
                                       stride=1,
                                       kszie=3,
                                       pad=0,
                                       has_bn=head_conv_bn[i])

            bbox_conv3x3 = conv_bn_relu(256,
                                        256,
                                        stride=1,
                                        kszie=3,
                                        pad=0,
                                        has_bn=head_conv_bn[i])
            setattr(self, 'cls_p5_conv%d' % (i + 1), cls_conv3x3)
            setattr(self, 'bbox_p5_conv%d' % (i + 1), bbox_conv3x3)
            self.cls_conv3x3_list.append(cls_conv3x3)
            self.bbox_conv3x3_list.append(bbox_conv3x3)