code: def main():
      args = parse_args()
  
      assert (
          args.out
          or args.eval
          or args.format_only
          or args.show
          or args.show_dir
      ), (
          "Please specify at least one operation (save/eval/format/show the "
          'results / save the results) with the argument "--out", "--eval"'
          ', "--format-only", "--show" or "--show-dir"'
      )
  
      if args.eval and args.format_only:
          raise ValueError(
              "--eval and --format_only cannot be both specified"
          )
  
      if args.out is not None and not args.out.endswith(
          (".pkl", ".pickle")
      ):
          raise ValueError("The output file must be a pkl file.")
  
      cfg = Config.fromfile(args.config)
      if args.cfg_options is not None:
          cfg.merge_from_dict(args.cfg_options)
      # import modules from string list.
      if cfg.get("custom_imports", None):
          from mmcv.utils import import_modules_from_strings
  
          import_modules_from_strings(**cfg["custom_imports"])
      # set cudnn_benchmark
      if cfg.get("cudnn_benchmark", False):
          torch.backends.cudnn.benchmark = True
      cfg.model.pretrained = None
      if cfg.model.get("neck"):
          if isinstance(cfg.model.neck, list):
              for neck_cfg in cfg.model.neck:
                  if neck_cfg.get("rfp_backbone"):
                      if neck_cfg.rfp_backbone.get("pretrained"):
                          neck_cfg.rfp_backbone.pretrained = None
          elif cfg.model.neck.get("rfp_backbone"):
              if cfg.model.neck.rfp_backbone.get("pretrained"):
                  cfg.model.neck.rfp_backbone.pretrained = None
  
      # in case the test dataset is concatenated
      if isinstance(cfg.data.test, dict):
          cfg.data.test.test_mode = True
      elif isinstance(cfg.data.test, list):
          for ds_cfg in cfg.data.test:
              ds_cfg.test_mode = True
  
      # init distributed env first, since logger depends on the dist info.
      if args.launcher == "none":
          distributed = False
      else:
          distributed = True
          init_dist(args.launcher, **cfg.dist_params)
  
      # build the dataloader
      samples_per_gpu = cfg.data.test.pop("samples_per_gpu", 1)
      if samples_per_gpu > 1:
          # Replace 'ImageToTensor' to 'DefaultFormatBundle'
          cfg.data.test.pipeline = replace_ImageToTensor(
              cfg.data.test.pipeline
          )
      dataset = build_dataset(cfg.data.test)
      data_loader = build_dataloader(
          dataset,
          samples_per_gpu=samples_per_gpu,
          workers_per_gpu=cfg.data.workers_per_gpu,
          dist=distributed,
          shuffle=False,
      )
  
      # build the model and load checkpoint
      model = build_detector(
          cfg.model, train_cfg=None, test_cfg=cfg.test_cfg
      )
      fp16_cfg = cfg.get("fp16", None)
      if fp16_cfg is not None:
          wrap_fp16_model(model)
      checkpoint = load_checkpoint(
          model, args.checkpoint, map_location="cpu"
      )
      if args.fuse_conv_bn:
          model = fuse_conv_bn(model)
      # old versions did not save class info in checkpoints, this walkaround is
      # for backward compatibility
      if "CLASSES" in checkpoint["meta"]:
          model.CLASSES = checkpoint["meta"]["CLASSES"]
      else:
          model.CLASSES = dataset.CLASSES
  
      if not distributed:
          model = MMDataParallel(model, device_ids=[0])
          outputs = single_gpu_test(
              model,
              data_loader,
              args.show,
              args.show_dir,
              args.show_score_thr,
          )
      else:
          model = MMDistributedDataParallel(
              model.cuda(),
              device_ids=[torch.cuda.current_device()],
              broadcast_buffers=False,
          )
          outputs = multi_gpu_test(
              model, data_loader, args.tmpdir, args.gpu_collect
          )
  
      rank, _ = get_dist_info()
      if rank == 0:
          if args.out:
              print(f"\nwriting results to {args.out}")
              mmcv.dump(outputs, args.out)
          kwargs = (
              {} if args.eval_options is None else args.eval_options
          )
          if args.format_only:
              dataset.format_results(outputs, **kwargs)
          if args.eval:
              eval_kwargs = cfg.get("evaluation", {}).copy()
              # hard-code way to remove EvalHook args
              for key in [
                  "interval",
                  "tmpdir",
                  "start",
                  "gpu_collect",
                  "save_best",
                  "rule",
              ]:
                  eval_kwargs.pop(key, None)
              eval_kwargs.update(dict(metric=args.eval, **kwargs))
              print(dataset.evaluate(outputs, **eval_kwargs))
  
file_path: insightface/detection/scrfd/tools/test.py
imports: import argparse
  import os
  import warnings
  import mmcv
  import torch
  from mmcv import Config, DictAction
  from mmcv.cnn import fuse_conv_bn
  from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
  from mmcv.runner import get_dist_info, init_dist, load_checkpoint, wrap_fp16_model
  from mmdet.apis import multi_gpu_test, single_gpu_test
  from mmdet.datasets import build_dataloader, build_dataset, replace_ImageToTensor
  from mmdet.models import build_detector
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types