class_docstr: Base class of Faster R-CNN with FPN.
  
  This is a base class of Faster R-CNN with FPN.
  
  Args:
      extractor (Link): A link that extracts feature maps.
          This link must have :obj:`scales`, :obj:`mean` and
          :meth:`forward`.
      rpn (Link): A link that has the same interface as
          :class:`~chainercv.links.model.fpn.RPN`.
          Please refer to the documentation found there.
      bbox_head (Link): A link that has the same interface as
          :class:`~chainercv.links.model.fpn.BboxHead`.
          Please refer to the documentation found there.
      mask_head (Link): A link that has the same interface as
          :class:`~chainercv.links.model.fpn.MaskHead`.
          Please refer to the documentation found there.
      return_values (list of strings): Determines the values
          returned by :meth:`predict`.
      min_size (int): A preprocessing paramter for :meth:`prepare`. Please
          refer to a docstring found for :meth:`prepare`.
      max_size (int): A preprocessing paramter for :meth:`prepare`. Note
          that the result of :meth:`prepare` can exceed this size due to
          alignment with stride.
  
  Parameters:
      nms_thresh (float): The threshold value
          for :func:`~chainercv.utils.non_maximum_suppression`.
          The default value is :obj:`0.45`.
          This value can be changed directly or by using :meth:`use_preset`.
      score_thresh (float): The threshold value for confidence score.
          If a bounding box whose confidence score is lower than this value,
          the bounding box will be suppressed.
          The default value is :obj:`0.6`.
          This value can be changed directly or by using :meth:`use_preset`.
class_docstr_tok: ["Base","class","of","Faster","R-CNN","with","FPN",".","This","is","a","base","class","of","Faster","R-CNN","with","FPN",".","Args",":","extractor","(","Link",")",":","A","link","that","extracts","feature","maps",".","This","link","must","have",":","obj",":","`","scales","`",",",":","obj",":","`","mean","`","and",":","meth",":","`","forward","`",".","rpn","(","Link",")",":","A","link","that","has","the","same","interface","as",":","class",":","`","~chainercv.links.model.fpn.RPN","`",".","Please","refer","to","the","documentation","found","there",".","bbox_head","(","Link",")",":","A","link","that","has","the","same","interface","as",":","class",":","`","~chainercv.links.model.fpn.BboxHead","`",".","Please","refer","to","the","documentation","found","there",".","mask_head","(","Link",")",":","A","link","that","has","the","same","interface","as",":","class",":","`","~chainercv.links.model.fpn.MaskHead","`",".","Please","refer","to","the","documentation","found","there",".","return_values","(","list","of","strings",")",":","Determines","the","values","returned","by",":","meth",":","`","predict","`",".","min_size","(","int",")",":","A","preprocessing","paramter","for",":","meth",":","`","prepare","`",".","Please","refer","to","a","docstring","found","for",":","meth",":","`","prepare","`",".","max_size","(","int",")",":","A","preprocessing","paramter","for",":","meth",":","`","prepare","`",".","Note","that","the","result","of",":","meth",":","`","prepare","`","can","exceed","this","size","due","to","alignment","with","stride",".","Parameters",":","nms_thresh","(","float",")",":","The","threshold","value","for",":","func",":","`","~chainercv.utils.non_maximum_suppression","`",".","The","default","value","is",":","obj",":","`","0.45","`",".","This","value","can","be","changed","directly","or","by","using",":","meth",":","`","use_preset","`",".","score_thresh","(","float",")",":","The","threshold","value","for","confidence","score",".","If","a","bounding","box","whose","confidence","score","is","lower","than","this","value",",","the","bounding","box","will","be","suppressed",".","The","default","value","is",":","obj",":","`","0.6","`",".","This","value","can","be","changed","directly","or","by","using",":","meth",":","`","use_preset","`","."]
docstr: 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`, --
docstr_tok: ["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","`",",","--"]
code: 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])
  
file_path: chainercv/chainercv/links/model/fpn/faster_rcnn.py
imports: from __future__ import division
  import numpy
  import chainer
  from chainer.backends import cuda
  import chainer.functions
  from chainercv.links.model.fpn.misc import scale_img
label_desc: Use image node_id 4 for calling the FasterRCNN obj's underlying member method code with example usage: obj.predict(imgs) and returns: tuple