Exemplo n.º 1
0
    def __init__(self, dim=512, n_obj_classes=151):
        super(_RelPN, self).__init__()
        self.anchor_scales = cfg.ANCHOR_SCALES
        self.feat_stride = cfg.FEAT_STRIDE[0]

        roi_feat_dim = n_obj_classes

        if cfg.TRAIN.RELPN_WITH_BBOX_INFO:
            roi_feat_dim += 4

        self.RelPN_bilinear_sub = nn.Sequential(
            nn.Linear(roi_feat_dim, 64),
            nn.ReLU(inplace=True),
            nn.Linear(64, 64),
        )

        self.RelPN_bilinear_obj = nn.Sequential(
            nn.Linear(roi_feat_dim, 64),
            nn.ReLU(inplace=True),
            nn.Linear(64, 64),
        )

        # define proposal layer
        self.RelPN_proposal = _ProposalLayer(self.feat_stride,
                                             self.anchor_scales)

        # define anchor target layer
        self.RelPN_anchor_target = _AnchorTargetLayer(self.feat_stride,
                                                      self.anchor_scales)

        self.relpn_loss_cls = 0
        self.relpn_loss_box = 0
Exemplo n.º 2
0
    def __init__(self, din):
        super(_RPN, self).__init__()
        
        self.din = din  # get depth of input feature map, e.g., 512
        self.anchor_scales = cfg.ANCHOR_SCALES
        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 = len(self.anchor_scales) * len(self.anchor_ratios) * 2 # 2(bg/fg) * 9 (anchors)
        self.RPN_cls_score = nn.Conv2d(512, self.nc_score_out, 1, 1, 0)

        # define anchor box offset prediction layer
        self.nc_bbox_out = len(self.anchor_scales) * len(self.anchor_ratios) * 4 # 4(coords) * 9 (anchors)
        self.RPN_bbox_pred = nn.Conv2d(512, self.nc_bbox_out, 1, 1, 0)

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

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

        self.rpn_loss_cls = 0
        self.rpn_loss_box = 0
Exemplo n.º 3
0
    def __init__(self, anchors, all_anchors, inds_inside):
        super(CPN, self).__init__()
        self.image_shape = [[240, 320]
                            ]  # for one batch, TODO: maybe need to change here
        self.anchors = anchors  # (630, x, y, xw, yw)                anchors coordinates
        self.inds_inside = inds_inside
        self.all_anchors = all_anchors
        self.nc_score_out = 2 * 12  # 2(bg/fg)  * 12 (anchors)
        self.nc_bbox_out = 4 * 12  # 4(coords) * 12 (anchors)
        c3d = C3D()
        self.action_num = 22  #-1       # 21(classes) do not consider bg
        self.action_anchor_num = self.action_num * 12
        c3d.load_state_dict(torch.load(c3d_checkpoint))

        self.RPN_Conv = nn.Conv2d(512, 512, 3, 1, 1, bias=True)
        self.BN1 = nn.BatchNorm2d(512)
        self.RPN_cls_bbox_action = nn.Conv2d(
            512, self.nc_score_out + self.nc_bbox_out + self.action_anchor_num,
            1, 1, 0)
        self.BN2 = nn.BatchNorm2d(self.nc_score_out + self.nc_bbox_out +
                                  self.action_anchor_num)
        self.RPN_proposal = _ProposalLayer(self.anchors, self.all_anchors)
        self.RPN_anchor_target = _AnchorTargetLayer(self.anchors,
                                                    self.inds_inside)