Exemplo n.º 1
0
    def __init__(self, classes, class_agnostic, compact_mode=False):
        super(_fasterRCNN, self).__init__()
        self.classes = classes
        self.n_classes = len(classes)
        self.class_agnostic = class_agnostic

        # loss
        self.RCNN_loss_cls = 0
        self.RCNN_loss_bbox = 0
        # self.focalloss_handle = FocalLossV4(num_class=21, alpha=0.25, gamma=2.0, balance_index=2)
        # define Large Separable Convolution Layer

        self.rpn = RPN(in_channels=245, f_channels=256)

        self.sam = SAM(256, 245)
        # define rpn
        self.RCNN_rpn = _RPN(self.dout_base_model)
        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)

        self.rpn_time = None
        self.pre_roi_time = None
        self.roi_pooling_time = None
        self.subnet_time = None
        self.psroiAlign = PSROIAlignhandle(1. / cfg.FEAT_STRIDE, 7, 2, 5)
        self.psroiPool = PSROIPoolhandle(7, 7, 1. / cfg.FEAT_STRIDE, 7, 5)
Exemplo n.º 2
0
    def __init__(self, classes, class_agnostic):
        super(_fasterRCNN, self).__init__()
        self.classes = classes
        self.n_classes = len(classes)
        self.class_agnostic = class_agnostic
        # loss
        self.RCNN_loss_cls = 0
        self.RCNN_loss_bbox = 0

        # define rpn
        self.RCNN_rpn = _RPN(self.dout_base_model)
        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)
        self.RCNN_roi_pool = _RoIPooling(cfg.POOLING_SIZE, cfg.POOLING_SIZE, 1.0/16.0)
        self.RCNN_roi_align = RoIAlignAvg(cfg.POOLING_SIZE, cfg.POOLING_SIZE, 1.0/16.0)

        self.grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE# = 7*2 =14
        '''
        # Size of the pooled region after RoI pooling
        __C.POOLING_SIZE = 7  roi pooling 之后得到的特征的尺寸
        CROP_RESIZE_WITH_MAX_POOL = True
        
        
        '''


        self.RCNN_roi_crop = _RoICrop()
Exemplo n.º 3
0
    def __init__(self, classes, class_agnostic):
        super(_HierRCNN, self).__init__()
        with h5py.File('data/pretrained_model/label_vec_vrd.h5', 'r') as f:
            self.label_vecs = np.array(f['label_vec'])
        self.classes = classes
        self.n_classes = len(classes)
        self.class_agnostic = class_agnostic
        # loss
        self.RCNN_loss_cls = 0
        self.RCNN_loss_bbox = 0

        # define rpn
        self.RCNN_rpn = _RPN(self.dout_base_model)
        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)
        self.RCNN_roi_pool = _RoIPooling(cfg.POOLING_SIZE, cfg.POOLING_SIZE,
                                         1.0 / 16.0)
        self.RCNN_roi_align = RoIAlignAvg(cfg.POOLING_SIZE, cfg.POOLING_SIZE,
                                          1.0 / 16.0)

        self.grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE
        self.RCNN_roi_crop = _RoICrop()

        self.order_embedding = nn.Sequential(
            nn.ReLU(inplace=True), nn.Dropout(), nn.Linear(4096, 4096),
            nn.ReLU(inplace=True), nn.Dropout(),
            nn.Linear(4096, cfg.HIER.EMBEDDING_LENGTH))

        self.order_score = _OrderSimilarity(cfg.HIER.ORDER_DISTANCE_NORM)
Exemplo n.º 4
0
    def __init__(self,
                 classes,
                 class_agnostic,
                 sample_sigma=0.001,
                 nms_threshold=0.01,
                 rpn_prior_weight=0.2,
                 rpn_reg_weight=0.1,
                 head_prior_weight=0.2,
                 head_reg_weight=0.1):

        super(_fasterRCNN_BiDet, self).__init__()
        self.classes = classes
        self.n_classes = len(classes)
        self.class_agnostic = class_agnostic
        self.sample_sigma = sample_sigma
        # loss
        self.RCNN_loss_cls = torch.FloatTensor([0.]).cuda()
        self.RCNN_loss_bbox = torch.FloatTensor([0.]).cuda()

        # IB setting
        self.nms_threshold = nms_threshold
        self.rpn_prior_weight = rpn_prior_weight
        self.head_prior_weight = head_prior_weight
        self.head_reg_weight = head_reg_weight

        # define rpn
        self.RCNN_rpn = _RPN_BiDet(self.dout_base_model,
                                   reg_weight=rpn_reg_weight)
        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)

        self.RCNN_roi_pool = ROIPool((cfg.POOLING_SIZE, cfg.POOLING_SIZE),
                                     1.0 / 16.0)
        self.RCNN_roi_align = ROIAlign((cfg.POOLING_SIZE, cfg.POOLING_SIZE),
                                       1.0 / 16.0, 0)
Exemplo n.º 5
0
    def __init__(self, n_obj_classes, n_rel_classes, pooled_feat_dim=4096):
        '''

        :param obj_classes:
        :param att_classes:
        :param rel_classes:
        :param dout_base_model: ## todo???
        :param pooled_feat_dim: ## todo???
        '''
        super(graphRCNN, self).__init__()

        self.n_obj_classes = n_obj_classes
        self.n_rel_classes = n_rel_classes

        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_obj_classes)
        # define aGCN
        if cfg.HAS_RELATIONS:
            self.encoder = EncoderLSTM_w2v()
            self.RELPN = _RelPN(pooled_feat_dim, self.n_obj_classes)
            self.RELPN_proposal_target = _RelProposalTargetLayer(
                self.n_rel_classes)

            self.RELPN_roi_pool = ROIPool((cfg.POOLING_SIZE, cfg.POOLING_SIZE),
                                          1.0 / 16.0)
            self.RELPN_roi_align = ROIAlign(
                (cfg.POOLING_SIZE, cfg.POOLING_SIZE), 1.0 / 16.0, 0)
            self.RELPN_grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE

            num_rois = cfg['TRAIN'].BATCH_SIZE * 5
            self.bn_obj = nn.BatchNorm1d(4096, affine=False)
            self.bn_rel = nn.BatchNorm1d(4096, affine=False)

        reduced_pooled_feat_dim = pooled_feat_dim
        #################////////////////////////////////////////////////////////////////////take care
        self.gcn_head_rel_sub = nn.Linear(pooled_feat_dim,
                                          int(pooled_feat_dim / 2))
        self.GRCNN_obj_cls_score = nn.Linear(reduced_pooled_feat_dim,
                                             self.n_obj_classes)
        self.GRCNN_rel_cls_score = nn.Linear(reduced_pooled_feat_dim,
                                             self.n_rel_classes)

        if cfg.GCN_LAYERS > 0:

            if cfg.GCN_ON_FEATS and not cfg.GCN_SHARE_FEAT_PARAMS:  # true
                self.GRCNN_gcn_feat = _GCN_2(reduced_pooled_feat_dim,
                                             dropout=0.1)

            if cfg.GCN_HAS_ATTENTION:
                self.GRCNN_gcn_att1 = _GCN_ATT(
                    pooled_feat_dim)  # self.n_obj_classes)

            self.fcsub = nn.Linear(reduced_pooled_feat_dim,
                                   reduced_pooled_feat_dim)
            self.fcrel = nn.Linear(reduced_pooled_feat_dim,
                                   reduced_pooled_feat_dim)

        self.GRCNN_loss_obj_cls = 0
        self.GRCNN_loss_rel_cls = 0
        self.res_spinn = []
 def __init__(self, classes, class_agnostic):
     super(_fasterRCNN, self).__init__()
     self.classes = classes
     self.n_classes = len(classes)
     self.class_agnostic = class_agnostic
     # loss
     self.RCNN_loss_cls = 0
     self.RCNN_loss_bbox = 0
     #define rpn
     self.RCNN_rpn = _RPN(self.dout_base_model)  # self.dout_base_model = 512
     self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)
     # self.RCNN_roi_pool = _RoIPooling(cfg.POOLING_SIZE, cfg.POOLING_SIZE, 1.0/16.0)
     self.RCNN_roi_align = RoIAlignAvg(cfg.POOLING_SIZE, cfg.POOLING_SIZE, 1.0/16.0)
     self.grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE
     self.RCNN_roi_crop = _RoICrop()
Exemplo n.º 7
0
    def __init__(self, classes, class_agnostic):
        super(_fasterRCNN, self).__init__()
        self.classes = classes
        self.n_classes = len(classes)
        self.class_agnostic = class_agnostic
        # loss
        self.RCNN_loss_cls = 0
        self.RCNN_loss_bbox = 0

        # define rpn
        self.RCNN_rpn = _RPN(self.dout_base_model)
        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)

        # self.RCNN_roi_pool = _RoIPooling(cfg.POOLING_SIZE, cfg.POOLING_SIZE, 1.0/16.0)
        # self.RCNN_roi_align = RoIAlignAvg(cfg.POOLING_SIZE, cfg.POOLING_SIZE, 1.0/16.0)

        self.RCNN_roi_pool = ROIPool((cfg.POOLING_SIZE, cfg.POOLING_SIZE), 1.0/16.0)
        self.RCNN_roi_align = ROIAlign((cfg.POOLING_SIZE, cfg.POOLING_SIZE), 1.0/16.0, 0)
Exemplo n.º 8
0
    def __init__(self):
        super(_TDCNN, self).__init__()
        # self.classes = classes
        self.n_classes = cfg.NUM_CLASSES    # 21
        # loss
        self.RCNN_loss_cls = 0  # 多分类损失
        self.RCNN_loss_twin = 0  # 窗口回归损失

        # define rpn
        #                   self.dout_base_model=512     # (1,2000,3),(1,20,96,1,1),(1,20,96,1,1),  (1),               (1),                (256),          (1) =0
        self.RCNN_rpn = _RPN(self.dout_base_model)  #     return rois, rpn_cls_prob, rpn_twin_pred, self.rpn_loss_cls, self.rpn_loss_twin, self.rpn_label, self.rpn_loss_mask

        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)
        self.RCNN_roi_temporal_pool = _RoITemporalPooling(cfg.POOLING_LENGTH, cfg.POOLING_HEIGHT, cfg.POOLING_WIDTH, cfg.DEDUP_TWINS)


        if cfg.USE_ATTENTION:   # 不走这条路
            self.RCNN_attention = NONLocalBlock3D(self.dout_base_model, inter_channels=self.dout_base_model)
Exemplo n.º 9
0
    def __init__(self, classes, class_agnostic, loss_type, pathway):
        super(_fasterRCNN, self).__init__()
        self.classes = classes
        self.pathway = pathway
        self.n_classes = classes
        self.class_agnostic = class_agnostic
        self.loss_type = loss_type
        # loss
        self.RCNN_loss_cls = 0
        self.RCNN_loss_bbox = 0

        #define fuse layer
        if pathway == "two_pathway":
            self.fuselayer = Fuse_twopath(self.dout_base_model)

        # define rpn
        self.RCNN_rpn = _RPN(self.dout_base_model, self.n_classes)
        self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes)

        self.RCNN_roi_pool = ROIPool((cfg.POOLING_SIZE, cfg.POOLING_SIZE),
                                     1.0 / 16.0)
        self.RCNN_roi_align = ROIAlign((cfg.POOLING_SIZE, cfg.POOLING_SIZE),
                                       1.0 / 16.0, 0)