Ejemplo n.º 1
0
    def __init__(self, vgg16_image_net=True):
        super(SSH, self).__init__()

        vgg16_features = tv.models.vgg16(pretrained=vgg16_image_net).features
        self.conv4_3 = nn.Sequential(*list(vgg16_features.children())[:23])
        self.conv5_3 = nn.Sequential(*list(vgg16_features.children())[23:30])
        self.m3_module = net.M3(512)
        self.m2_module = net.M2(512)
        self.m1_module = net.M1(128)

        self.conv5_128 = net.Conv2D(512, 128, 1, False, 1, True)
        self.conv5_128_up = nn.ConvTranspose2d(128, 128, 4, 2, 1, 1, 128,
                                               False)
        self.con4_128 = net.Conv2D(512, 128, 1, False, 1, True)
        self.con4_fuse_final = net.Conv2D(128, 128, 3, True, 1, True)

        self.pool6 = nn.MaxPool2d(2, 2)

        self.m3_anchor_target_layer = _AnchorTargetLayer(32,
                                                         np.array([16, 32]),
                                                         np.array([
                                                             1,
                                                         ]),
                                                         512,
                                                         name='m3')
        self.m2_anchor_target_layer = _AnchorTargetLayer(16,
                                                         np.array([4, 8]),
                                                         np.array([
                                                             1,
                                                         ]),
                                                         0,
                                                         name='m2')
        self.m1_anchor_target_layer = _AnchorTargetLayer(8,
                                                         np.array([1, 2]),
                                                         np.array([
                                                             1,
                                                         ]),
                                                         0,
                                                         name='m1')

        self.m3_proposal_layer = _Proposallayer(32, np.array([16, 32]),
                                                np.array([
                                                    1,
                                                ]))
        self.m2_proposal_layer = _Proposallayer(16, np.array([4, 8]),
                                                np.array([
                                                    1,
                                                ]))
        self.m1_proposal_layer = _Proposallayer(8, np.array([1, 2]),
                                                np.array([
                                                    1,
                                                ]))

        self.m3_soft_max = nn.Softmax(1)
        self.m2_soft_max = nn.Softmax(1)
        self.m1_soft_max = nn.Softmax(1)
Ejemplo n.º 2
0
    def __init__(self, din):
        super(_Stereo_RPN, self).__init__()

        self.din = din  # get depth of input feature map, e.g., 512
        self.anchor_ratios = cfg.ANCHOR_RATIOS
        self.feat_stride = cfg.FEAT_STRIDE[0]

        # define the convrelu layers processing input feature map
        self.RPN_Conv = nn.Conv2d(self.din, 512, 3, 1, 1, bias=True)

        # define bg/fg classifcation score layer
        self.nc_score_out = 1 * len(
            self.anchor_ratios
        ) * 2  # 2(bg/fg) * 3 (anchor ratios) * 1 (anchor scale)
        self.RPN_cls_score = nn.Conv2d(512 * 2, self.nc_score_out, 1, 1, 0)

        # define anchor box offset prediction layer
        self.nc_bbox_out = 1 * len(
            self.anchor_ratios
        ) * 6  # 6(coords) * 3 (anchors) * 1 (anchor scale)
        self.RPN_bbox_pred_left_right = nn.Conv2d(512 * 2, self.nc_bbox_out, 1,
                                                  1, 0)

        # define proposal layer
        self.RPN_proposal = _ProposalLayer(self.feat_stride,
                                           self.anchor_ratios)

        # define anchor target layer
        self.RPN_anchor_target = _AnchorTargetLayer(self.feat_stride,
                                                    self.anchor_ratios)

        self.rpn_loss_cls = 0
        self.rpn_loss_box_left_right = 0
Ejemplo n.º 3
0
    def __init__(self, din, use_gpu=False):
        super(_RPN, self).__init__()

        self.use_gpu = use_gpu
        self.din = din  # input channel num
        self.anchor_scales = [8, 16, 32]  # anchor_scales
        self.anchor_ratios = [0.5, 1, 2]  # anchor_ratios
        self.feat_stride = [16]  # feat_stride

        # define the convrelu layers processing input feature map
        # in_channels, out_channels, kernel_size=3, stride=1, padding=1
        self.RPN_Conv = nn.Conv2d(self.din, 512, 3, 1, 1, bias=True)

        # 2(bg/fg) * 9(anchor)
        self.nc_score_out = len(self.anchor_scales) * len(
            self.anchor_ratios) * 2
        self.RPN_cls_score = nn.Conv2d(512, self.nc_score_out, 1, 1, 0)

        self.nc_bbox_out = len(self.anchor_scales) * len(
            self.anchor_ratios) * 4
        self.RPN_bbox_pred = nn.Conv2d(512, self.nc_bbox_out, 1, 1, 0)

        self.RPN_proposal = _ProposalLayer(self.feat_stride,
                                           self.anchor_scales,
                                           self.anchor_ratios, self.use_gpu)

        self.RPN_anchor_target = _AnchorTargetLayer(self.feat_stride,
                                                    self.anchor_scales,
                                                    self.anchor_ratios)

        self.rpn_loss_cls = 0
        self.rpn_loss_bbox = 0
    def __init__(self,
                 in_channels=512,
                 mid_channels=512,
                 sliding_window_size=3):
        super().__init__()

        self.anchor_scales = cfg.ANCHOR_SCALES
        self.anchor_ratios = cfg.ANCHOR_RATIOS
        self.feat_stride = cfg.FEAT_STRIDE[0]
        self.num_classes = 21

        self.RPN_Conv = nn.Conv2d(in_channels,
                                  mid_channels,
                                  sliding_window_size,
                                  stride=1,
                                  padding=1)
        self.num_anchors = len(self.anchor_ratios) * len(self.anchor_scales)
        self.cls_out_channels = self.num_anchors * 2
        self.reg_out_channels = self.num_anchors * 4
        self.RPN_cls_score = nn.Conv2d(mid_channels,
                                       self.cls_out_channels,
                                       1,
                                       stride=1,
                                       padding=0)
        self.RPN_bbox_pred = nn.Conv2d(mid_channels,
                                       self.reg_out_channels,
                                       1,
                                       stride=1,
                                       padding=0)
        self.proposal_layer = ProposalLayer(scales=(8, 16, 32),
                                            aspect_ratios=(0.5, 1, 2))
        self.anchor_generator = AnchorGenerator(self.anchor_scales,
                                                self.anchor_ratios)
        self.anchor_target_layer = _AnchorTargetLayer(self.feat_stride,
                                                      self.anchor_scales,
                                                      self.anchor_ratios)