class_docstr: Base class for  Light-Head R-CNN.
  
  This is a base class for Light-Head R-CNN links supporting object detection
  API [#]_. The following three stages constitute Light-Head R-CNN.
  
  1. **Feature extraction**: Images are taken and their         feature maps are calculated.
  2. **Region Proposal Networks**: Given the feature maps calculated in         the previous stage, produce set of RoIs around objects.
  3. **Localization and Classification Heads**: Using feature maps that         belong to the proposed RoIs, classify the categories of the objects         in the RoIs and improve localizations.
  
  Each stage is carried out by one of the callable
  :class:`chainer.Chain` objects :obj:`feature`, :obj:`rpn` and :obj:`head`.
  
  There are two functions :meth:`predict` and :meth:`__call__` to conduct
  object detection.
  :meth:`predict` takes images and returns bounding boxes that are converted
  to image coordinates. This will be useful for a scenario when
  Light-Head R-CNN is treated as a black box function, for instance.
  :meth:`__call__` is provided for a scnerario when intermediate outputs
  are needed, for instance, for training and debugging.
  
  Links that support obejct detection API have method :meth:`predict` with
  the same interface. Please refer to :meth:`predict` for
  further details.
  
  .. [#] Zeming Li, Chao Peng, Gang Yu, Xiangyu Zhang, Yangdong Deng,     Jian Sun. Light-Head R-CNN: In Defense of Two-Stage Object Detector.     arXiv preprint arXiv:1711.07264.
  
  Args:
      extractor (callable Chain): A callable that takes a BCHW image
          array and returns feature maps.
      rpn (callable Chain): A callable that has the same interface as
          :class:`~chainercv.links.model.faster_rcnn.RegionProposalNetwork`.
          Please refer to the documentation found there.
      head (callable Chain): A callable that takes
          a BCHW array, RoIs and batch indices for RoIs. This returns class
          dependent localization paramters and class scores.
      mean (numpy.ndarray): A value to be subtracted from an image
          in :meth:`prepare`.
      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`.
      loc_normalize_mean (tuple of four floats): Mean values of
          localization estimates.
      loc_normalize_std (tupler of four floats): Standard deviation
          of localization estimates.
class_docstr_tok: ["Base","class","for","Light-Head","R-CNN",".","This","is","a","base","class","for","Light-Head","R-CNN","links","supporting","object","detection","API","[","#","]","_",".","The","following","three","stages","constitute","Light-Head","R-CNN",".","1",".","*","*","Feature","extraction","*","*",":","Images","are","taken","and","their","feature","maps","are","calculated",".","2",".","*","*","Region","Proposal","Networks","*","*",":","Given","the","feature","maps","calculated","in","the","previous","stage",",","produce","set","of","RoIs","around","objects",".","3",".","*","*","Localization","and","Classification","Heads","*","*",":","Using","feature","maps","that","belong","to","the","proposed","RoIs",",","classify","the","categories","of","the","objects","in","the","RoIs","and","improve","localizations",".","Each","stage","is","carried","out","by","one","of","the","callable",":","class",":","`","chainer.Chain","`","objects",":","obj",":","`","feature","`",",",":","obj",":","`","rpn","`","and",":","obj",":","`","head","`",".","There","are","two","functions",":","meth",":","`","predict","`","and",":","meth",":","`","__call__","`","to","conduct","object","detection",".",":","meth",":","`","predict","`","takes","images","and","returns","bounding","boxes","that","are","converted","to","image","coordinates",".","This","will","be","useful","for","a","scenario","when","Light-Head","R-CNN","is","treated","as","a","black","box","function",",","for","instance",".",":","meth",":","`","__call__","`","is","provided","for","a","scnerario","when","intermediate","outputs","are","needed",",","for","instance",",","for","training","and","debugging",".","Links","that","support","obejct","detection","API","have","method",":","meth",":","`","predict","`","with","the","same","interface",".","Please","refer","to",":","meth",":","`","predict","`","for","further","details",".","..","[","#","]","Zeming","Li",",","Chao","Peng",",","Gang","Yu",",","Xiangyu","Zhang",",","Yangdong","Deng",",","Jian","Sun",".","Light-Head","R-CNN",":","In","Defense","of","Two-Stage","Object","Detector",".","arXiv","preprint","arXiv:1711.07264",".","Args",":","extractor","(","callable","Chain",")",":","A","callable","that","takes","a","BCHW","image","array","and","returns","feature","maps",".","rpn","(","callable","Chain",")",":","A","callable","that","has","the","same","interface","as",":","class",":","`","~chainercv.links.model.faster_rcnn.RegionProposalNetwork","`",".","Please","refer","to","the","documentation","found","there",".","head","(","callable","Chain",")",":","A","callable","that","takes","a","BCHW","array",",","RoIs","and","batch","indices","for","RoIs",".","This","returns","class","dependent","localization","paramters","and","class","scores",".","mean","(","numpy.ndarray",")",":","A","value","to","be","subtracted","from","an","image","in",":","meth",":","`","prepare","`",".","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","`",".","loc_normalize_mean","(","tuple","of","four","floats",")",":","Mean","values","of","localization","estimates",".","loc_normalize_std","(","tupler","of","four","floats",")",":","Standard","deviation","of","localization","estimates","."]
docstr: Detect objects from images.
  
  This method predicts objects for each image.
  
  Args:
      imgs (iterable of numpy.ndarray): Arrays holding images.
          All images are in CHW and RGB format
          and the range of their value is :math:`[0, 255]`.
  
  Returns:
     tuple of lists:
     This method returns a tuple of three lists,
     :obj:`(bboxes, labels, scores)`.
  
     * **bboxes**: A list of float arrays of shape :math:`(R, 4)`,                where :math:`R` is the number of bounding boxes in a image.                Each bouding box is organized by                :math:`(y_{min}, x_{min}, y_{max}, x_{max})`                in the second axis.
     * **labels** : A list of integer arrays of shape :math:`(R,)`.                Each value indicates the class of the bounding box.                Values are in range :math:`[0, L - 1]`, where :math:`L` is the                number of the foreground classes.
     * **scores** : A list of float arrays of shape :math:`(R,)`.                Each value indicates how confident the prediction is.
docstr_tok: ["Detect","objects","from","images",".","This","method","predicts","objects","for","each","image",".","Args",":","imgs","(","iterable","of","numpy.ndarray",")",":","Arrays","holding","images",".","All","images","are","in","CHW","and","RGB","format","and","the","range","of","their","value","is",":","math",":","`","[","0",",","255","]","`",".","Returns",":","tuple","of","lists",":","This","method","returns","a","tuple","of","three","lists",",",":","obj",":","`","(","bboxes",",","labels",",","scores",")","`",".","*","*","*","bboxes","*","*",":","A","list","of","float","arrays","of","shape",":","math",":","`","(","R",",","4",")","`",",","where",":","math",":","`","R","`","is","the","number","of","bounding","boxes","in","a","image",".","Each","bouding","box","is","organized","by",":","math",":","`","(","y_","{","min","}",",","x_","{","min","}",",","y_","{","max","}",",","x_","{","max","}",")","`","in","the","second","axis",".","*","*","*","labels","*","*",":","A","list","of","integer","arrays","of","shape",":","math",":","`","(","R",",",")","`",".","Each","value","indicates","the","class","of","the","bounding","box",".","Values","are","in","range",":","math",":","`","[","0",",","L","-","1","]","`",",","where",":","math",":","`","L","`","is","the","number","of","the","foreground","classes",".","*","*","*","scores","*","*",":","A","list","of","float","arrays","of","shape",":","math",":","`","(","R",",",")","`",".","Each","value","indicates","how","confident","the","prediction","is","."]
code: def predict(self, imgs):
      """Detect objects from images.
  
          This method predicts objects for each image.
  
          Args:
              imgs (iterable of numpy.ndarray): Arrays holding images.
                  All images are in CHW and RGB format
                  and the range of their value is :math:`[0, 255]`.
  
          Returns:
             tuple of lists:
             This method returns a tuple of three lists,
             :obj:`(bboxes, labels, scores)`.
  
             * **bboxes**: A list of float arrays of shape :math:`(R, 4)`, \
                 where :math:`R` is the number of bounding boxes in a image. \
                 Each bouding box is organized by \
                 :math:`(y_{min}, x_{min}, y_{max}, x_{max})` \
                 in the second axis.
             * **labels** : A list of integer arrays of shape :math:`(R,)`. \
                 Each value indicates the class of the bounding box. \
                 Values are in range :math:`[0, L - 1]`, where :math:`L` is the \
                 number of the foreground classes.
             * **scores** : A list of float arrays of shape :math:`(R,)`. \
                 Each value indicates how confident the prediction is.
  
          """
      prepared_imgs = []
      sizes = []
      for img in imgs:
          size = img.shape[1:]
          img = self.prepare(img.astype(np.float32))
          prepared_imgs.append(img)
          sizes.append(size)
  
      bboxes = []
      labels = []
      scores = []
      for img, size in zip(prepared_imgs, sizes):
          with chainer.using_config(
              "train", False
          ), chainer.function.no_backprop_mode():
              img_var = chainer.Variable(self.xp.asarray(img[None]))
              scale = img_var.shape[3] / size[1]
              roi_cls_locs, roi_scores, rois, _ = self.__call__(
                  img_var, [scale]
              )
          # We are assuming that batch size is 1.
          roi_cls_loc = roi_cls_locs.array
          roi_score = roi_scores.array
          roi = rois / scale
  
          # Convert predictions to bounding boxes in image coordinates.
          # Bounding boxes are scaled to the scale of the input images.
          mean = self.xp.tile(
              self.xp.asarray(self.loc_normalize_mean), self.n_class
          )
          std = self.xp.tile(
              self.xp.asarray(self.loc_normalize_std), self.n_class
          )
          roi_cls_loc = (roi_cls_loc * std + mean).astype(np.float32)
          roi_cls_loc = roi_cls_loc.reshape((-1, self.n_class, 4))
          roi = self.xp.broadcast_to(roi[:, None], roi_cls_loc.shape)
          cls_bbox = loc2bbox(
              roi.reshape((-1, 4)), roi_cls_loc.reshape((-1, 4))
          )
          cls_bbox = cls_bbox.reshape((-1, self.n_class * 4))
          # clip bounding box
          cls_bbox[:, 0::2] = self.xp.clip(
              cls_bbox[:, 0::2], 0, size[0]
          )
          cls_bbox[:, 1::2] = self.xp.clip(
              cls_bbox[:, 1::2], 0, size[1]
          )
  
          prob = F.softmax(roi_score).array
  
          raw_cls_bbox = cuda.to_cpu(cls_bbox)
          raw_prob = cuda.to_cpu(prob)
  
          bbox, label, prob = self._suppress(raw_cls_bbox, raw_prob)
          indices = np.argsort(prob)[::-1]
          bbox = bbox[indices]
          label = label[indices]
          prob = prob[indices]
  
          bboxes.append(bbox)
          labels.append(label)
          scores.append(prob)
  
      return bboxes, labels, scores
  
file_path: chainercv/chainercv/links/model/light_head_rcnn/light_head_rcnn.py
imports: from __future__ import division
  import numpy
  import chainer
  from chainer.backends import cuda
  import chainer.functions
  from chainercv.links.model.faster_rcnn.utils.loc2bbox import loc2bbox
  from chainercv.transforms.image.resize import resize
  from chainercv.utils.bbox.non_maximum_suppression import non_maximum_suppression
label_desc: Use image node_id 7 for calling the LightHeadRCNN obj's underlying member method code with example usage: obj.predict(imgs) and returns: bboxes,  labels,  scores