(self, loc, score,
                 anchor, img_size, scale=1.)
return roi
Propose RoIs.

        Inputs :obj:`loc, score, anchor` refer to the same anchor when indexed
        by the same index.

        On notations, :math:`R` is the total number of anchors. This is equal
        to product of the height and the width of an image and the number of
        anchor bases per pixel.

        Type of the output is same as the inputs.

        Args:
            loc (array): Predicted offsets and scaling to anchors.
                Its shape is :math:`(R, 4)`.
            score (array): Predicted foreground probability for anchors.
                Its shape is :math:`(R,)`.
            anchor (array): Coordinates of anchors. Its shape is
                :math:`(R, 4)`.
            img_size (tuple of ints): A tuple :obj:`height, width`,
                which contains image size after scaling.
            scale (float): The scaling factor used to scale an image after
                reading it from a file.

        Returns:
            array:
            An array of coordinates of proposal boxes.
            Its shape is :math:`(S, 4)`. :math:`S` is less than
            :obj:`self.n_test_post_nms` in test time and less than
            :obj:`self.n_train_post_nms` in train time. :math:`S` depends on
            the size of the predicted bounding boxes and the number of
            bounding boxes discarded by NMS.
Propose RoIs.
Propose RoIs .
def __call__(self, loc, score,
                 anchor, img_size, scale=1.):
        """Propose RoIs.

        Inputs :obj:`loc, score, anchor` refer to the same anchor when indexed
        by the same index.

        On notations, :math:`R` is the total number of anchors. This is equal
        to product of the height and the width of an image and the number of
        anchor bases per pixel.

        Type of the output is same as the inputs.

        Args:
            loc (array): Predicted offsets and scaling to anchors.
                Its shape is :math:`(R, 4)`.
            score (array): Predicted foreground probability for anchors.
                Its shape is :math:`(R,)`.
            anchor (array): Coordinates of anchors. Its shape is
                :math:`(R, 4)`.
            img_size (tuple of ints): A tuple :obj:`height, width`,
                which contains image size after scaling.
            scale (float): The scaling factor used to scale an image after
                reading it from a file.

        Returns:
            array:
            An array of coordinates of proposal boxes.
            Its shape is :math:`(S, 4)`. :math:`S` is less than
            :obj:`self.n_test_post_nms` in test time and less than
            :obj:`self.n_train_post_nms` in train time. :math:`S` depends on
            the size of the predicted bounding boxes and the number of
            bounding boxes discarded by NMS.

        """
        if chainer.config.train:
            n_pre_nms = self.n_train_pre_nms
            n_post_nms = self.n_train_post_nms
        else:
            n_pre_nms = self.n_test_pre_nms
            n_post_nms = self.n_test_post_nms

        xp = cuda.get_array_module(loc)
        loc = cuda.to_cpu(loc)
        score = cuda.to_cpu(score)
        anchor = cuda.to_cpu(anchor)

        # Convert anchors into proposal via bbox transformations.
        roi = loc2bbox(anchor, loc)

        # Clip predicted boxes to image.
        roi[:, slice(0, 4, 2)] = np.clip(
            roi[:, slice(0, 4, 2)], 0, img_size[0])
        roi[:, slice(1, 4, 2)] = np.clip(
            roi[:, slice(1, 4, 2)], 0, img_size[1])

        # Remove predicted boxes with either height or width < threshold.
        min_size = self.min_size * scale
        hs = roi[:, 2] - roi[:, 0]
        ws = roi[:, 3] - roi[:, 1]
        keep = np.where((hs >= min_size) & (ws >= min_size))[0]
        roi = roi[keep, :]
        score = score[keep]

        # Sort all (proposal, score) pairs by score from highest to lowest.
        # Take top pre_nms_topN (e.g. 6000).
        order = score.ravel().argsort()[::-1]
        if n_pre_nms > 0:
            order = order[:n_pre_nms]
        roi = roi[order, :]

        # Apply nms (e.g. threshold = 0.7).
        # Take after_nms_topN (e.g. 300).
        if xp != np and not self.force_cpu_nms:
            keep = non_maximum_suppression(
                cuda.to_gpu(roi),
                thresh=self.nms_thresh)
            keep = cuda.to_cpu(keep)
        else:
            keep = non_maximum_suppression(
                roi,
                thresh=self.nms_thresh)
        if n_post_nms > 0:
            keep = keep[:n_post_nms]
        roi = roi[keep]

        if xp != np:
            roi = cuda.to_gpu(roi)
        return roi
def __call__ ( self , loc , score , anchor , img_size , scale = 1. ) : if chainer . config . train : n_pre_nms = self . n_train_pre_nms n_post_nms = self . n_train_post_nms else : n_pre_nms = self . n_test_pre_nms n_post_nms = self . n_test_post_nms xp = cuda . get_array_module ( loc ) loc = cuda . to_cpu ( loc ) score = cuda . to_cpu ( score ) anchor = cuda . to_cpu ( anchor ) # Convert anchors into proposal via bbox transformations. roi = loc2bbox ( anchor , loc ) # Clip predicted boxes to image. roi [ : , slice ( 0 , 4 , 2 ) ] = np . clip ( roi [ : , slice ( 0 , 4 , 2 ) ] , 0 , img_size [ 0 ] ) roi [ : , slice ( 1 , 4 , 2 ) ] = np . clip ( roi [ : , slice ( 1 , 4 , 2 ) ] , 0 , img_size [ 1 ] ) # Remove predicted boxes with either height or width < threshold. min_size = self . min_size * scale hs = roi [ : , 2 ] - roi [ : , 0 ] ws = roi [ : , 3 ] - roi [ : , 1 ] keep = np . where ( ( hs >= min_size ) & ( ws >= min_size ) ) [ 0 ] roi = roi [ keep , : ] score = score [ keep ] # Sort all (proposal, score) pairs by score from highest to lowest. # Take top pre_nms_topN (e.g. 6000). order = score . ravel ( ) . argsort ( ) [ : : - 1 ] if n_pre_nms > 0 : order = order [ : n_pre_nms ] roi = roi [ order , : ] # Apply nms (e.g. threshold = 0.7). # Take after_nms_topN (e.g. 300). if xp != np and not self . force_cpu_nms : keep = non_maximum_suppression ( cuda . to_gpu ( roi ) , thresh = self . nms_thresh ) keep = cuda . to_cpu ( keep ) else : keep = non_maximum_suppression ( roi , thresh = self . nms_thresh ) if n_post_nms > 0 : keep = keep [ : n_post_nms ] roi = roi [ keep ] if xp != np : roi = cuda . to_gpu ( roi ) return roi