class_docstr: Estimator implementation for Faster-RCNN.
  
  Parameters
  ----------
  config : dict
      Config in nested dict.
  logger : logging.Logger, default is None
      Optional logger for this estimator, can be `None` when default setting is used.
  reporter : callable, default is None
      If set, use reporter callback to report the metrics of the current estimator.
  
  Attributes
  ----------
  _logger : logging.Logger
      The customized/default logger for this estimator.
  _logdir : str
      The temporary dir for logs.
  _cfg : autocfg.dataclass
      The configurations.
class_docstr_tok: ["Estimator","implementation","for","Faster-RCNN",".","Parameters","--","--","--","--","--","config",":","dict","Config","in","nested","dict",".","logger",":","logging.Logger",",","default","is","None","Optional","logger","for","this","estimator",",","can","be","`","None","`","when","default","setting","is","used",".","reporter",":","callable",",","default","is","None","If","set",",","use","reporter","callback","to","report","the","metrics","of","the","current","estimator",".","Attributes","--","--","--","--","--","_logger",":","logging.Logger","The","customized\/default","logger","for","this","estimator",".","_logdir",":","str","The","temporary","dir","for","logs",".","_cfg",":","autocfg.dataclass","The","configurations","."]
code: def _init_network(self, **kwargs):
      load_only = kwargs.get("load_only", False)
      if not self.num_class:
          raise ValueError(
              "Unable to create network when `num_class` is unknown. \
                  It should be inferred from dataset or resumed from saved states."
          )
      assert len(self.classes) == self.num_class
  
      # training contexts
      if self._cfg.horovod:
          self.ctx = [mx.gpu(hvd.local_rank())]
      else:
          valid_gpus = []
          if self._cfg.gpus:
              valid_gpus = self._validate_gpus(self._cfg.gpus)
              if not valid_gpus:
                  self._logger.warning(
                      "No gpu detected, fallback to cpu. You can ignore this warning if this is intended."
                  )
              elif len(valid_gpus) != len(self._cfg.gpus):
                  self._logger.warning(
                      f"Loaded on gpu({valid_gpus}), different from gpu({self._cfg.gpus})."
                  )
          ctx = [mx.gpu(int(i)) for i in valid_gpus]
          self.ctx = ctx if ctx else [mx.cpu()]
  
      # network
      kwargs = {}
      module_list = []
      if self._cfg.faster_rcnn.use_fpn:
          module_list.append("fpn")
      if self._cfg.faster_rcnn.norm_layer is not None:
          module_list.append(self._cfg.faster_rcnn.norm_layer)
          if self._cfg.faster_rcnn.norm_layer == "syncbn":
              kwargs["num_devices"] = len(self.ctx)
  
      self.num_gpus = hvd.size() if self._cfg.horovod else len(self.ctx)
  
      # adjust batch size
      self.batch_size = (
          self._cfg.train.batch_size // min(1, self.num_gpus)
          if self._cfg.horovod
          else self._cfg.train.batch_size
      )
      if not self._cfg.horovod:
          if self._cfg.train.batch_size == 1 and self.num_gpus > 1:
              self.batch_size *= self.num_gpus
          elif self._cfg.train.batch_size < self.num_gpus:
              self.batch_size = self.num_gpus
      if self.batch_size % self.num_gpus != 0:
          raise ValueError(
              f"batch_size {self._cfg.train.batch_size} must be divisible by # gpu {self.num_gpus}"
          )
  
      if self._cfg.faster_rcnn.transfer is not None:
          assert isinstance(self._cfg.faster_rcnn.transfer, str)
          self._logger.info(
              f"Using transfer learning from {self._cfg.faster_rcnn.transfer}, "
              + "the other network parameters are ignored."
          )
          self._cfg.faster_rcnn.use_fpn = (
              "fpn" in self._cfg.faster_rcnn.transfer
          )
          with warnings.catch_warnings(record=True) as w:
              warnings.simplefilter("always")
              self.net = get_model(
                  self._cfg.faster_rcnn.transfer,
                  pretrained=(not load_only),
                  per_device_batch_size=self.batch_size
                  // self.num_gpus,
                  **kwargs,
              )
              self.net.sampler._max_num_gt = (
                  self._cfg.faster_rcnn.max_num_gt
              )
          if load_only:
              with warnings.catch_warnings(record=True) as w:
                  warnings.simplefilter("always")
                  self.net.initialize()
              self.net.set_nms(nms_thresh=0)
              self.net(mx.nd.zeros((1, 3, 600, 800)))
              self.net.set_nms(
                  nms_thresh=self._cfg.faster_rcnn.nms_thresh
              )
          self.net.reset_class(
              self.classes,
              reuse_weights=[
                  cname
                  for cname in self.classes
                  if cname in self.net.classes
              ],
          )
      else:
          self._cfg.faster_rcnn.use_fpn = True
          if self._cfg.faster_rcnn.norm_layer == "syncbn":
              norm_layer = gluon.contrib.nn.SyncBatchNorm
              norm_kwargs = {"num_devices": len(self.ctx)}
              sym_norm_layer = mx.sym.contrib.SyncBatchNorm
              sym_norm_kwargs = {"ndev": len(self.ctx)}
          elif self._cfg.faster_rcnn.norm_layer == "gn":
              norm_layer = gluon.nn.GroupNorm
              norm_kwargs = {"groups": 8}
              sym_norm_layer = mx.sym.GroupNorm
              sym_norm_kwargs = {"groups": 8}
          else:
              norm_layer = gluon.nn.BatchNorm
              norm_kwargs = None
              sym_norm_layer = None
              sym_norm_kwargs = None
          with warnings.catch_warnings(record=True) as w:
              warnings.simplefilter("always")
              self.net = get_model(
                  "custom_faster_rcnn_fpn",
                  classes=self.classes,
                  transfer=None,
                  dataset=self._cfg.dataset,
                  pretrained_base=self._cfg.train.pretrained_base
                  and not load_only,
                  base_network_name=self._cfg.faster_rcnn.base_network,
                  norm_layer=norm_layer,
                  norm_kwargs=norm_kwargs,
                  sym_norm_layer=sym_norm_layer,
                  sym_norm_kwargs=sym_norm_kwargs,
                  num_fpn_filters=self._cfg.faster_rcnn.num_fpn_filters,
                  num_box_head_conv=self._cfg.faster_rcnn.num_box_head_conv,
                  num_box_head_conv_filters=self._cfg.faster_rcnn.num_box_head_conv_filters,
                  num_box_head_dense_filters=self._cfg.faster_rcnn.num_box_head_dense_filters,
                  short=self._cfg.faster_rcnn.image_short,
                  max_size=self._cfg.faster_rcnn.image_max_size,
                  min_stage=2,
                  max_stage=6,
                  nms_thresh=self._cfg.faster_rcnn.nms_thresh,
                  nms_topk=self._cfg.faster_rcnn.nms_topk,
                  roi_mode=self._cfg.faster_rcnn.roi_mode,
                  roi_size=self._cfg.faster_rcnn.roi_size,
                  strides=self._cfg.faster_rcnn.strides,
                  clip=self._cfg.faster_rcnn.clip,
                  rpn_channel=self._cfg.faster_rcnn.rpn_channel,
                  base_size=self._cfg.faster_rcnn.anchor_base_size,
                  scales=self._cfg.faster_rcnn.anchor_scales,
                  ratios=self._cfg.faster_rcnn.anchor_aspect_ratio,
                  alloc_size=self._cfg.faster_rcnn.anchor_alloc_size,
                  rpn_nms_thresh=self._cfg.faster_rcnn.rpn_nms_thresh,
                  rpn_train_pre_nms=self._cfg.train.rpn_train_pre_nms,
                  rpn_train_post_nms=self._cfg.train.rpn_train_post_nms,
                  rpn_test_pre_nms=self._cfg.valid.rpn_test_pre_nms,
                  rpn_test_post_nms=self._cfg.valid.rpn_test_post_nms,
                  rpn_min_size=self._cfg.train.rpn_min_size,
                  per_device_batch_size=self.batch_size
                  // self.num_gpus,
                  num_sample=self._cfg.train.rcnn_num_samples,
                  pos_iou_thresh=self._cfg.train.rcnn_pos_iou_thresh,
                  pos_ratio=self._cfg.train.rcnn_pos_ratio,
                  max_num_gt=self._cfg.faster_rcnn.max_num_gt,
              )
  
      if self._cfg.resume.strip():
          self.net.load_parameters(self._cfg.resume.strip())
      else:
          for param in self.net.collect_params().values():
              if param._data is not None:
                  continue
              param.initialize()
      self.net.collect_params().reset_ctx(self.ctx)
      if self._cfg.faster_rcnn.amp:
          # Cast both weights and gradients to 'float16'
          self.net.cast("float16")
          # These layers don't support type 'float16'
          self.net.collect_params(".*batchnorm.*").setattr(
              "dtype", "float32"
          )
          self.net.collect_params(
              ".*normalizedperclassboxcenterencoder.*"
          ).setattr("dtype", "float32")
      if self._cfg.resume.strip():
          self.net.load_parameters(self._cfg.resume.strip())
      else:
          for param in self.net.collect_params().values():
              if param._data is not None:
                  continue
              param.initialize()
      self.net.collect_params().reset_ctx(self.ctx)
  
imports: import os
  import math
  import time
  import warnings
  from PIL import Image
  import pandas
  import numpy
  import mxnet
  from mxnet import gluon
  from ....data.batchify import Tuple, Append
  from ....data.transforms.presets.rcnn import load_test, transform_test
  from ....data.transforms.presets.rcnn import FasterRCNNDefaultTrainTransform, FasterRCNNDefaultValTransform
  from ....model_zoo import get_model
  from ....model_zoo.rcnn.faster_rcnn.data_parallel import ForwardBackwardTask
  from ....nn.bbox import BBoxClipToImage
  from ....utils.parallel import Parallel
  from ....utils.metrics.rcnn import RPNAccMetric, RPNL1LossMetric, RCNNAccMetric, RCNNL1LossMetric
  from ....utils.metrics.voc_detection import VOC07MApMetric, VOCMApMetric
  from ..base_estimator import BaseEstimator, set_default
  from .utils import _get_lr_at_iter, _get_dataloader, _split_and_load
  from ...data.dataset import ObjectDetectionDataset
  from ..conf import _BEST_CHECKPOINT_FILE
  from ..utils import EarlyStopperOnPlateau
  from .default import FasterRCNNCfg
label_desc: Use image node_id 7 for calling the FasterRCNNEstimator obj's underlying member method code with example usage: obj._init_network() without return types