|
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. |
|
""" |
|
|
|
base, ext = os.path.splitext(config_path) |
|
ext = ext[1:] |
|
|
|
if ext not in ['py', 'json', 'yaml', 'yml']: |
|
raise ValueError(f"Unsupported config file extension: .{ext}") |
|
|
|
|
|
cfg = Config.fromfile(config_path) |
|
|
|
|
|
|
|
|
|
|
|
runner = Runner.from_cfg(cfg) |
|
|
|
return cfg, runner |
|
|