class_docstr: This trial serves as the trainer for MMDetection models.  It replaces the
  `mmcv runner used by MMDetection
  <https://github.com/open-mmlab/mmdetection/blob/master/mmdet/apis/train.py>`_.
  
  For nearly all use cases, you can just use this trial definition and control behavior
  by changing the MMDetection config.  If you want to customize the trial further, you
  can use this trial as the starting point.
class_docstr_tok: ["This","trial","serves","as","the","trainer","for","MMDetection","models",".","It","replaces","the","`","mmcv","runner","used","by","MMDetection","<","https",":","\/\/github.com\/open-mmlab\/mmdetection\/blob\/master\/mmdet\/apis\/train.py",">","`","_",".","For","nearly","all","use","cases",",","you","can","just","use","this","trial","definition","and","control","behavior","by","changing","the","MMDetection","config",".","If","you","want","to","customize","the","trial","further",",","you","can","use","this","trial","as","the","starting","point","."]
code: def __init__(self, context: det_torch.PyTorchTrialContext) -> None:
      self.context = context
      self.hparams = utils.AttrDict(context.get_hparams())
      self.data_config = utils.AttrDict(context.get_data_config())
      self.cfg = self.build_mmdet_config()
      # We will control how data is moved to GPU.
      self.context.experimental.disable_auto_to_device()
  
      # Build model and make sure it's compatible with horovod.
      self.model = mmdet.models.build_detector(self.cfg.model)
  
      # Initialize model
      self.model.init_weights()
  
      # If use_pretrained, try loading pretrained weights for the mmcv config if available.
      if self.hparams.use_pretrained:
          ckpt_path, ckpt = mmdetutils.get_pretrained_ckpt_path(
              "/tmp", self.hparams.config_file
          )
          if ckpt_path is not None:
              logging.info("Loading from pretrained weights.")
              if "state_dict" in ckpt:
                  self.model.load_state_dict(ckpt["state_dict"])
              else:
                  self.model.load_state_dict(ckpt)
  
      # If fp16 is specified in the mmdet config, we will use torch native amp.
      fp16_cfg = self.cfg.get("fp16", None)
      if fp16_cfg is not None:
          self.setup_torch_amp(fp16_cfg)
  
      self.model = self.context.wrap_model(self.model)
  
      self.optimizer = self.context.wrap_optimizer(
          mmcv.runner.build_optimizer(self.model, self.cfg.optimizer)
      )
      self.model.zero_grad()
  
      self.clip_grads_fn = None
      if self.cfg.optimizer_config.grad_clip is not None:
          self.clip_grads_fn = lambda x: torch.nn.utils.clip_grad_norm_(
              x,
              self.cfg.optimizer_config.grad_clip.max_norm,
              self.cfg.optimizer_config.grad_clip.norm_type,
          )
  
      # mmdet sets loggers in the package that interrupt with Determined logging.
      # We reset the root logger after mmdet models are initialized.
      set_logger(
          bool(self.context.get_experiment_config().get("debug", False))
      )
  
imports: import logging
  import os
  from typing import Any, Dict, List
  import mmcv
  import mmcv.parallel
  import mmcv.runner
  import mmdet.core
  import mmdet.datasets
  import mmdet.models
  import numpy
  import torch
  import determined.pytorch
  from determined.common import set_logger
  from model_hub import utils
  from model_hub.mmdetection import _callbacks
  from model_hub.mmdetection import _data
  from model_hub.mmdetection import _data_backends
  from model_hub.mmdetection import utils
label_desc: Use image node_id 1 to create a new MMDetTrial object from inherited base classes: det_torch with example: obj = MMDetTrial(context)