code: def inference(args, logger):
      if digit_version(torch.__version__) < digit_version("1.12"):
          logger.warning(
              "Some config files, such as configs/yolact and configs/detectors,"
              "may have compatibility issues with torch.jit when torch<1.12. "
              "If you want to calculate flops for these models, "
              "please make sure your pytorch version is >=1.12."
          )
  
      config_name = Path(args.config)
      if not config_name.exists():
          logger.error(f"{config_name} not found.")
  
      cfg = Config.fromfile(args.config)
      cfg.val_dataloader.batch_size = 1
      cfg.work_dir = tempfile.TemporaryDirectory().name
  
      if args.cfg_options is not None:
          cfg.merge_from_dict(args.cfg_options)
  
      init_default_scope(cfg.get("default_scope", "mmdet"))
  
      # TODO: The following usage is temporary and not safe
      # use hard code to convert mmSyncBN to SyncBN. This is a known
      # bug in mmengine, mmSyncBN requires a distributed environment，
      # this question involves models like configs/strong_baselines
      if hasattr(cfg, "head_norm_cfg"):
          cfg["head_norm_cfg"] = dict(type="SyncBN", requires_grad=True)
          cfg["model"]["roi_head"]["bbox_head"]["norm_cfg"] = dict(
              type="SyncBN", requires_grad=True
          )
          cfg["model"]["roi_head"]["mask_head"]["norm_cfg"] = dict(
              type="SyncBN", requires_grad=True
          )
  
      result = {}
      avg_flops = []
      data_loader = Runner.build_dataloader(cfg.val_dataloader)
      model = MODELS.build(cfg.model)
      if torch.cuda.is_available():
          model = model.cuda()
      model = revert_sync_batchnorm(model)
      model.eval()
      _forward = model.forward
  
      for idx, data_batch in enumerate(data_loader):
          if idx == args.num_images:
              break
          data = model.data_preprocessor(data_batch)
          result["ori_shape"] = data["data_samples"][0].ori_shape
          result["pad_shape"] = data["data_samples"][0].pad_shape
          if hasattr(data["data_samples"][0], "batch_input_shape"):
              result["pad_shape"] = data["data_samples"][
                  0
              ].batch_input_shape
          model.forward = partial(
              _forward, data_samples=data["data_samples"]
          )
          outputs = get_model_complexity_info(
              model,
              None,
              inputs=data["inputs"],
              show_table=False,
              show_arch=False,
          )
          avg_flops.append(outputs["flops"])
          params = outputs["params"]
          result[
              "compute_type"
          ] = "dataloader: load a picture from the dataset"
      del data_loader
  
      mean_flops = _format_size(int(np.average(avg_flops)))
      params = _format_size(params)
      result["flops"] = mean_flops
      result["params"] = params
  
      return result
  
file_path: mmdetection/tools/analysis_tools/get_flops.py
imports: import argparse
  import tempfile
  from functools import partial
  from pathlib import Path
  import numpy
  import torch
  from mmengine.config import Config, DictAction
  from mmengine.logging import MMLogger
  from mmengine.model import revert_sync_batchnorm
  from mmengine.registry import init_default_scope
  from mmengine.runner import Runner
  from mmengine.utils import digit_version
  from mmdet.registry import MODELS
label_desc: Use image node_id 2 for calling a global function with example usage: inference(args, logger) and returns: result