(self, imgs)
return tuple([outputs[key] for key in self._return_values])
Conduct inference on the given images.

        The value returned by this method is decided based on
        the argument :obj:`return_values` of :meth:`__init__`.

        Examples:

            >>> from chainercv.links import FasterRCNNFPNResNet50
            >>> model = FasterRCNNFPNResNet50(
            ...     pretrained_model='coco',
            ...     return_values=['rois', 'bboxes', 'labels', 'scores'])
            >>> rois, bboxes, labels, scores = model.predict(imgs)

        Args:
            imgs (iterable of numpy.ndarray): Inputs.

        Returns:
            tuple of lists:
            The table below shows the input and possible outputs.

        .. csv-table::
            :header: Input name, shape, dtype, format

            :obj:`imgs`, ":math:`[(3, H, W)]`", :obj:`float32`, \
            "RGB, :math:`[0, 255]`"

        .. csv-table::
            :header: Output name, shape, dtype, format

            :obj:`rois`, ":math:`[(R', 4)]`", :obj:`float32`, \
            ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`"
            :obj:`bboxes`, ":math:`[(R, 4)]`", :obj:`float32`, \
            ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`"
            :obj:`scores`, ":math:`[(R,)]`", :obj:`float32`, \
            --
            :obj:`labels`, ":math:`[(R,)]`", :obj:`int32`, \
            ":math:`[0, \#fg\_class - 1]`"
            :obj:`masks`, ":math:`[(R, H, W)]`", :obj:`bool`, --
Conduct inference on the given images.
Conduct inference on the given images .
def predict(self, imgs):
        """Conduct inference on the given images.

        The value returned by this method is decided based on
        the argument :obj:`return_values` of :meth:`__init__`.

        Examples:

            >>> from chainercv.links import FasterRCNNFPNResNet50
            >>> model = FasterRCNNFPNResNet50(
            ...     pretrained_model='coco',
            ...     return_values=['rois', 'bboxes', 'labels', 'scores'])
            >>> rois, bboxes, labels, scores = model.predict(imgs)

        Args:
            imgs (iterable of numpy.ndarray): Inputs.

        Returns:
            tuple of lists:
            The table below shows the input and possible outputs.

        .. csv-table::
            :header: Input name, shape, dtype, format

            :obj:`imgs`, ":math:`[(3, H, W)]`", :obj:`float32`, \
            "RGB, :math:`[0, 255]`"

        .. csv-table::
            :header: Output name, shape, dtype, format

            :obj:`rois`, ":math:`[(R', 4)]`", :obj:`float32`, \
            ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`"
            :obj:`bboxes`, ":math:`[(R, 4)]`", :obj:`float32`, \
            ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`"
            :obj:`scores`, ":math:`[(R,)]`", :obj:`float32`, \
            --
            :obj:`labels`, ":math:`[(R,)]`", :obj:`int32`, \
            ":math:`[0, \#fg\_class - 1]`"
            :obj:`masks`, ":math:`[(R, H, W)]`", :obj:`bool`, --

        """
        outputs = {}

        sizes = [img.shape[1:] for img in imgs]
        x, scales = self.prepare(imgs)

        with chainer.using_config('train', False), chainer.no_backprop_mode():
            hs, rpn_rois, rpn_roi_indices = self(x)
            if self._store_rpn_outputs:
                rpn_rois_cpu = [
                    chainer.backends.cuda.to_cpu(rpn_roi) / scale
                    for rpn_roi, scale in
                    zip(_flat_to_list(rpn_rois, rpn_roi_indices, len(imgs)),
                        scales)]
                outputs.update({'rois': rpn_rois_cpu})

        if self._run_bbox:
            bbox_rois, bbox_roi_indices = self.bbox_head.distribute(
                rpn_rois, rpn_roi_indices)
            with chainer.using_config(
                    'train', False), chainer.no_backprop_mode():
                head_locs, head_confs = self.bbox_head(
                    hs, bbox_rois, bbox_roi_indices)
            bboxes, labels, scores = self.bbox_head.decode(
                bbox_rois, bbox_roi_indices, head_locs, head_confs,
                scales, sizes, self.nms_thresh, self.score_thresh)
            bboxes_cpu = [
                chainer.backends.cuda.to_cpu(bbox) for bbox in bboxes]
            labels_cpu = [
                chainer.backends.cuda.to_cpu(label) for label in labels]
            scores_cpu = [cuda.to_cpu(score) for score in scores]
            outputs.update({'bboxes': bboxes_cpu, 'labels': labels_cpu,
                            'scores': scores_cpu})

        if self._run_mask:
            rescaled_bboxes = [bbox * scale
                               for scale, bbox in zip(scales, bboxes)]
            # Change bboxes to RoI and RoI indices format
            mask_rois_before_reordering, mask_roi_indices_before_reordering =\
                _list_to_flat(rescaled_bboxes)
            mask_rois, mask_roi_indices, order = self.mask_head.distribute(
                mask_rois_before_reordering,
                mask_roi_indices_before_reordering)
            with chainer.using_config(
                    'train', False), chainer.no_backprop_mode():
                segms = F.sigmoid(
                    self.mask_head(hs, mask_rois, mask_roi_indices)).data
            # Put the order of proposals back to the one used by bbox head.
            segms = segms[order]
            segms = _flat_to_list(
                segms, mask_roi_indices_before_reordering, len(imgs))
            segms = [segm if segm is not None else
                     self.xp.zeros(
                         (0, self.mask_head.segm_size,
                          self.mask_head.segm_size), dtype=np.float32)
                     for segm in segms]
            segms = [chainer.backends.cuda.to_cpu(segm) for segm in segms]
            # Currently MaskHead only supports numpy inputs
            masks_cpu = self.mask_head.decode(
                segms, bboxes_cpu, labels_cpu, sizes)
            outputs.update({'masks': masks_cpu})
        return tuple([outputs[key] for key in self._return_values])
def predict ( self , imgs ) : outputs = { } sizes = [ img . shape [ 1 : ] for img in imgs ] x , scales = self . prepare ( imgs ) with chainer . using_config ( 'train' , False ) , chainer . no_backprop_mode ( ) : hs , rpn_rois , rpn_roi_indices = self ( x ) if self . _store_rpn_outputs : rpn_rois_cpu = [ chainer . backends . cuda . to_cpu ( rpn_roi ) / scale for rpn_roi , scale in zip ( _flat_to_list ( rpn_rois , rpn_roi_indices , len ( imgs ) ) , scales ) ] outputs . update ( { 'rois' : rpn_rois_cpu } ) if self . _run_bbox : bbox_rois , bbox_roi_indices = self . bbox_head . distribute ( rpn_rois , rpn_roi_indices ) with chainer . using_config ( 'train' , False ) , chainer . no_backprop_mode ( ) : head_locs , head_confs = self . bbox_head ( hs , bbox_rois , bbox_roi_indices ) bboxes , labels , scores = self . bbox_head . decode ( bbox_rois , bbox_roi_indices , head_locs , head_confs , scales , sizes , self . nms_thresh , self . score_thresh ) bboxes_cpu = [ chainer . backends . cuda . to_cpu ( bbox ) for bbox in bboxes ] labels_cpu = [ chainer . backends . cuda . to_cpu ( label ) for label in labels ] scores_cpu = [ cuda . to_cpu ( score ) for score in scores ] outputs . update ( { 'bboxes' : bboxes_cpu , 'labels' : labels_cpu , 'scores' : scores_cpu } ) if self . _run_mask : rescaled_bboxes = [ bbox * scale for scale , bbox in zip ( scales , bboxes ) ] # Change bboxes to RoI and RoI indices format mask_rois_before_reordering , mask_roi_indices_before_reordering = _list_to_flat ( rescaled_bboxes ) mask_rois , mask_roi_indices , order = self . mask_head . distribute ( mask_rois_before_reordering , mask_roi_indices_before_reordering ) with chainer . using_config ( 'train' , False ) , chainer . no_backprop_mode ( ) : segms = F . sigmoid ( self . mask_head ( hs , mask_rois , mask_roi_indices ) ) . data # Put the order of proposals back to the one used by bbox head. segms = segms [ order ] segms = _flat_to_list ( segms , mask_roi_indices_before_reordering , len ( imgs ) ) segms = [ segm if segm is not None else self . xp . zeros ( ( 0 , self . mask_head . segm_size , self . mask_head . segm_size ) , dtype = np . float32 ) for segm in segms ] segms = [ chainer . backends . cuda . to_cpu ( segm ) for segm in segms ] # Currently MaskHead only supports numpy inputs masks_cpu = self . mask_head . decode ( segms , bboxes_cpu , labels_cpu , sizes ) outputs . update ( { 'masks' : masks_cpu } ) return tuple ( [ outputs [ key ] for key in self . _return_values ] )