class_docstr: Estimator implementation for Mask-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","Mask-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__(self, config, logger=None, reporter=None):
      super(MaskRCNNEstimator, self).__init__(config, logger, reporter)
  
      # fix seed for mxnet, numpy and python builtin random generator.
      gutils.random.seed(self._cfg.train.seed)
  
      if self._cfg.mask_rcnn.amp:
          amp.init()
  
      # training contexts
      if self._cfg.horovod:
          self.ctx = [mx.gpu(hvd.local_rank())]
      else:
          ctx = [mx.gpu(int(i)) for i in self._cfg.gpus]
          self.ctx = ctx if ctx else [mx.cpu()]
  
      # network
      kwargs = {}
      module_list = []
      if self._cfg.mask_rcnn.use_fpn:
          module_list.append("fpn")
      if self._cfg.mask_rcnn.norm_layer is not None:
          module_list.append(self._cfg.mask_rcnn.norm_layer)
          if self._cfg.mask_rcnn.norm_layer == "bn":
              kwargs["num_devices"] = len(self.ctx)
      self.num_gpus = hvd.size() if self._cfg.horovod else len(self.ctx)
      net_name = "_".join(
          (
              "mask_rcnn",
              *module_list,
              self._cfg.mask_rcnn.backbone,
              self._cfg.dataset,
          )
      )
      if self._cfg.mask_rcnn.custom_model:
          self._cfg.mask_rcnn.use_fpn = True
          net_name = "_".join(
              (
                  "mask_rcnn_fpn",
                  self._cfg.mask_rcnn.backbone,
                  self._cfg.dataset,
              )
          )
          if self._cfg.mask_rcnn.norm_layer == "bn":
              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.mask_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
          if self._cfg.dataset == "coco":
              classes = COCODetection.CLASSES
          else:
              # default to VOC
              classes = VOCDetection.CLASSES
          self.net = get_model(
              "custom_mask_rcnn_fpn",
              classes=classes,
              transfer=None,
              dataset=self._cfg.dataset,
              pretrained_base=self._cfg.train.pretrained_base,
              base_network_name=self._cfg.mask_rcnn.backbone,
              norm_layer=norm_layer,
              norm_kwargs=norm_kwargs,
              sym_norm_kwargs=sym_norm_kwargs,
              num_fpn_filters=self._cfg.mask_rcnn.num_fpn_filters,
              num_box_head_conv=self._cfg.mask_rcnn.num_box_head_conv,
              num_box_head_conv_filters=self._cfg.mask_rcnn.num_box_head_conv_filters,
              num_box_head_dense_filters=self._cfg.mask_rcnn.num_box_head_dense_filters,
              short=self._cfg.mask_rcnn.image_short,
              max_size=self._cfg.mask_rcnn.image_max_size,
              min_stage=2,
              max_stage=6,
              nms_thresh=self._cfg.mask_rcnn.nms_thresh,
              nms_topk=self._cfg.mask_rcnn.nms_topk,
              post_nms=self._cfg.mask_rcnn.post_nms,
              roi_mode=self._cfg.mask_rcnn.roi_mode,
              roi_size=self._cfg.mask_rcnn.roi_size,
              strides=self._cfg.mask_rcnn.strides,
              clip=self._cfg.mask_rcnn.clip,
              rpn_channel=self._cfg.mask_rcnn.rpn_channel,
              base_size=self._cfg.mask_rcnn.anchor_base_size,
              scales=self._cfg.mask_rcnn.anchor_scales,
              ratios=self._cfg.mask_rcnn.anchor_aspect_ratio,
              alloc_size=self._cfg.mask_rcnn.anchor_alloc_size,
              rpn_nms_thresh=self._cfg.mask_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._cfg.train.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.mask_rcnn.max_num_gt,
              target_roi_scale=self._cfg.mask_rcnn.target_roi_scale,
              num_fcn_convs=self._cfg.mask_rcnn.num_mask_head_convs,
          )
      else:
          self.net = get_model(
              net_name,
              pretrained_base=True,
              per_device_batch_size=self._cfg.train.batch_size
              // self.num_gpus,
              **kwargs,
          )
      self._cfg.save_prefix += net_name
      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.mask_rcnn.amp:
          # Cast both weights and gradients to 'float16'
          self.net.cast("float16")
          # This layers doesn't support type 'float16'
          self.net.collect_params(".*batchnorm.*").setattr(
              "dtype", "float32"
          )
          self.net.collect_params(
              ".*normalizedperclassboxcenterencoder.*"
          ).setattr("dtype", "float32")
  
      # set up logger
      logging.basicConfig()
      self._logger = logging.getLogger()
      self._logger.setLevel(logging.INFO)
      log_file_path = self._cfg.save_prefix + "_train.log"
      log_dir = os.path.dirname(log_file_path)
      if log_dir and not os.path.exists(log_dir):
          os.makedirs(log_dir)
      fh = logging.FileHandler(log_file_path)
      self._logger.addHandler(fh)
      if MPI is None and self._cfg.horovod:
          self._logger.warning(
              "mpi4py is not installed, validation result may be incorrect."
          )
      self._logger.info(self._cfg)
  
      self.rpn_cls_loss = mx.gluon.loss.SigmoidBinaryCrossEntropyLoss(
          from_sigmoid=False
      )
      self.rpn_box_loss = mx.gluon.loss.HuberLoss(
          rho=self._cfg.train.rpn_smoothl1_rho
      )  # == smoothl1
      self.rcnn_cls_loss = mx.gluon.loss.SoftmaxCrossEntropyLoss()
      self.rcnn_box_loss = mx.gluon.loss.HuberLoss(
          rho=self._cfg.train.rcnn_smoothl1_rho
      )  # == smoothl1
      self.rcnn_mask_loss = mx.gluon.loss.SigmoidBinaryCrossEntropyLoss(
          from_sigmoid=False
      )
      self.metrics = [
          mx.metric.Loss("RPN_Conf"),
          mx.metric.Loss("RPN_SmoothL1"),
          mx.metric.Loss("RCNN_CrossEntropy"),
          mx.metric.Loss("RCNN_SmoothL1"),
          mx.metric.Loss("RCNN_Mask"),
      ]
  
      self.rpn_acc_metric = RPNAccMetric()
      self.rpn_bbox_metric = RPNL1LossMetric()
      self.rcnn_acc_metric = RCNNAccMetric()
      self.rcnn_bbox_metric = RCNNL1LossMetric()
      self.rcnn_mask_metric = MaskAccMetric()
      self.rcnn_fgmask_metric = MaskFGAccMetric()
      self.metrics2 = [
          self.rpn_acc_metric,
          self.rpn_bbox_metric,
          self.rcnn_acc_metric,
          self.rcnn_bbox_metric,
          self.rcnn_mask_metric,
          self.rcnn_fgmask_metric,
      ]
  
      self.async_eval_processes = []
      self.best_map = [0]
      self.epoch = 0
  
      # training data
      (
          self.train_dataset,
          self.val_dataset,
          self.eval_metric,
      ) = _get_dataset(self._cfg.dataset, self._cfg)
      self.batch_size = (
          self._cfg.train.batch_size // self.num_gpus
          if self._cfg.horovod
          else self._cfg.train.batch_size
      )
      self._train_data, self._val_data = _get_dataloader(
          self.net,
          self.train_dataset,
          self.val_dataset,
          MaskRCNNDefaultTrainTransform,
          MaskRCNNDefaultValTransform,
          self.batch_size,
          len(self.ctx),
          self._cfg,
      )
  
imports: import os
  import math
  import time
  import logging
  from multiprocessing import Process
  import numpy
  import mxnet
  from mxnet import gluon
  from mxnet.contrib import amp
  from ....None import data
  from ....None import utils
  from ....data import COCODetection, VOCDetection
  from ....data.transforms import presets
  from ....data.transforms.presets.rcnn import MaskRCNNDefaultTrainTransform, MaskRCNNDefaultValTransform
  from ....model_zoo import get_model
  from ....model_zoo.rcnn.mask_rcnn.data_parallel import ForwardBackwardTask
  from ....nn.bbox import BBoxClipToImage
  from ....utils.parallel import Parallel
  from ....utils.metrics.rcnn import RPNAccMetric, RPNL1LossMetric, RCNNAccMetric, RCNNL1LossMetric, MaskAccMetric, MaskFGAccMetric
  from ..base_estimator import BaseEstimator, set_default
  from .utils import _get_dataset, _get_dataloader, _save_params, _split_and_load, _get_lr_at_iter
  from .default import MaskRCNNCfg
label_desc: Use image node_id 1 to create a new MaskRCNNEstimator object from inherited base classes: BaseEstimator with example: obj = MaskRCNNEstimator(config, logger, reporter)