class_docstr: FCIS Head for ResNet101 based implementation.
  
  This class is used as a head for FCIS.
  This outputs class-agnostice segmentation scores, class-agnostic
  localizations and classification based on feature maps in the given RoIs.
  
  Args:
      n_class (int): The number of classes possibly including the background.
      roi_size (int): Height and width of the feature maps after
          Position Sensitive RoI pooling.
      group_size (int): Group height and width for Position Sensitive
          ROI pooling.
      spatial_scale (float): Scale of the roi is resized.
      loc_normalize_mean (tuple of four floats): Mean values of
          localization estimates.
      loc_normalize_std (tupler of four floats): Standard deviation
          of localization estimates.
      iter2 (bool): if the value is set :obj:`True`, Position Sensitive
          ROI pooling is executed twice. In the second time, Position
          Sensitive ROI pooling uses improved ROIs by the localization
          parameters calculated in the first time.
      initialW (callable): Initializer for the layers.
class_docstr_tok: ["FCIS","Head","for","ResNet101","based","implementation",".","This","class","is","used","as","a","head","for","FCIS",".","This","outputs","class-agnostice","segmentation","scores",",","class-agnostic","localizations","and","classification","based","on","feature","maps","in","the","given","RoIs",".","Args",":","n_class","(","int",")",":","The","number","of","classes","possibly","including","the","background",".","roi_size","(","int",")",":","Height","and","width","of","the","feature","maps","after","Position","Sensitive","RoI","pooling",".","group_size","(","int",")",":","Group","height","and","width","for","Position","Sensitive","ROI","pooling",".","spatial_scale","(","float",")",":","Scale","of","the","roi","is","resized",".","loc_normalize_mean","(","tuple","of","four","floats",")",":","Mean","values","of","localization","estimates",".","loc_normalize_std","(","tupler","of","four","floats",")",":","Standard","deviation","of","localization","estimates",".","iter2","(","bool",")",":","if","the","value","is","set",":","obj",":","`","True","`",",","Position","Sensitive","ROI","pooling","is","executed","twice",".","In","the","second","time",",","Position","Sensitive","ROI","pooling","uses","improved","ROIs","by","the","localization","parameters","calculated","in","the","first","time",".","initialW","(","callable",")",":","Initializer","for","the","layers","."]
docstr: Forward the chain.
  
  We assume that there are :math:`N` batches.
  
  Args:
      x (~chainer.Variable): 4D image variable.
      rois (array): 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` proposed
          RoIs from the :math:`i` th image,
          :math:`R' = \sum _{i=1} ^ N R_i`.
      roi_indices (array): An array containing indices of images to
          which bounding boxes correspond to. Its shape is :math:`(R',)`.
      img_size (tuple of int): A tuple containing image size.
docstr_tok: ["Forward","the","chain",".","We","assume","that","there","are",":","math",":","`","N","`","batches",".","Args",":","x","(","~chainer.Variable",")",":","4D","image","variable",".","rois","(","array",")",":","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","`","proposed","RoIs","from","the",":","math",":","`","i","`","th","image",",",":","math",":","`","R","'","=","\\sum","_","{","i=1","}","^","N","R_i","`",".","roi_indices","(","array",")",":","An","array","containing","indices","of","images","to","which","bounding","boxes","correspond","to",".","Its","shape","is",":","math",":","`","(","R","'",",",")","`",".","img_size","(","tuple","of","int",")",":","A","tuple","containing","image","size","."]
code: def forward(self, x, rois, roi_indices, img_size, gt_roi_labels=None):
      """Forward the chain.
  
      We assume that there are :math:`N` batches.
  
      Args:
          x (~chainer.Variable): 4D image variable.
          rois (array): 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` proposed
              RoIs from the :math:`i` th image,
              :math:`R' = \\sum _{i=1} ^ N R_i`.
          roi_indices (array): An array containing indices of images to
              which bounding boxes correspond to. Its shape is :math:`(R',)`.
          img_size (tuple of int): A tuple containing image size.
  
      """
      h = F.relu(self.conv1(x))
      h_cls_seg = self.cls_seg(h)
      h_ag_loc = self.ag_loc(h)
  
      # PSROI pooling and regression
      roi_ag_seg_scores, roi_ag_locs, roi_cls_scores = self._pool(
          h_cls_seg, h_ag_loc, rois, roi_indices, gt_roi_labels
      )
      if self.iter2:
          # 2nd Iteration
          # get rois2 for more precise prediction
          roi_ag_locs = roi_ag_locs.array
          mean = self.xp.array(self.loc_normalize_mean)
          std = self.xp.array(self.loc_normalize_std)
          roi_locs = roi_ag_locs[:, 1, :]
          roi_locs = (roi_locs * std + mean).astype(np.float32)
          rois2 = loc2bbox(rois, roi_locs)
  
          rois2[:, 0::2] = self.xp.clip(rois2[:, 0::2], 0, img_size[0])
          rois2[:, 1::2] = self.xp.clip(rois2[:, 1::2], 0, img_size[1])
  
          # PSROI pooling and regression
          (
              roi_ag_seg_scores2,
              roi_ag_locs2,
              roi_cls_scores2,
          ) = self._pool(
              h_cls_seg, h_ag_loc, rois2, roi_indices, gt_roi_labels
          )
  
          # concat 1st and 2nd iteration results
          rois = self.xp.concatenate((rois, rois2))
          roi_indices = self.xp.concatenate((roi_indices, roi_indices))
          roi_ag_seg_scores = F.concat(
              (roi_ag_seg_scores, roi_ag_seg_scores2), axis=0
          )
          roi_ag_locs = F.concat((roi_ag_locs, roi_ag_locs2), axis=0)
          roi_cls_scores = F.concat(
              (roi_cls_scores, roi_cls_scores2), axis=0
          )
      return (
          roi_ag_seg_scores,
          roi_ag_locs,
          roi_cls_scores,
          rois,
          roi_indices,
      )
  
imports: from __future__ import division
  import chainer
  import chainer.functions
  import chainer.links
  import numpy
  from chainercv.experimental.links.model.fcis import FCIS
  from chainercv.functions import ps_roi_average_pooling_2d
  from chainercv.links import Conv2DBNActiv
  from chainercv.links.model.faster_rcnn.region_proposal_network import RegionProposalNetwork
  from chainercv.links.model.faster_rcnn.utils.loc2bbox import loc2bbox
  from chainercv.links.model.resnet.resblock import ResBlock
  from chainercv.links import ResNet101
  from chainercv import utils
label_desc: Use image node_id 2 for calling the FCISResNet101Head obj's underlying member method code with example usage: obj.forward(x, rois, roi_indices, img_size, gt_roi_labels) and returns: roi_ag_seg_scores,  roi_ag_locs,  roi_cls_scores,  rois,  roi_indices