def to_nested_dict(config: dict) -> dict:
    """Convert a flattened dictionary to a nested dictionary.

    This function takes a dictionary with dot-separated keys and converts it into a nested
    dictionary structure. Keys containing dots (`.`) are split and used to create nested
    dictionaries.

    Args:
        config: Flattened dictionary where keys can contain dots to indicate nesting
               levels. For example, ``"dataset.category"`` will become
               ``{"dataset": {"category": ...}}``.

    Returns:
        dict: A nested dictionary where dot-separated keys in the input are converted
              to nested dictionary structures. Keys without dots remain at the top
              level.

    Examples:
        >>> config = {
        ...     "dataset.category": "bottle",
        ...     "dataset.image_size": 224,
        ...     "model_name": "padim"
        ... }
        >>> result = to_nested_dict(config)
        >>> print(result["dataset"]["category"])
        bottle
        >>> print(result["dataset"]["image_size"])
        224
        >>> print(result["model_name"])
        padim

    Note:
        - The function preserves the original values while only restructuring the keys
        - Non-dot keys are kept as-is at the root level
        - Empty key segments (e.g. ``"dataset..name"``) are handled as literal keys
    """
    out: dict[str, Any] = {}
    for key, value in config.items():
        keys = key.split(".")
        _dict = out
        for k in keys[:-1]:
            _dict = _dict.setdefault(k, {})
        _dict[keys[-1]] = value
    return out
Convert a flattened dictionary to a nested dictionary.

    This function takes a dictionary with dot-separated keys and converts it into a nested
    dictionary structure. Keys containing dots (`.`) are split and used to create nested
    dictionaries.

    Args:
        config: Flattened dictionary where keys can contain dots to indicate nesting
               levels. For example, ``"dataset.category"`` will become
               ``{"dataset": {"category": ...}}``.

    Returns:
        dict: A nested dictionary where dot-separated keys in the input are converted
              to nested dictionary structures. Keys without dots remain at the top
              level.

    Examples:
        >>> config = {
        ...     "dataset.category": "bottle",
        ...     "dataset.image_size": 224,
        ...     "model_name": "padim"
        ... }
        >>> result = to_nested_dict(config)
        >>> print(result["dataset"]["category"])
        bottle
        >>> print(result["dataset"]["image_size"])
        224
        >>> print(result["model_name"])
        padim

    Note:
        - The function preserves the original values while only restructuring the keys
        - Non-dot keys are kept as-is at the root level
        - Empty key segments (e.g. ``"dataset..name"``) are handled as literal keys
    
src/anomalib/utils/config.py