class_docstr: The mapper to preprocess the input data for training.
  
  Since the mapping may run in other processes, we write a new class and
  explicitly pass cfg to it, in the spirit of "explicitly pass resources to subprocess".
class_docstr_tok: ["The","mapper","to","preprocess","the","input","data","for","training",".","Since","the","mapping","may","run","in","other","processes",",","we","write","a","new","class","and","explicitly","pass","cfg","to","it",",","in","the","spirit","of","``","explicitly","pass","resources","to","subprocess","''","."]
docstr: Args:
      im: an image
      boxes: nx4, floatbox, gt. shoudn't be changed
      is_crowd: n,
  
  Returns:
      The anchor labels and target boxes for each pixel in the featuremap.
      fm_labels: fHxfWxNA
      fm_boxes: fHxfWxNAx4
      NA will be NUM_ANCHOR_SIZES x NUM_ANCHOR_RATIOS
docstr_tok: ["Args",":","im",":","an","image","boxes",":","nx4",",","floatbox",",","gt",".","shoud","n't","be","changed","is_crowd",":","n",",","Returns",":","The","anchor","labels","and","target","boxes","for","each","pixel","in","the","featuremap",".","fm_labels",":","fHxfWxNA","fm_boxes",":","fHxfWxNAx4","NA","will","be","NUM_ANCHOR_SIZES","x","NUM_ANCHOR_RATIOS"]
code: def get_rpn_anchor_input(self, im, boxes, is_crowd):
      """
      Args:
          im: an image
          boxes: nx4, floatbox, gt. shoudn't be changed
          is_crowd: n,
  
      Returns:
          The anchor labels and target boxes for each pixel in the featuremap.
          fm_labels: fHxfWxNA
          fm_boxes: fHxfWxNAx4
          NA will be NUM_ANCHOR_SIZES x NUM_ANCHOR_RATIOS
      """
      boxes = boxes.copy()
      all_anchors = np.copy(
          get_all_anchors(
              stride=self.cfg.RPN.ANCHOR_STRIDE,
              sizes=self.cfg.RPN.ANCHOR_SIZES,
              ratios=self.cfg.RPN.ANCHOR_RATIOS,
              max_size=self.cfg.PREPROC.MAX_SIZE,
          )
      )
      # fHxfWxAx4 -> (-1, 4)
      featuremap_anchors_flatten = all_anchors.reshape((-1, 4))
  
      # only use anchors inside the image
      inside_ind, inside_anchors = filter_boxes_inside_shape(
          featuremap_anchors_flatten, im.shape[:2]
      )
      # obtain anchor labels and their corresponding gt boxes
      anchor_labels, anchor_gt_boxes = self.get_anchor_labels(
          inside_anchors, boxes[is_crowd == 0], boxes[is_crowd == 1]
      )
  
      # Fill them back to original size: fHxfWx1, fHxfWx4
      num_anchor = self.cfg.RPN.NUM_ANCHOR
      anchorH, anchorW = all_anchors.shape[:2]
      featuremap_labels = -np.ones(
          (anchorH * anchorW * num_anchor,), dtype="int32"
      )
      featuremap_labels[inside_ind] = anchor_labels
      featuremap_labels = featuremap_labels.reshape(
          (anchorH, anchorW, num_anchor)
      )
      featuremap_boxes = np.zeros(
          (anchorH * anchorW * num_anchor, 4), dtype="float32"
      )
      featuremap_boxes[inside_ind, :] = anchor_gt_boxes
      featuremap_boxes = featuremap_boxes.reshape(
          (anchorH, anchorW, num_anchor, 4)
      )
      return featuremap_labels, featuremap_boxes
  
imports: import copy
  import itertools
  import numpy
  import cv2
  from tabulate import tabulate
  from termcolor import colored
  from tensorpack.dataflow import DataFromList, MapData, MapDataComponent, MultiProcessMapData, MultiThreadMapData, TestDataSpeed, imgaug
  from tensorpack.utils import logger
  from tensorpack.utils.argtools import log_once
  from modeling.model_rpn import get_all_anchors
  from modeling.model_fpn import get_all_anchors_fpn
  from common import CustomResize, DataFromListOfDict, box_to_point4, filter_boxes_inside_shape, np_iou, point4_to_box, polygons_to_mask
  from config import config
  from dataset import DatasetRegistry, register_coco
  from utils.np_box_ops import area
  from utils.np_box_ops import ioa
label_desc: Use image node_id 3 for calling the TrainingDataPreprocessor obj's underlying member method code with example usage: obj.get_rpn_anchor_input(im, boxes, is_crowd) and returns: featuremap_labels,  featuremap_boxes