docstr: Args:
      proposals: BoxProposals
      roi_func (boxes -> features): a function to crop features with rois
      fastrcnn_head_func (features -> features): the fastrcnn head to apply on the cropped features
      gt_targets (gt_boxes, gt_labels):
docstr_tok: ["Args",":","proposals",":","BoxProposals","roi_func","(","boxes","-",">","features",")",":","a","function","to","crop","features","with","rois","fastrcnn_head_func","(","features","-",">","features",")",":","the","fastrcnn","head","to","apply","on","the","cropped","features","gt_targets","(","gt_boxes",",","gt_labels",")",":"]
code: def __init__(
      self,
      proposals,
      roi_func,
      fastrcnn_head_func,
      gt_targets,
      image_shape2d,
      num_categories,
  ):
      """
      Args:
          proposals: BoxProposals
          roi_func (boxes -> features): a function to crop features with rois
          fastrcnn_head_func (features -> features): the fastrcnn head to apply on the cropped features
          gt_targets (gt_boxes, gt_labels):
      """
      for k, v in locals().items():
          if k != "self":
              setattr(self, k, v)
      self.gt_boxes, self.gt_labels = gt_targets
      del self.gt_targets
  
      self.num_cascade_stages = len(cfg.CASCADE.IOUS)
  
      self.training = get_current_tower_context().is_training
      if self.training:
  
          @tf.custom_gradient
          def scale_gradient(x):
              return x, lambda dy: dy * (1.0 / self.num_cascade_stages)
  
          self.scale_gradient = scale_gradient
      else:
          self.scale_gradient = tf.identity
  
      ious = cfg.CASCADE.IOUS
      # It's unclear how to do >3 stages, so it does not make sense to implement them
      assert (
          self.num_cascade_stages == 3
      ), "Only 3-stage cascade was implemented!"
      with tf.variable_scope("cascade_rcnn_stage1"):
          H1, B1 = self.run_head(self.proposals, 0)
  
      with tf.variable_scope("cascade_rcnn_stage2"):
          B1_proposal = self.match_box_with_gt(B1, ious[1])
          H2, B2 = self.run_head(B1_proposal, 1)
  
      with tf.variable_scope("cascade_rcnn_stage3"):
          B2_proposal = self.match_box_with_gt(B2, ious[2])
          H3, B3 = self.run_head(B2_proposal, 2)
      self._cascade_boxes = [B1, B2, B3]
      self._heads = [H1, H2, H3]
  
file_path: tensorpack/examples/FasterRCNN/modeling/model_cascade.py
imports: import tensorflow
  from tensorpack.tfutils import get_current_tower_context
  from config import config
  from utils.box_ops import pairwise_iou, area
  from .model_box import clip_boxes
  from .model_frcnn import BoxProposals, FastRCNNHead, fastrcnn_outputs
label_desc: Use image node_id 1 to create a new CascadeRCNNHead object from inherited base classes: object with example: obj = CascadeRCNNHead(proposals, roi_func, fastrcnn_head_func, gt_targets, image_shape2d, num_categories)