Ejemplo n.º 1
0
    def setup(self, bottom, top):
        # parse the layer parameter string, which must be valid YAML
        try:
            layer_params = yaml.load(self.param_str_)
        except AttributeError:
            layer_params = yaml.load(self.param_str)

        self._feat_stride = layer_params['feat_stride']
        self._anchor_ratios = layer_params.get('ratios', (0.5, 1, 2))
        anchor_scales = layer_params.get('scales', (8, 16, 32))
        base_size = layer_params.get('base_size', 16)
        print('feat_stride: ', self._feat_stride, 'anchor_ratio: ',
              self._anchor_ratios, 'anchor_scales:', anchor_scales,
              'base_size: ', base_size)
        self._anchors = generate_anchors(scales=np.array(anchor_scales),
                                         base_size=base_size,
                                         ratios=np.array(self._anchor_ratios))
        print('anchors: ', self._anchors)
        self._num_anchors = self._anchors.shape[0]
        print('anchors_shape: ', self._anchors.shape)

        if DEBUG:
            print 'feat_stride: {}'.format(self._feat_stride)
            print 'anchors:'
            print self._anchors

        # rois blob: holds R regions of interest, each is a 5-tuple
        # (n, x1, y1, x2, y2) specifying an image batch index n and a
        # rectangle (x1, y1, x2, y2)
        top[0].reshape(1, 5)

        # scores blob: holds scores for R regions of interest
        if len(top) > 1:
            top[1].reshape(1, 1, 1, 1)
    def setup(self, bottom, top):
        # parse the layer parameter string, which must be valid YAML
        try:
            layer_params = yaml.load(self.param_str_)
        except AttributeError:
            layer_params = yaml.load(self.param_str)

        self._feat_stride = layer_params['feat_stride']
        self._anchor_ratios = layer_params.get('ratios',(0.5, 1, 2))
        anchor_scales = layer_params.get('scales', (8, 16, 32))
        base_size = layer_params.get('base_size',16)
        self._anchors = generate_anchors(scales=np.array(anchor_scales), base_size=base_size,ratios=np.array(self._anchor_ratios))
        self._num_anchors = self._anchors.shape[0]

        if DEBUG:
            print 'feat_stride: {}'.format(self._feat_stride)
            print 'anchors:'
            print self._anchors

        # rois blob: holds R regions of interest, each is a 5-tuple
        # (n, x1, y1, x2, y2) specifying an image batch index n and a
        # rectangle (x1, y1, x2, y2)
        top[0].reshape(1, 5)

        # scores blob: holds scores for R regions of interest
        if len(top) > 1:
            top[1].reshape(1, 1, 1, 1)
Ejemplo n.º 3
0
    def setup(self, bottom, top):
        try:
            layer_params = yaml.load(self.param_str_)
        except AttributeError:
            layer_params = yaml.load(self.param_str)
        # Determine if hard negative mining should be performed
        # based on the number of bottom blobs
        self._hard_mining = False
        if len(bottom) == 5:
            self._hard_mining = True
        anchor_scales = layer_params.get('scales', (8, 16, 32))
        self._anchor_ratios = layer_params.get('ratios',(0.5, 1, 2))
        base_size = layer_params.get('base_size', 16)
        self._anchors = generate_anchors(scales=np.array(anchor_scales), base_size=base_size,
                                         ratios=np.array(self._anchor_ratios))
        self._num_anchors = self._anchors.shape[0]
        self._feat_stride = layer_params['feat_stride']
        self._positive_overlap = layer_params.get('positive_overlap',cfg.TRAIN.ANCHOR_POSITIVE_OVERLAP)

        # allow boxes to sit over the edge
        self._allowed_border = layer_params.get('allowed_border', 0)

        height, width = bottom[0].data.shape[-2:]

        A = self._num_anchors
        # labels
        top[0].reshape(1, 1, A * height, width)
        # bbox_targets
        top[1].reshape(1, A * 4, height, width)
        # bbox_inside_weights
        top[2].reshape(1, A * 4, height, width)
        # bbox_outside_weights
        top[3].reshape(1, A * 4, height, width)
    def setup(self, bottom, top):
        try:
            layer_params = yaml.load(self.param_str_)
        except AttributeError:
            layer_params = yaml.load(self.param_str)
        # Determine if hard negative mining should be performed
        # based on the number of bottom blobs
        self._hard_mining = False
        if len(bottom) == 5:
            self._hard_mining = True
        anchor_scales = layer_params.get('scales', (8, 16, 32))
        self._anchor_ratios = layer_params.get('ratios',(0.5, 1, 2))
        base_size = layer_params.get('base_size', 16)
        self._anchors = generate_anchors(scales=np.array(anchor_scales), base_size=base_size,
                                         ratios=np.array(self._anchor_ratios))
        self._num_anchors = self._anchors.shape[0]
        self._feat_stride = layer_params['feat_stride']
        self._positive_overlap = layer_params.get('positive_overlap',cfg.TRAIN.ANCHOR_POSITIVE_OVERLAP)

        # allow boxes to sit over the edge
        self._allowed_border = layer_params.get('allowed_border', 0)

        height, width = bottom[0].data.shape[-2:]

        A = self._num_anchors
        # labels
        top[0].reshape(1, 1, A * height, width)
        # bbox_targets
        top[1].reshape(1, A * 4, height, width)
        # bbox_inside_weights
        top[2].reshape(1, A * 4, height, width)
        # bbox_outside_weights
        top[3].reshape(1, A * 4, height, width)