from pathlib import Path


def model_config_dict(path):
    """
    Function returning a dictionary with the model configuration inferred from the file name.

    Parameters
    ----------
    path :
        Path to the model, either string or pathlib.Path object.

    Returns
    -------
    config : dict
        Dictionary with model configuration.

    """

    # Convert to Path
    if type(path) == str:
        path = Path(path)

    config = path.stem.split(sep='_')
    config = {config[n]: config[n + 1] for n in range(0, len(config) - 1, 2)}

    return config