from pathlib import Path


def get_unique_stem_from_last_k_strs(fpath: str, k: int = 4) -> str:
    """
    For datasets like ScanNet where image filename stem is not unique.
        Args:
        -   fpath
        -   k

        Returns:
        -   unique_stem: string
    """
    parts = Path(fpath).parts
    concat_kparent_dirs = '_'.join(parts[-k:-1])
    unique_stem = concat_kparent_dirs + '_' + Path(fpath).stem
    return unique_stem