code: def merge_cfg(args):
      # load config
      with open(args.config) as f:
          pred_config = yaml.safe_load(f)
  
      def merge(cfg, arg):
          # update cfg from arg directly
          merge_cfg = copy.deepcopy(cfg)
          for k, v in cfg.items():
              if k in arg:
                  merge_cfg[k] = arg[k]
              else:
                  if isinstance(v, dict):
                      merge_cfg[k] = merge(v, arg)
  
          return merge_cfg
  
      def merge_opt(cfg, arg):
          merge_cfg = copy.deepcopy(cfg)
          # merge opt
          if "opt" in arg.keys() and arg["opt"]:
              for name, value in arg[
                  "opt"
              ].items():  # example: {'MOT': {'batch_size': 3}}
                  if name not in merge_cfg.keys():
                      print("No", name, "in config file!")
                      continue
                  for sub_k, sub_v in value.items():
                      if sub_k not in merge_cfg[name].keys():
                          print(
                              "No",
                              sub_k,
                              "in config file of",
                              name,
                              "!",
                          )
                          continue
                      merge_cfg[name][sub_k] = sub_v
  
          return merge_cfg
  
      args_dict = vars(args)
      pred_config = merge(pred_config, args_dict)
      pred_config = merge_opt(pred_config, args_dict)
  
      return pred_config
  
file_path: PaddleDetection/deploy/pipeline/cfg_utils.py
imports: import ast
  import yaml
  import copy
  import argparse
  from argparse import ArgumentParser, RawDescriptionHelpFormatter
label_desc: Use image node_id 2 for calling a global function with example usage: merge_cfg(args) and returns: pred_config, merge_cfg, merge_cfg