import os from mmengine.config import Config from mmengine.runner import Runner def load_config(config_path): """ Load an MMEngine config file and return the config and Runner. Args: config_path (str): Path to the config file (e.g., 'configs/my_model/my_config.py'). Returns: cfg (Config): Loaded config object. runner (Runner): Runner initialized with the config. """ # Use os.path.splitext to safely get the extension base, ext = os.path.splitext(config_path) ext = ext[1:] # Remove the dot from extension if ext not in ['py', 'json', 'yaml', 'yml']: raise ValueError(f"Unsupported config file extension: .{ext}") # Load the configuration using MMEngine cfg = Config.fromfile(config_path) # Optional: Do any programmatic config updates here # e.g., cfg.work_dir = './work_dirs/my_experiment' # Initialize the runner with the loaded config runner = Runner.from_cfg(cfg) return cfg, runner