code: def init_detector(
      config, checkpoint=None, device="cuda:0", cfg_options=None
  ):
      """Initialize a detector from config file.
  
      Args:
          config (str or :obj:`mmcv.Config`): Config file path or the config
              object.
          checkpoint (str, optional): Checkpoint path. If left as None, the model
              will not load any weights.
          cfg_options (dict): Options to override some settings in the used
              config.
  
      Returns:
          nn.Module: The constructed detector.
      """
      if isinstance(config, str):
          config = mmcv.Config.fromfile(config)
      elif not isinstance(config, mmcv.Config):
          raise TypeError(
              "config must be a filename or Config object, "
              f"but got {type(config)}"
          )
      if cfg_options is not None:
          config.merge_from_dict(cfg_options)
      config.model.pretrained = None
      model = build_detector(config.model, test_cfg=config.test_cfg)
      if checkpoint is not None:
          map_loc = "cpu" if device == "cpu" else None
          checkpoint = load_checkpoint(
              model, checkpoint, map_location=map_loc
          )
          if "CLASSES" in checkpoint["meta"]:
              model.CLASSES = checkpoint["meta"]["CLASSES"]
          else:
              warnings.simplefilter("once")
              warnings.warn(
                  "Class names are not saved in the checkpoint's "
                  "meta data, use COCO classes by default."
              )
              model.CLASSES = get_classes("coco")
      model.cfg = config  # save the config in the model for convenience
      model.to(device)
      model.eval()
      return model
  
file_path: insightface/detection/scrfd/mmdet/apis/inference.py
imports: import warnings
  import matplotlib.pyplot
  import mmcv
  import numpy
  import torch
  from mmcv.ops import RoIPool
  from mmcv.parallel import collate, scatter
  from mmcv.runner import load_checkpoint
  from mmdet.core import get_classes
  from mmdet.datasets.pipelines import Compose
  from mmdet.models import build_detector
label_desc: Use image node_id 1 for calling a global function with example usage: init_detector(config, checkpoint, device, cfg_options) and returns: model