(self, x, img_size, scales=None)
return rpn_locs, rpn_scores, rois, roi_indices, anchor
Forward Region Proposal Network.

        Here are notations.

        * :math:`N` is batch size.
        * :math:`C` channel size of the input.
        * :math:`H` and :math:`W` are height and witdh of the input feature.
        * :math:`A` is number of anchors assigned to each pixel.

        Args:
            x (~chainer.Variable): The Features extracted from images.
                Its shape is :math:`(N, C, H, W)`.
            img_size (tuple of ints): A tuple :obj:`height, width`,
                which contains image size after scaling.
            scales (tuple of floats): The amount of scaling done to each input
                image during preprocessing.

        Returns:
            (~chainer.Variable, ~chainer.Variable, array, array, array):

            This is a tuple of five following values.

            * **rpn_locs**: Predicted bounding box offsets and scales for \
                anchors. Its shape is :math:`(N, H W A, 4)`.
            * **rpn_scores**:  Predicted foreground scores for \
                anchors. Its shape is :math:`(N, H W A, 2)`.
            * **rois**: A bounding box array containing coordinates of \
                proposal boxes.  This is a concatenation of bounding box \
                arrays from multiple images in the batch. \
                Its shape is :math:`(R', 4)`. Given :math:`R_i` predicted \
                bounding boxes from the :math:`i` th image, \
                :math:`R' = \\sum _{i=1} ^ N R_i`.
            * **roi_indices**: An array containing indices of images to \
                which RoIs correspond to. Its shape is :math:`(R',)`.
            * **anchor**: Coordinates of enumerated shifted anchors. \
                Its shape is :math:`(H W A, 4)`.
Forward Region Proposal Network.
Forward Region Proposal Network .
def forward(self, x, img_size, scales=None):
        """Forward Region Proposal Network.

        Here are notations.

        * :math:`N` is batch size.
        * :math:`C` channel size of the input.
        * :math:`H` and :math:`W` are height and witdh of the input feature.
        * :math:`A` is number of anchors assigned to each pixel.

        Args:
            x (~chainer.Variable): The Features extracted from images.
                Its shape is :math:`(N, C, H, W)`.
            img_size (tuple of ints): A tuple :obj:`height, width`,
                which contains image size after scaling.
            scales (tuple of floats): The amount of scaling done to each input
                image during preprocessing.

        Returns:
            (~chainer.Variable, ~chainer.Variable, array, array, array):

            This is a tuple of five following values.

            * **rpn_locs**: Predicted bounding box offsets and scales for \
                anchors. Its shape is :math:`(N, H W A, 4)`.
            * **rpn_scores**:  Predicted foreground scores for \
                anchors. Its shape is :math:`(N, H W A, 2)`.
            * **rois**: A bounding box array containing coordinates of \
                proposal boxes.  This is a concatenation of bounding box \
                arrays from multiple images in the batch. \
                Its shape is :math:`(R', 4)`. Given :math:`R_i` predicted \
                bounding boxes from the :math:`i` th image, \
                :math:`R' = \\sum _{i=1} ^ N R_i`.
            * **roi_indices**: An array containing indices of images to \
                which RoIs correspond to. Its shape is :math:`(R',)`.
            * **anchor**: Coordinates of enumerated shifted anchors. \
                Its shape is :math:`(H W A, 4)`.

        """

        n, _, hh, ww = x.shape
        if scales is None:
            scales = [1.0] * n
        if not isinstance(scales, chainer.utils.collections_abc.Iterable):
            scales = [scales] * n

        anchor = _enumerate_shifted_anchor(
            self.xp.array(self.anchor_base), self.feat_stride, hh, ww)
        n_anchor = anchor.shape[0] // (hh * ww)
        h = F.relu(self.conv1(x))

        rpn_locs = self.loc(h)
        rpn_locs = rpn_locs.transpose((0, 2, 3, 1)).reshape((n, -1, 4))

        rpn_scores = self.score(h)
        rpn_scores = rpn_scores.transpose((0, 2, 3, 1))
        rpn_fg_scores =\
            rpn_scores.reshape((n, hh, ww, n_anchor, 2))[:, :, :, :, 1]
        rpn_fg_scores = rpn_fg_scores.reshape((n, -1))
        rpn_scores = rpn_scores.reshape((n, -1, 2))

        rois = []
        roi_indices = []
        for i in range(n):
            roi = self.proposal_layer(
                rpn_locs[i].array, rpn_fg_scores[i].array, anchor, img_size,
                scale=scales[i])
            batch_index = i * self.xp.ones((len(roi),), dtype=np.int32)
            rois.append(roi)
            roi_indices.append(batch_index)

        rois = self.xp.concatenate(rois, axis=0)
        roi_indices = self.xp.concatenate(roi_indices, axis=0)
        return rpn_locs, rpn_scores, rois, roi_indices, anchor
def forward ( self , x , img_size , scales = None ) : n , _ , hh , ww = x . shape if scales is None : scales = [ 1.0 ] * n if not isinstance ( scales , chainer . utils . collections_abc . Iterable ) : scales = [ scales ] * n anchor = _enumerate_shifted_anchor ( self . xp . array ( self . anchor_base ) , self . feat_stride , hh , ww ) n_anchor = anchor . shape [ 0 ] // ( hh * ww ) h = F . relu ( self . conv1 ( x ) ) rpn_locs = self . loc ( h ) rpn_locs = rpn_locs . transpose ( ( 0 , 2 , 3 , 1 ) ) . reshape ( ( n , - 1 , 4 ) ) rpn_scores = self . score ( h ) rpn_scores = rpn_scores . transpose ( ( 0 , 2 , 3 , 1 ) ) rpn_fg_scores = rpn_scores . reshape ( ( n , hh , ww , n_anchor , 2 ) ) [ : , : , : , : , 1 ] rpn_fg_scores = rpn_fg_scores . reshape ( ( n , - 1 ) ) rpn_scores = rpn_scores . reshape ( ( n , - 1 , 2 ) ) rois = [ ] roi_indices = [ ] for i in range ( n ) : roi = self . proposal_layer ( rpn_locs [ i ] . array , rpn_fg_scores [ i ] . array , anchor , img_size , scale = scales [ i ] ) batch_index = i * self . xp . ones ( ( len ( roi ) , ) , dtype = np . int32 ) rois . append ( roi ) roi_indices . append ( batch_index ) rois = self . xp . concatenate ( rois , axis = 0 ) roi_indices = self . xp . concatenate ( roi_indices , axis = 0 ) return rpn_locs , rpn_scores , rois , roi_indices , anchor