code: def inference_detector(model, img):
      """Inference image(s) with the detector.
  
      Args:
          model (nn.Module): The loaded detector.
          imgs (str/ndarray or list[str/ndarray]): Either image files or loaded
              images.
  
      Returns:
          If imgs is a str, a generator will be returned, otherwise return the
          detection results directly.
      """
      cfg = model.cfg
      device = next(model.parameters()).device  # model device
      # prepare data
      if isinstance(img, np.ndarray):
          # directly add img
          data = dict(img=img)
          cfg = cfg.copy()
          # set loading pipeline type
          cfg.data.test.pipeline[0].type = "LoadImageFromWebcam"
      else:
          # add information into dict
          data = dict(img_info=dict(filename=img), img_prefix=None)
      # build the data pipeline
      test_pipeline = Compose(cfg.data.test.pipeline)
      data = test_pipeline(data)
      data = collate([data], samples_per_gpu=1)
      if next(model.parameters()).is_cuda:
          # scatter to specified GPU
          data = scatter(data, [device])[0]
      else:
          for m in model.modules():
              assert not isinstance(
                  m, RoIPool
              ), "CPU inference with RoIPool is not supported currently."
          # just get the actual data from DataContainer
          data["img_metas"] = data["img_metas"][0].data
  
      # forward the model
      with torch.no_grad():
          result = model(return_loss=False, rescale=True, **data)[0]
      return result
  
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 2 for calling a global function with example usage: inference_detector(model, img) and returns: result