File size: 995 Bytes
3c5b534 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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
|