예제 #1
0
 def __init__(
         self,
         in_channels=512,
         mid_channels=512,
         ratios=[0.5, 1, 2],
         # the anchor_scales are the edge length, not the area of the anchor. In order to get the
         # area of the anchor, take the square of it (8^2, 16^2, 32^2).
         anchor_scales=[8, 16, 32],
         feat_stride=16,
         proposal_creator_params=dict(),
 ):
     super(RegionProposalNetwork, self).__init__()
     self.anchor_base = generate_anchor_base(anchor_scales=anchor_scales,
                                             ratios=ratios)
     self.feat_stride = feat_stride
     self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
     n_anchor = self.anchor_base.shape[0]
     # first conv layer before send into RPN
     self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)
     # the 1 by 1 conv layer of score
     self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0)
     # the 1 by 1 conv layer of bbox regression
     self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0)
     normal_init(self.conv1, 0, 0.01)
     normal_init(self.score, 0, 0.01)
     normal_init(self.loc, 0, 0.01)
예제 #2
0
 def __init__(
         self,
         in_channels=512,
         mid_channels=512,
         ratios=[0.5, 1, 2],
         anchor_scales=[8, 16, 32],
         feat_stride=16,
         proposal_creator_params=dict(),
 ):
     super(RegionProposalNetwork, self).__init__()
     self.anchor_base = generate_anchor_base(anchor_scales=anchor_scales,
                                             ratios=ratios)
     self.feat_stride = feat_stride
     self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
     n_anchor = self.anchor_base.shape[0]
     self.conv1 = nn.Conv2d(in_channels,
                            mid_channels,
                            kernel_size=3,
                            stride=1,
                            padding=1)
     self.score = nn.Conv2d(mid_channels,
                            n_anchor * 2,
                            kernel_size=1,
                            stride=1,
                            padding=0)
     self.loc = nn.Conv2d(mid_channels,
                          n_anchor * 4,
                          kernel_size=1,
                          stride=1,
                          padding=0)
     normal_init(self.conv1, 0, 0.01)
     normal_init(self.score, 0, 0.01)
     normal_init(self.loc, 0, 0.01)
예제 #3
0
    def __init__(
            self,
            in_channels=512,
            mid_channels=512,
            ratios=[0.5, 1, 2],
            anchor_scales=[8, 16, 32],
            feat_stride=16,
            proposal_creator_params=dict(),
    ):
        super(RegionProposalNetwork, self).__init__()

        # 在reshaped image的尺度上,以feature map上一个点对应的一个16*16的左上角点为原点,计算得到的所有anchorbox的角点的相对坐标
        # 为了后边计算reshaped image上的所有anchor box做准备
        self.anchor_base = generate_anchor_base(anchor_scales=anchor_scales,
                                                ratios=ratios)
        self.feat_stride = feat_stride
        self.proposal_layer = ProposalCreator(
            self, **proposal_creator_params
        )  # parent_model = instance of RegionProposalNetwork, and use other default parameters
        n_anchor = self.anchor_base.shape[0]
        self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)
        self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0)
        self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0)
        normal_init(self.conv1, 0, 0.01)
        normal_init(self.score, 0, 0.01)
        normal_init(self.loc, 0, 0.01)
예제 #4
0
    def __init__(self):
        super(RegionProposalNetwork, self).__init__()
        self.anchor_base = generate_anchor_base()
        self.conv = nn.Conv2d(512, 512, 3, 1, 1)

        k = self.anchor_base.shape[0]
        self.score = nn.Conv2d(512, 2 * k, 1)
        self.loc = nn.Conv2d(512, 4 * k, 1)

        self.proposal_layer = ProposalCreator(self)

        normal_init(self.conv, 0, 0.01)
        normal_init(self.score, 0, 0.01)
        normal_init(self.loc, 0, 0.01)
예제 #5
0
 def __init__(
         self, in_channels=512, mid_channels=512, ratios=[0.5, 1, 2],
         anchor_scales=[8, 16, 32], feat_stride=16,
         proposal_creator_params=dict(),
 ):
     super(RegionProposalNetwork, self).__init__()
     self.anchor_base = generate_anchor_base( #生成anchor_base
         anchor_scales=anchor_scales, ratios=ratios)
     self.feat_stride = feat_stride #下采样倍数
     self.proposal_layer = ProposalCreator(self, **proposal_creator_params) #实例化生成roi函数
     n_anchor = self.anchor_base.shape[0] #anchor_base的数量
     self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1) #3x3卷积核
     self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0) #rpn分类层
     self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0) #rpn回归层
     normal_init(self.conv1, 0, 0.01) #初始化3x3卷积核参数
     normal_init(self.score, 0, 0.01) #初始化rpn分类层参数
     normal_init(self.loc, 0, 0.01) #初始化rpn回归层参数
    def __init__(
            self, in_channels=512, mid_channels=512, ratios=[0.5,1,2],
            anchor_scales=[8,16,32], feat_stride=16,
            proposal_creator_params=dict()):
        super(RegionProposalNetwork, self).__init__()
        self.anchor_base = generate_anchor_base(anchor_scales=anchor_scales,ratios=ratios)
        self.feat_stride = feat_stride

        self.proposal_layer = ProposalCreator(self, **proposal_creator_params)

        num_anchor_base = self.anchor_base.shape[0]  #9
        self.conv1 = torch.nn.Conv2d(in_channels, mid_channels, 3, 1, 1)
        self.score = torch.nn.Conv2d(mid_channels, num_anchor_base*2, 1, 1, 0) #二分类,obj or nobj
        self.loc = torch.nn.Conv2d(mid_channels, num_anchor_base*4, 1, 1, 0) #坐标回归
        normal_init(self.conv1, 0, 0.01)
        normal_init(self.score, 0, 0.01)
        normal_init(self.loc, 0, 0.01)
 def __init__(
         self, in_channels=512, mid_channels=512, ratios=[0.5, 1, 2],
         anchor_scales=[8, 16, 32], feat_stride=16,
         proposal_creator_params=dict(),
 ):
     super(RegionProposalNetwork, self).__init__()
     # anchor_baseは(9,4)のndarray。 anchor_scales * rations = 3 * 3なので9。x,y,w,hで4
     self.anchor_base = generate_anchor_base(
         anchor_scales=anchor_scales, ratios=ratios)
     self.feat_stride = feat_stride
     self.proposal_layer = ProposalCreator(self, **proposal_creator_params)  # これはなんだろうなぁ。
     n_anchor = self.anchor_base.shape[0]
     self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)
     self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0)  # 2k 論文でいうところのcls_layer
     self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0)  # 4k 論文でいうところのreg_layer
     normal_init(self.conv1, 0, 0.01)  # 初期化
     normal_init(self.score, 0, 0.01)  # 初期化
     normal_init(self.loc, 0, 0.01)  # 初期化
예제 #8
0
    def __init__(
            self, in_channels=512, mid_channels=512, ratios=[0.5, 1, 2],
            anchor_scales=[8, 16, 32], feat_stride=16,
            proposal_creator_params=dict(),
    ):
        super(fixed_RegionProposalNetwork, self).__init__()
        self.anchor_base = generate_anchor_base(
            anchor_scales=anchor_scales, ratios=ratios)
        self.feat_stride = feat_stride
        self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
        n_anchor = self.anchor_base.shape[0]

        self.act_quant = qt.activation_quantization(8, qt.Quant.linear)

        self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)
        self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0)
        self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0)
        normal_init(self.conv1, 0, 0.01)
        normal_init(self.score, 0, 0.01)
        normal_init(self.loc, 0, 0.01)
    def __init__(
            self, in_channels=512, mid_channels=512, ratios=[0.5, 1, 2],
            anchor_scales=[8, 16, 32], feat_stride=16,
            proposal_creator_params=dict(),
    ):
        super(RegionProposalNetwork, self).__init__()
        self.anchor_base = generate_anchor_base(
            anchor_scales=anchor_scales, ratios=ratios)
        self.feat_stride = feat_stride
        self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
        n_anchor = self.anchor_base.shape[0]                        # 9
        self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)  # 首先是加pad的512个3*3大小卷积核,输出仍为(N,512,h,w)
        #然后左右两边各有一个1 * 1卷积。
        # 左路为18个1 * 1卷积,输出为(N,18,h,w),即所有anchor的0 - 1类别概率(h * w约为2400,h * w * 9约为20000)。
        # 右路为36个1 * 1卷积,输出为(N,36,h,w),即所有anchor的回归位置参数。
        self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0) # 18,分类得分
        self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0)   # 36,回归参数

        normal_init(self.conv1, 0, 0.01)        # 归一初始化
        normal_init(self.score, 0, 0.01)
        normal_init(self.loc, 0, 0.01)
예제 #10
0
 def __init__(
         self,
         in_channels=512,
         mid_channels=512,
         ratios=[0.5, 1, 2],
         anchor_scales=[8, 16, 32],
         feat_stride=16,
         proposal_creator_params=dict(),
 ):
     super(RegionProposalNetwork, self).__init__()
     self.anchor_base = generate_base_anchor(
         anchor_scales=anchor_scales,
         ratios=ratios)  # 调用generate_anchor_base()函数,生成左上角9个anchor_base
     self.feat_stride = feat_stride
     self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
     n_anchor = self.anchor_base.shape[0]  # 9
     self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)
     self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0)
     self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0)
     normal_init(self.conv1, 0, 0.01)
     normal_init(self.score, 0, 0.01)
     normal_init(self.loc, 0, 0.01)
 def __init__(self,
              in_channels=512,
              mid_channels=512,
              ratios=[0.5, 1, 2],
              anchor_scales=[8, 16, 32],
              feat_stride=16,
              proposal_creator_params=dict()):
     super(RegionProposalNetwork, self).__init__()
     self.anchor_base = generate_anchor_base(anchor_scales=anchor_scales,
                                             ratios=ratios)
     self.feat_stride = feat_stride
     #TODO:为什么要传入这个self变量
     self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
     n_anchor = self.anchor_base.shape[0]  #9
     self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)  #卷积核3*3
     self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1,
                            0)  #卷积核 1*1,是不是物体二分类
     self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1,
                          0)  #卷积核1*1,回归框的4个坐标
     #TODO:为什么要这样初始化,以及bais要置零
     normal_init(self.conv1, 0, 0.01)
     normal_init(self.score, 0, 0.01)
     normal_init(self.loc, 0, 0.01)
 def __init__(
         self,
         in_channels=512,
         mid_channels=512,
         ratios=[0.5, 1, 2],
         anchor_scales=[8, 16, 32],
         feat_stride=16,
         proposal_creator_params=dict(),
 ):
     super(RegionProposalNetwork, self).__init__()
     self.anchor_base = generate_anchor_base(  # 创建 9 个锚框的 以 cell 为中心的相对坐标(9,4)
         anchor_scales=anchor_scales,
         ratios=ratios)
     n_anchor = self.anchor_base.shape[0]  # 每个点对应着 9 个锚框
     self.feat_stride = feat_stride  # 缩小后是原图的 1/16
     self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)
     self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0)  # 前景后景特征提取
     self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0)  # 回归特征提取
     self.proposal_layer = ProposalCreator(
         self, **proposal_creator_params)  # 输出2000个roi
     normal_init(self.conv1, 0, 0.01)  # 归一化处理
     normal_init(self.score, 0, 0.01)
     normal_init(self.loc, 0, 0.01)
예제 #13
0
 def __init__(self,
              feature_channels=512,
              mid_channels=512,
              ratios=OPT.ratios,
              anchor_scales=OPT.anchor_scales,
              sub_sample=OPT.sub_sample,
              proposal_creator_params=dict()):
     super(RegionProposalNetwork, self).__init__()
     # 第一个锚点处生成的锚点框
     self.anchor_base = generate_anchor_base(ratios=ratios,
                                             anchor_scales=anchor_scales)
     self.sub_sample = sub_sample  # 下采样的倍数,由特征提取网络决定
     self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
     # 一个锚点处的锚点框的个数
     n_anchor = self.anchor_base.shape[0]
     # rpn网络中的第一个卷积层
     self.conv1 = nn.Conv2d(in_channels=feature_channels,
                            out_channels=mid_channels,
                            kernel_size=3,
                            stride=1,
                            padding=1)
     # rpn网络背景和前景的分类层
     self.score = nn.Conv2d(in_channels=mid_channels,
                            out_channels=n_anchor * 2,
                            kernel_size=1,
                            stride=1,
                            padding=0)
     # rpn网络预测的锚点框偏移量
     self.loc = nn.Conv2d(in_channels=mid_channels,
                          out_channels=n_anchor * 4,
                          kernel_size=1,
                          stride=1,
                          padding=0)
     normal_init(self.conv1, 0, 0.01)
     normal_init(self.score, 0, 0.01)
     normal_init(self.loc, 0, 0.01)
예제 #14
0
 def __init__(
         self,
         in_channels=512,
         mid_channels=512,
         ratios=[0.5, 1, 2],
         anchor_scales=[8, 16, 32],
         feat_stride=16,
         proposal_creator_params=dict(),
 ):
     super(RegionProposalNetwork, self).__init__()
     self.anchor_base = generate_anchor_base(anchor_scales=anchor_scales,
                                             ratios=ratios)
     self.feat_stride = feat_stride
     self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
     n_anchor = self.anchor_base.shape[0]
     self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1,
                            1)  # Head layer of RPN 3*3*512
     self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1,
                            0)  # classification layer 1*1*18
     self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1,
                          0)  # regression layer 1*1*36
     normal_init(self.conv1, 0, 0.01)
     normal_init(self.score, 0, 0.01)  # ([1*18*50*50])
     normal_init(self.loc, 0, 0.01)
    def __init__(
            self,
            in_channels=512,
            mid_channels=512,
            ratios=[0.5, 1, 2],
            anchor_scales=[8, 16, 32],
            feat_stride=16,
            proposal_creator_params=dict(),
    ):
        super(RegionProposalNetwork, self).__init__()

        # 生成一个(R, 4),R = len(anchor_scales)*len(ratios)=9,[y_min, x_min, y_max, x_max]
        self.anchor_base = generate_anchor_base(anchor_scales=anchor_scales,
                                                ratios=ratios)

        self.feat_stride = feat_stride
        self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
        n_anchor = self.anchor_base.shape[0]
        self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)
        self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0)  # 2为背景和前景
        self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0)  # 4为坐标
        normal_init(self.conv1, 0, 0.01)
        normal_init(self.score, 0, 0.01)
        normal_init(self.loc, 0, 0.01)
예제 #16
0
    def __init__(
            self,
            in_channels=512,
            mid_channels=512,
            ratios=[0.5, 1, 2],
            anchor_scales=[8, 16, 32],
            feat_stride=16,
            proposal_creator_params=dict(),
    ):
        super(RegionProposalNetwork, self).__init__()
        # 生成面积为[128,256,512],比例为[0.5,1,2]的9个base anchor,[9,4]
        self.anchor_base = generate_anchor_base(anchor_scales=anchor_scales,
                                                ratios=ratios)
        self.feat_stride = feat_stride

        # proposal_layer用于生成ROI
        self.proposal_layer = ProposalCreator(self, **proposal_creator_params)
        n_anchor = self.anchor_base.shape[0]
        self.conv1 = nn.Conv2d(in_channels, mid_channels, 3, 1, 1)
        self.score = nn.Conv2d(mid_channels, n_anchor * 2, 1, 1, 0)
        self.loc = nn.Conv2d(mid_channels, n_anchor * 4, 1, 1, 0)
        normal_init(self.conv1, 0, 0.01)
        normal_init(self.score, 0, 0.01)
        normal_init(self.loc, 0, 0.01)