def __init__(self, classes, class_agnostic): super(CoupleNet, 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.box_num_classes = 1 if class_agnostic else self.n_classes # 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_crop = _RoICrop() self.RCNN_psroi_pool_cls = PSRoIPool(cfg.POOLING_SIZE, cfg.POOLING_SIZE, spatial_scale=1/16.0, group_size=cfg.POOLING_SIZE, output_dim=self.n_classes) self.RCNN_psroi_pool_loc = PSRoIPool(cfg.POOLING_SIZE, cfg.POOLING_SIZE, spatial_scale=1/16.0, group_size=cfg.POOLING_SIZE, output_dim=self.box_num_classes * 4) self.avg_pooling = nn.AvgPool2d(kernel_size=cfg.POOLING_SIZE, stride=cfg.POOLING_SIZE) self.grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE
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 self.RCNN_roi_crop = _RoICrop()
def __init__(self, classes, class_agnostic): super(_RFCN, self).__init__() self.classes = classes self.n_classes = len(classes) self.class_agnostic = class_agnostic # loss self.RFCN_loss_cls = 0 self.RFCN_loss_bbox = 0 self.box_num_classes = (1 if class_agnostic else len(classes)) #print(self.box_num_classes) #input() # define rpn self.RFCN_rpn = _RPN(self.dout_base_model) self.RFCN_proposal_target = _ProposalTargetLayer(self.n_classes) self.RFCN_psroi_pool_cls = PSRoIPool(cfg.POOLING_SIZE, cfg.POOLING_SIZE, spatial_scale=1. / 16.0, group_size=cfg.POOLING_SIZE, output_dim=self.n_classes) self.RFCN_psroi_pool_loc = PSRoIPool(cfg.POOLING_SIZE, cfg.POOLING_SIZE, spatial_scale=1. / 16.0, group_size=cfg.POOLING_SIZE, output_dim=self.box_num_classes * 4) #self.pooling = nn.AvgPool2d(kernel_size=cfg.POOLING_SIZE, stride=cfg.POOLING_SIZE) self.grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE self.RFCN_cls_net = nn.Conv2d(512, self.n_classes * 7 * 7, [1, 1], padding=0, stride=1) nn.init.normal(self.RFCN_cls_net.weight.data, 0.0, 0.01) self.RFCN_bbox_net = nn.Conv2d(512, 4 * self.box_num_classes * 7 * 7, [1, 1], padding=0, stride=1) nn.init.normal(self.RFCN_bbox_net.weight.data, 0.0, 0.01) self.RFCN_cls_score = nn.AvgPool2d((7, 7), stride=(7, 7)) #print(self.RFCN_cls_score) #input() self.RFCN_bbox_pred = nn.AvgPool2d((7, 7), stride=(7, 7))
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)
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_adaalign = RoIAlignAdaMax(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 * 2 self.RCNN_roi_crop = _RoICrop()
def __init__(self, classes, class_agnostic, K=-1): super(_fasterRCNN, self).__init__() self.classes = classes self.n_classes = len(classes) self.class_agnostic = class_agnostic self.K = K # if K > 1, transform FasterRCNN to take a stack of K images as input # loss self.RCNN_loss_cls = 0 self.RCNN_loss_bbox = 0 # define rpn self.RCNN_rpn = _RPN(self.dout_base_model, K=self.K) self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes, K=K) 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()
def __init__(self, classes, n_way=2, n_shot=5, pos_encoding=True): super(_qkvRCNN, self).__init__() self.classes = classes self.n_classes = len(classes) # loss self.RCNN_loss_cls = 0 self.RCNN_loss_bbox = 0 # define rpn self.RCNN_rpn = _RPN(self.dout_base_model) # for proposal-target matching self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes) # pooling or align 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) # few shot rcnn head self.global_relation = True self.local_correlation = True self.pool_feat_dim = 1024 self.soft_gamma = 10 self.avgpool = nn.AvgPool2d(14, stride=1) # self.maxpool_fc = nn.MaxPool1d(49) dim_in = self.pool_feat_dim ################ self.d_k = 64 self.Q_weight = nn.Linear(dim_in, self.d_k) self.K_weight = nn.Linear(dim_in, self.d_k) self.V_weight = nn.Linear(dim_in, self.d_k) init.normal_(self.Q_weight.weight, std=0.01) init.constant_(self.Q_weight.bias, 0) init.normal_(self.K_weight.weight, std=0.01) init.constant_(self.K_weight.bias, 0) init.normal_(self.V_weight.weight, std=0.01) init.constant_(self.V_weight.bias, 0) self.ffn_layer = FFN(self.d_k * 49, dim_in) ################ self.pos_encoding = pos_encoding if pos_encoding: self.pos_encoding_layer = PositionalEncoding() ################ # few shot settings self.n_way = n_way self.n_shot = n_shot
def __init__(self, classes, class_agnostic): super(_fasterRCNN, self).__init__() #继承Module的舒适化 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 #def larger(num1, num2): return num1 if num1 > num2 else num2, this variable may be declare in other place self.RCNN_roi_crop = _RoICrop()
def __init__(self, classes, n_way=2, n_shot=5): super(_metaRCNN, self).__init__() self.classes = classes self.n_classes = len(classes) # loss self.RCNN_loss_cls = 0 self.RCNN_loss_bbox = 0 # define rpn self.RCNN_rpn = _RPN(self.dout_base_model) # for proposal-target matching self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes) # pooling or align 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) # few shot settings self.n_way = n_way self.n_shot = n_shot
def __init__(self, classes, class_agnostic, pretrained, base_model='vgg16'): 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.detector = _detector(self.classes, self.class_agnostic, pretrained, base_model=base_model)
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 * cfg.ALIGN_SAMPLE_NUM if cfg.POOLING_MODE == 'crop' else cfg.POOLING_SIZE self.RCNN_roi_crop = _RoICrop()
def __init__(self, classes, class_agnostic, model_type="attention", fusion='query'): super(_fasterRCNN, self).__init__() self.classes = classes self.n_classes = len(classes) self.class_agnostic = class_agnostic conv_nd = nn.Conv2d self.fusion = fusion if fusion == 'query': self.attention_net = attention(self.dout_base_model) elif fusion == 'attention': self.attention_net = attention_early_fusion_multi_query( self.dout_base_model) self.projection = conv_nd(in_channels=1024 * 2, out_channels=1024, kernel_size=1, stride=1, padding=0, bias=False) nn.init.xavier_uniform_(self.projection.weight) # 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) self.triplet_loss = torch.nn.MarginRankingLoss(margin=cfg.TRAIN.MARGIN)
def __init__(self): super(_TDCNN, self).__init__() self.n_classes = cfg.NUM_CLASSES # loss self.RCNN_loss_cls = 0 self.RCNN_loss_twin = 0 # define rpn self.RCNN_rpn = _RPN(self.dout_base_model) 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) self.support_pool = nn.AvgPool3d(kernel_size=(1, 7, 7), stride=(1, 7, 7)) self.cosine_pool = nn.AvgPool3d(kernel_size=(1, 4, 4), stride=(1, 4, 4)) # nl self._fusion_modules = fusion_modules(in_channels=512, shot=self.shot)
def __init__(self, n_classes, class_agnostic, meta_train, meta_test=None, meta_loss=None): super(_fasterRCNN, self).__init__() self.n_classes = n_classes self.class_agnostic = class_agnostic self.meta_train = meta_train self.meta_test = meta_test self.meta_loss = meta_loss # 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()
def __init__(self): super(_TDCNN_Fewshot, self).__init__() self.n_classes = cfg.NUM_CLASSES # loss self.RCNN_loss_cls = 0 self.RCNN_loss_twin = 0 # define rpn # region proposal network self.RCNN_rpn = _RPN(self.dout_base_model) self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes) self.pooled_feat = None print('cfg.POOLING_LENGTH: %d' % cfg.POOLING_LENGTH) # self.RCNN_roi_temporal_pool = _RoITemporalPooling(cfg.POOLING_LENGTH, cfg.POOLING_HEIGHT, cfg.POOLING_WIDTH, # cfg.DEDUP_TWINS) self.RCNN_roi_temporal_pool = _RoITemporalPooling( 1, 4, 4, cfg.DEDUP_TWINS) if cfg.USE_ATTENTION: self.RCNN_attention = NONLocalBlock3D( self.dout_base_model, inter_channels=self.dout_base_model)
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_align = RoIAlign(output_size=(cfg.POOLING_SIZE, cfg.POOLING_SIZE), spatial_scale=1.0 / 16.0, sampling_ratio=2) self.RCNN_roi_pool = RoIPool((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
def __init__(self, main_classes, sub_classes, class_agnostic, casecade_type='add_score', alpha=0.5): super(_hierarchyCasecadeFasterRCNN, self).__init__() #self.classes = classes #type: add_score, add_prob, mul_score, mul_prob self.casecade_type = casecade_type self.alpha = alpha self.main_classes = main_classes self.sub_classes = sub_classes self.n_sub_classes = len(sub_classes) self.n_main_classes = len(main_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_sub_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.RFCN_psroi_pool = None self.grid_size = cfg.POOLING_SIZE * \ 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE self.RCNN_roi_crop = _RoICrop() self.main2sub_idx_dict = defaultdict(list) for key, val in sub2main_dict.items(): try: # not all cls in dict are in this imdb self.main2sub_idx_dict[self.main_classes.index( val)].append(self.sub_classes.index(key)) except: print("key:{}, val:{} may not in this imdb".format(key, val))
def _init_modules(self): # define backbone if self.backbone_type == 'vgg': pass elif self.backbone_type == 'res101': backbone_net = resnet_backbone(num_layers=101, pretrained=self.pretrained) self.RCNN_base1, self.RCNN_base2, self.RCNN_top = backbone_net.init_modules( ) self.dout_base_model = backbone_net.dout_base_model # cross domain classifier self.netD_pixel = netD_pixel(input_dim=256, output_dim=128, context=self.lc) self.netD = netD(input_dim=1024, context=self.gc) # 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() # define RCNN pred feat_d = 2048 if self.lc: feat_d += 128 if self.gc: feat_d += 128 self.RCNN_cls_score = nn.Linear(feat_d, self.n_classes) if self.class_agnostic: self.RCNN_bbox_pred = nn.Linear(feat_d, 4) else: self.RCNN_bbox_pred = nn.Linear(feat_d, 4 * self.n_classes)
def __init__(self, classes, class_agnostic, lc, gc): super(_fasterRCNNAttention, 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.lc = lc self.gc = gc # 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.fc1 = nn.Linear(2048, 1024) self.fc2 = nn.Linear(1024, 1024) self.nongt_dim = 300 if self.training else cfg.TEST.RPN_POST_NMS_TOP_N self.attention_1 = attention_module_multi_head( nongt_dim=self.nongt_dim, fc_dim=16, feat_dim=1024, index=1, group=16, dim=(1024, 1024, 1024)) self.attention_2 = attention_module_multi_head( nongt_dim=self.nongt_dim, fc_dim=16, feat_dim=1024, index=2, group=16, dim=(1024, 1024, 1024))
def __init__(self, classes, class_agnostic,lc,gc, la_attention = False, mid_attention = 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.lc = lc self.gc = gc self.la_attention = la_attention self.mid_attention = mid_attention # 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)
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/8.0) self.RCNN_roi_align = RoIAlignAvg(cfg.POOLING_SIZE, cfg.POOLING_SIZE, 1.0/8.0) self.grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE self.RCNN_roi_crop = _RoICrop() # CAF head self.confidence_ref = nn.Linear(4096, 2) self.confidence_sens = nn.Linear(4096, 2)
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 self.RCNN_roi_crop = _RoICrop() # Start add by Jie, set the flag to use mobilenetV2 as the backbone network for feature extraction. self.dlb = False self.neg_rate = 1 # For resample
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 self.RCNN_roi_crop = _RoICrop() if cfg.GCN.RE_CLASS: self.Class_GCN = CGCN(cfg.GCN.N_FEAT, cfg.GCN.N_HID, cfg.GCN.DROPOUT, self.n_classes, t = 0.05, adj_file = cfg.GCN.ADJ_FILE)
def __init__(self, classes, class_agnostic, pooling_size, teaching=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 # define rpn self.teaching = teaching self.pooling_size = pooling_size self.RCNN_rpn = _RPN(self.dout_base_model, teaching=self.teaching) self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes) self.RCNN_roi_pool = _RoIPooling(self.pooling_size, self.pooling_size, 1.0 / 16.0) self.RCNN_roi_align = RoIAlignAvg(self.pooling_size, self.pooling_size, 1.0 / 16.0) self.grid_size = self.pooling_size * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else self.pooling_size self.RCNN_roi_crop = _RoICrop()
def __init__(self, classes, class_agnostic, lighthead=False, compact_mode=False): super(_fasterRCNN, self).__init__() self.classes = classes self.n_classes = len(classes) self.class_agnostic = class_agnostic self.lighthead = lighthead # loss self.RCNN_loss_cls = 0 self.RCNN_loss_bbox = 0 # define Large Separable Convolution Layer if self.lighthead: self.lh_mode = 'S' if compact_mode else 'L' self.lsconv = LargeSeparableConv2d(self.dout_lh_base_model, bias=False, bn=False, setting=self.lh_mode) self.lh_relu = nn.ReLU(inplace=True) # define rpn if lighthead: self.dout_base_model = self.dout_lh_base_model 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.rpn_time = None self.pre_roi_time = None self.roi_pooling_time = None self.subnet_time = None
def __init__(self, classes, class_agnostic, lc, gc, da_use_contex, in_channel=4096): 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.lc = lc self.gc = gc # define rpn self.RCNN_rpn = _RPN(self.dout_base_model) 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) self.grid_size = (cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE) self.conv_lst = nn.Conv2d(self.dout_base_model, self.n_classes - 1, 1, 1, 0) self.avg_pool = nn.AdaptiveAvgPool2d(output_size=(1, 1)) # self.bn1 = nn.BatchNorm2d(self.dout_base_model, momentum=0.01) # self.bn2 = nn.BatchNorm2d(self.n_classes-1, momentum=0.01) self.da_use_contex = da_use_contex if self.da_use_contex: if self.lc: in_channel += 128 if self.gc: in_channel += 128 self.RCNN_instanceDA = _InstanceDA(in_channel)
def __init__(self, classes, class_agnostic, rpn_batchsize): super(_fasterRCNN, self).__init__() self.classes = classes self.n_classes = len(classes) self.class_agnostic = class_agnostic self.rpn_batchsize = rpn_batchsize # loss self.RCNN_loss_cls = 0 self.RCNN_loss_bbox = 0 # define rpn self.RCNN_rpn = _RPN(self.dout_base_model, self.rpn_batchsize) self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes) #print 'INFO: pooling size is: ', cfg.POOLING_SIZE_H, cfg.POOLING_SIZE_W #self.RCNN_roi_pool = _RoIPooling(cfg.POOLING_SIZE_H, cfg.POOLING_SIZE_W, 1.0/16.0) #self.RCNN_roi_align = RoIAlignAvg(cfg.POOLING_SIZE_H, cfg.POOLING_SIZE_W, 1.0/16.0) self.RCNN_roi_pool = ROIPool((cfg.POOLING_SIZE_H, cfg.POOLING_SIZE_W), 1.0/16.0) self.RCNN_roi_align = ROIAlign((cfg.POOLING_SIZE_H, cfg.POOLING_SIZE_W), 1.0/16.0, 0) ''' RoICrop removed from pytorch-1.0 branch
def __init__(self, classes, class_agnostic): super(_RFCN, self).__init__() self.classes = classes self.n_classes = len(classes) self.n_reg_classes = (1 if class_agnostic else len(classes)) self.class_agnostic = class_agnostic self.n_bbox_reg = (4 if class_agnostic else len(classes)) # loss self.RFCN_loss_cls = 0 self.RFCN_loss_bbox = 0 # define rpn self.RFCN_rpn = _RPN(self.dout_base_model) self.RFCN_proposal_target = _ProposalTargetLayer(self.n_classes) self.RFCN_tracking_proposal_target = _TrackingProposalTargetLayer(self.n_classes) self.RFCN_psroi_cls_pool = _PSRoIPooling(cfg.POOLING_SIZE, cfg.POOLING_SIZE, spatial_scale=1.0/16.0, group_size=7, output_dim=self.n_classes) self.RFCN_psroi_loc_pool = _PSRoIPooling(cfg.POOLING_SIZE, cfg.POOLING_SIZE, spatial_scale=1.0/16.0, group_size=7, output_dim=4*self.n_reg_classes) self.grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE self.RFCN_cls_net = nn.Conv2d(512,self.n_classes*7*7, [1,1], padding=0, stride=1) nn.init.normal(self.RFCN_cls_net.weight.data, 0.0, 0.01) self.RFCN_bbox_net = nn.Conv2d(512, 4*self.n_reg_classes*7*7, [1,1], padding=0, stride=1) nn.init.normal(self.RFCN_bbox_net.weight.data, 0.0, 0.01) self.conv3_corr_layer = Correlation(pad_size=8, kernel_size=1, max_displacement=8, stride1=2, stride2=2) self.conv4_corr_layer = Correlation(pad_size=8, kernel_size=1, max_displacement=8, stride1=1, stride2=1) self.conv5_corr_layer = Correlation(pad_size=8, kernel_size=1, max_displacement=8, stride1=1, stride2=1) self.RFCN_cls_score = nn.AvgPool2d((7,7), stride=(7,7)) self.RFCN_bbox_pred = nn.AvgPool2d((7,7), stride=(7,7)) self.RFCN_tracking_pred = nn.AvgPool2d((7,7), stride=(7,7))
def __init__(self): # self : c3d_tdcnn() 将 super(_TDCNN, self).__init__( ) # 先找到_TDCNN的父类为nn.Module,然后将_TDCNN类的对象c3d_tdcnn转为nn.Module初始化 #self.classes = classes self.n_classes = cfg.NUM_CLASSES # 21 # loss self.RCNN_loss_cls = 0 self.RCNN_loss_twin = 0 # define rpn # 在初始化的过程中定义好rpn类,具体的数据在forward的时候传入 self.RCNN_rpn = _RPN(self.dout_base_model) # 传入特征图 self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes) # 21 self.RCNN_roi_temporal_pool = _RoITemporalPooling( cfg.POOLING_LENGTH, cfg.POOLING_HEIGHT, cfg.POOLING_WIDTH, cfg.DEDUP_TWINS) # 4 2 2 1./8 if cfg.USE_ATTENTION: # false self.RCNN_attention = NONLocalBlock3D( self.dout_base_model, inter_channels=self.dout_base_model)
def __init__(self, classes, class_agnostic): super(_fasterRCNN, self).__init__() self.classes = classes self.n_classes = len(classes) self.class_agnostic = class_agnostic self.RCNN_loss_cls = 0 self.RCNN_loss_bbox = 0 # RPN layer (also compute the cls loss and bbox loss for RPN layer) self.RCNN_rpn = _RPN(self.dout_base_model) # RCNN gt labels layer (produces gt labels for final cls and bbox regression) self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes) # ROIPooling or ROIAlign layer 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) # new layer self.extension_layer = extension_layers.extension_layer()
def __init__(self, classes, class_agnostic): super(_fasterRCNN_seg, 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.n_classes) 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.criterion = CrossEntropyLoss2d(size_average=False, ignore_index=255).cuda()
def __init__(self, classes, class_agnostic): super(_RFCN, 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.box_num_classes = 1 if class_agnostic else self.n_classes # define rpn self.RCNN_rpn = _RPN(self.dout_base_model) self.RCNN_proposal_target = _ProposalTargetLayer(self.n_classes) self.RCNN_psroi_pool_cls = PSRoIPool(cfg.POOLING_SIZE, cfg.POOLING_SIZE, spatial_scale=1/16.0, group_size=cfg.POOLING_SIZE, output_dim=self.n_classes) self.RCNN_psroi_pool_loc = PSRoIPool(cfg.POOLING_SIZE, cfg.POOLING_SIZE, spatial_scale=1/16.0, group_size=cfg.POOLING_SIZE, output_dim=self.box_num_classes * 4) self.pooling = nn.AvgPool2d(kernel_size=cfg.POOLING_SIZE, stride=cfg.POOLING_SIZE) self.grid_size = cfg.POOLING_SIZE * 2 if cfg.CROP_RESIZE_WITH_MAX_POOL else cfg.POOLING_SIZE