def __init__(self,
                 num_classes,
                 mode="training",
                 feat_stride=16,
                 anchor_scales=[8, 16, 32],
                 ratios=[0.5, 1, 2],
                 backbone='vgg'):
        super(FasterRCNN, self).__init__()
        self.feat_stride = feat_stride
        if backbone == 'vgg':
            self.extractor, classifier = decom_vgg16()

            self.rpn = RegionProposalNetwork(512,
                                             512,
                                             ratios=ratios,
                                             anchor_scales=anchor_scales,
                                             feat_stride=self.feat_stride,
                                             mode=mode)
            self.head = VGG16RoIHead(n_class=num_classes + 1,
                                     roi_size=7,
                                     spatial_scale=1,
                                     classifier=classifier)
        elif backbone == 'resnet50':
            self.extractor, classifier = resnet50()

            self.rpn = RegionProposalNetwork(1024,
                                             512,
                                             ratios=ratios,
                                             anchor_scales=anchor_scales,
                                             feat_stride=self.feat_stride,
                                             mode=mode)
            self.head = Resnet50RoIHead(n_class=num_classes + 1,
                                        roi_size=14,
                                        spatial_scale=1,
                                        classifier=classifier)
Ejemplo n.º 2
0
    def __init__(self,
                 num_classes,
                 mode="training",
                 loc_normalize_mean=(0., 0., 0., 0.),
                 loc_normalize_std=(0.1, 0.1, 0.2, 0.2),
                 feat_stride=16,
                 anchor_scales=[8, 16, 32],
                 ratios=[0.5, 1, 2],
                 backbone='vgg'):
        super(FasterRCNN, self).__init__()

        self.loc_normalize_mean = loc_normalize_mean
        self.loc_normalize_std = loc_normalize_std
        self.feat_stride = feat_stride
        if backbone == 'vgg':
            self.extractor, self.classifier = decom_vgg16()
            self.rpn = RegionProposalNetwork(512,
                                             512,
                                             ratios=ratios,
                                             anchor_scales=anchor_scales,
                                             feat_stride=self.feat_stride,
                                             mode=mode)
            self.head = VGG16RoIHead(n_class=num_classes + 1,
                                     roi_size=7,
                                     spatial_scale=(1. / self.feat_stride),
                                     classifier=self.classifier)
        elif backbone == 'resnet50':
            self.extractor, self.classifier = resnet50()
            # 完成RPN的3×3、两个1×1卷积、Proposal,返回 输出结果为 rpn_locs, rpn_scores, rois, roi_indices, anchor
            # 其中rois为从先验框rpn_locs中选出的得分较高的候选框
            self.rpn = RegionProposalNetwork(1024,
                                             512,
                                             ratios=ratios,
                                             anchor_scales=anchor_scales,
                                             feat_stride=self.feat_stride,
                                             mode=mode)

            self.head = Resnet50RoIHead(n_class=num_classes + 1,
                                        roi_size=14,
                                        spatial_scale=(1. / self.feat_stride),
                                        classifier=self.classifier)
Ejemplo n.º 3
0
 def __init__(self,num_classes,
             mode='training',
             loc_normalize_mean=(0.,0.,0.,0.),
             loc_normalize_std=(0.1,0.1,0.2,0.2),
             feat_stride=16,
             anchor_scales=[8, 16, 32],
             rotios = [0.5, 1, 2],
             backbone='vgg'):
     super(FasterRCNN,self).__init__()
     
     self.loc_normalize_mean = loc_normalize_mean
     self.loc_normalize_std = loc_normalize_std
     self.feat_stride = feat_stride
     
     if backbone == 'vgg' :
         self.extractor,classifier = decom_vgg16()
         self.rpn = RegionProposalNetwork(512,512, 
                                         ratios = rotios,
                                         anchor_scales = anchor_scales,
                                         feat_stride=feat_stride,
                                         mode=mode)
         self.head = VGG16RoIHead(n_class=num_classes+1,
                                 roi_size=7,
                                 spatial_scale=(1. / self.feat_stride),
                                 classifier=classifier)
     elif backbone == 'resnet50':
         self.extractor,classifier = resnet50()
         self.rpn = RegionProposalNetwork(1024,512,
                                         ratios=rotios,
                                         anchor_scales = anchor_scales,
                                         feat_stride=feat_stride,
                                         mode=mode)
         self.head = Resnet50RoIHead(n_class=num_classes+1,
                                     roi_size=14,
                                     spatial_scale=(1. / self.feat_stride),
                                     classifier=classifier)