Пример #1
0
    def GenerateProposals(self, blobs_in, blobs_out, anchors, spatial_scale):
        """Op for generating RPN porposals.

        blobs_in:
          - 'rpn_cls_probs': 4D tensor of shape (N, A, H, W), where N is the
            number of minibatch images, A is the number of anchors per
            locations, and (H, W) is the spatial size of the prediction grid.
            Each value represents a "probability of object" rating in [0, 1].
          - 'rpn_bbox_pred': 4D tensor of shape (N, 4 * A, H, W) of predicted
            deltas for transformation anchor boxes into RPN proposals.
          - 'im_info': 2D tensor of shape (N, 3) where the three columns encode
            the input image's [height, width, scale]. Height and width are
            for the input to the network, not the original image; scale is the
            scale factor used to scale the original image to the network input
            size.

        blobs_out:
          - 'rpn_rois': 2D tensor of shape (R, 5), for R RPN proposals where the
            five columns encode [batch ind, x1, y1, x2, y2]. The boxes are
            w.r.t. the network input, which is a *scaled* version of the
            original image; these proposals must be scaled by 1 / scale (where
            scale comes from im_info; see above) to transform it back to the
            original input image coordinate system.
          - 'rpn_roi_probs': 1D tensor of objectness probability scores
            (extracted from rpn_cls_probs; see above).
        """
        name = 'GenerateProposalsOp:' + ','.join([str(b) for b in blobs_in])
        # spatial_scale passed to the Python op is only used in convert_pkl_to_pb
        self.net.Python(
            GenerateProposalsOp(anchors, spatial_scale, self.train).forward)(
                blobs_in, blobs_out, name=name, spatial_scale=spatial_scale)
        return blobs_out
Пример #2
0
    def GenerateProposals(self, blobs_in, blobs_out, anchors, spatial_scale):

        name = 'GenerateProposalsOp:' + ','.join([str(b) for b in blobs_in])
        # spatial_scale passed to the Python op is only used in convert_pkl_to_pb
        self.net.Python(
            GenerateProposalsOp(anchors, spatial_scale, self.train).forward)(
                blobs_in, blobs_out, name=name, spatial_scale=spatial_scale)
        return blobs_out
Пример #3
0
    def GenerateProposals(self, blobs_in, blobs_out, anchors, spatial_scale):
        """Op for generating RPN porposals.

        blobs_in:
          - 'rpn_cls_probs': 4D tensor of shape (N, A, H, W), where N is the
            number of minibatch images, A is the number of anchors per
            locations, and (H, W) is the spatial size of the prediction grid.
            Each value represents a "probability of object" rating in [0, 1].
          - 'rpn_bbox_pred': 4D tensor of shape (N, 4 * A, H, W) of predicted
            deltas for transformation anchor boxes into RPN proposals.
          - 'im_info': 2D tensor of shape (N, 3) where the three columns encode
            the input image's [height, width, scale]. Height and width are
            for the input to the network, not the original image; scale is the
            scale factor used to scale the original image to the network input
            size.

        blobs_out:
          - 'rpn_rois': 2D tensor of shape (R, 5), for R RPN proposals where the
            five columns encode [batch ind, x1, y1, x2, y2]. The boxes are
            w.r.t. the network input, which is a *scaled* version of the
            original image; these proposals must be scaled by 1 / scale (where
            scale comes from im_info; see above) to transform it back to the
            original input image coordinate system.
          - 'rpn_roi_probs': 1D tensor of objectness probability scores
            (extracted from rpn_cls_probs; see above).
        """
        cfg_key = 'TRAIN' if self.train else 'TEST'

        if cfg[cfg_key].GENERATE_PROPOSALS_ON_GPU:
            rpn_pre_nms_topN = cfg[cfg_key].RPN_PRE_NMS_TOP_N
            rpn_post_nms_topN = cfg[cfg_key].RPN_POST_NMS_TOP_N
            rpn_nms_thresh = cfg[cfg_key].RPN_NMS_THRESH
            rpn_min_size = float(cfg[cfg_key].RPN_MIN_SIZE)

            input_name = str(blobs_in[0])
            lvl = int(input_name[-1]) if input_name[-1].isdigit() else None
            anchors_name = 'anchors{}'.format(lvl) if lvl else 'anchors'

            for i in range(cfg.NUM_GPUS):
                with c2_utils.CudaScope(i):
                    workspace.FeedBlob(
                        'gpu_{}/{}'.format(i, anchors_name),
                        anchors.astype(np.float32))

            self.net.GenerateProposals(
                blobs_in + [anchors_name],
                blobs_out,
                spatial_scale=spatial_scale,
                pre_nms_topN=rpn_pre_nms_topN,
                post_nms_topN=rpn_post_nms_topN,
                nms_thresh=rpn_nms_thresh,
                min_size=rpn_min_size,
            )
        else:
            name = 'GenerateProposalsOp:' + ','.join([str(b) for b in blobs_in])
            # spatial_scale passed to the Python op is only used in
            # convert_pkl_to_pb
            self.net.Python(
                GenerateProposalsOp(anchors, spatial_scale, self.train).forward
            )(blobs_in, blobs_out, name=name, spatial_scale=spatial_scale)

        return blobs_out