(self, locs, confs, anchors, in_shape)
return rois, roi_indices
Decodes back to coordinates of RoIs.

        This method decodes :obj:`locs` and :obj:`confs` returned
        by a FPN network back to :obj:`rois` and :obj:`roi_indices`.

        Args:
            locs (list of arrays): A list of arrays whose shape is
                :math:`(N, K_l, 4)`, where :math:`N` is the size of batch and
                :math:`K_l` is the number of the anchor boxes
                of the :math:`l`-th level.
            confs (list of arrays): A list of array whose shape is
                :math:`(N, K_l)`.
            anchors (list of arrays): Anchor boxes returned by :meth:`anchors`.
            in_shape (tuple of ints): The shape of input of array
                the feature extractor.

        Returns:
            tuple of two arrays:
            :obj:`rois` and :obj:`roi_indices`.

            * **rois**: An array of shape :math:`(R, 4)`, \
                where :math:`R` is the total number of RoIs in the given batch.
            * **roi_indices** : An array of shape :math:`(R,)`.
Decodes back to coordinates of RoIs.
Decodes back to coordinates of RoIs .
def decode(self, locs, confs, anchors, in_shape):
        """Decodes back to coordinates of RoIs.

        This method decodes :obj:`locs` and :obj:`confs` returned
        by a FPN network back to :obj:`rois` and :obj:`roi_indices`.

        Args:
            locs (list of arrays): A list of arrays whose shape is
                :math:`(N, K_l, 4)`, where :math:`N` is the size of batch and
                :math:`K_l` is the number of the anchor boxes
                of the :math:`l`-th level.
            confs (list of arrays): A list of array whose shape is
                :math:`(N, K_l)`.
            anchors (list of arrays): Anchor boxes returned by :meth:`anchors`.
            in_shape (tuple of ints): The shape of input of array
                the feature extractor.

        Returns:
            tuple of two arrays:
            :obj:`rois` and :obj:`roi_indices`.

            * **rois**: An array of shape :math:`(R, 4)`, \
                where :math:`R` is the total number of RoIs in the given batch.
            * **roi_indices** : An array of shape :math:`(R,)`.
        """

        if chainer.config.train:
            nms_limit_pre = self._train_nms_limit_pre
            nms_limit_post = self._train_nms_limit_post
        else:
            nms_limit_pre = self._test_nms_limit_pre
            nms_limit_post = self._test_nms_limit_post

        rois = []
        roi_indices = []
        for i in range(in_shape[0]):
            roi = []
            conf = []
            for l in range(len(self._scales)):
                loc_l = locs[l].array[i]
                conf_l = confs[l].array[i]

                roi_l = anchors[l].copy()
                # tlbr -> yxhw
                roi_l[:, 2:] -= roi_l[:, :2]
                roi_l[:, :2] += roi_l[:, 2:] / 2
                # offset
                roi_l[:, :2] += loc_l[:, :2] * roi_l[:, 2:]
                roi_l[:, 2:] *= self.xp.exp(
                    self.xp.minimum(loc_l[:, 2:], exp_clip))
                # yxhw -> tlbr
                roi_l[:, :2] -= roi_l[:, 2:] / 2
                roi_l[:, 2:] += roi_l[:, :2]
                # clip
                roi_l[:, :2] = self.xp.maximum(roi_l[:, :2], 0)
                roi_l[:, 2:] = self.xp.minimum(
                    roi_l[:, 2:], self.xp.array(in_shape[2:]))

                order = argsort(-conf_l)[:nms_limit_pre]
                roi_l = roi_l[order]
                conf_l = conf_l[order]

                mask = (roi_l[:, 2:] - roi_l[:, :2] > 0).all(axis=1)
                roi_l = roi_l[mask]
                conf_l = conf_l[mask]

                indices = utils.non_maximum_suppression(
                    roi_l, self._nms_thresh, limit=nms_limit_post)
                roi_l = roi_l[indices]
                conf_l = conf_l[indices]

                roi.append(roi_l)
                conf.append(conf_l)

            roi = self.xp.vstack(roi).astype(np.float32)
            conf = self.xp.hstack(conf).astype(np.float32)

            order = argsort(-conf)[:nms_limit_post]
            roi = roi[order]

            rois.append(roi)
            roi_indices.append(self.xp.array((i,) * len(roi)))

        rois = self.xp.vstack(rois).astype(np.float32)
        roi_indices = self.xp.hstack(roi_indices).astype(np.int32)
        return rois, roi_indices
def decode ( self , locs , confs , anchors , in_shape ) : if chainer . config . train : nms_limit_pre = self . _train_nms_limit_pre nms_limit_post = self . _train_nms_limit_post else : nms_limit_pre = self . _test_nms_limit_pre nms_limit_post = self . _test_nms_limit_post rois = [ ] roi_indices = [ ] for i in range ( in_shape [ 0 ] ) : roi = [ ] conf = [ ] for l in range ( len ( self . _scales ) ) : loc_l = locs [ l ] . array [ i ] conf_l = confs [ l ] . array [ i ] roi_l = anchors [ l ] . copy ( ) # tlbr -> yxhw roi_l [ : , 2 : ] -= roi_l [ : , : 2 ] roi_l [ : , : 2 ] += roi_l [ : , 2 : ] / 2 # offset roi_l [ : , : 2 ] += loc_l [ : , : 2 ] * roi_l [ : , 2 : ] roi_l [ : , 2 : ] *= self . xp . exp ( self . xp . minimum ( loc_l [ : , 2 : ] , exp_clip ) ) # yxhw -> tlbr roi_l [ : , : 2 ] -= roi_l [ : , 2 : ] / 2 roi_l [ : , 2 : ] += roi_l [ : , : 2 ] # clip roi_l [ : , : 2 ] = self . xp . maximum ( roi_l [ : , : 2 ] , 0 ) roi_l [ : , 2 : ] = self . xp . minimum ( roi_l [ : , 2 : ] , self . xp . array ( in_shape [ 2 : ] ) ) order = argsort ( - conf_l ) [ : nms_limit_pre ] roi_l = roi_l [ order ] conf_l = conf_l [ order ] mask = ( roi_l [ : , 2 : ] - roi_l [ : , : 2 ] > 0 ) . all ( axis = 1 ) roi_l = roi_l [ mask ] conf_l = conf_l [ mask ] indices = utils . non_maximum_suppression ( roi_l , self . _nms_thresh , limit = nms_limit_post ) roi_l = roi_l [ indices ] conf_l = conf_l [ indices ] roi . append ( roi_l ) conf . append ( conf_l ) roi = self . xp . vstack ( roi ) . astype ( np . float32 ) conf = self . xp . hstack ( conf ) . astype ( np . float32 ) order = argsort ( - conf ) [ : nms_limit_post ] roi = roi [ order ] rois . append ( roi ) roi_indices . append ( self . xp . array ( ( i , ) * len ( roi ) ) ) rois = self . xp . vstack ( rois ) . astype ( np . float32 ) roi_indices = self . xp . hstack ( roi_indices ) . astype ( np . int32 ) return rois , roi_indices