def load_motion_masks(motion_root):
    """Load motion masks from disk.

    Args:
        motion_root (Path): Points to a directory which contains a
            subdirectory for each sequence, which in turn contains a .png for
            each frame in the sequence.

    Returns:
        motion_masks (dict): Map sequence to dict mapping frame name to motion
            mask path.
    """
    motion_mask_paths = {}
    for sequence_path in motion_root.iterdir():
        if not sequence_path.is_dir():
            continue

        sequence = sequence_path.stem
        motion_mask_paths[sequence] = {}
        for motion_path in sequence_path.glob('*.png'.format(sequence)):
            # Pavel's ICCV 2017 method outputs an extra set of soft masks that
            # start with 'raw_' or 'input_'; ignore them by starting the glob
            # with the sequence name.
            if (motion_path.stem.startswith('raw_')
                    or motion_path.stem.startswith('input_')):
                continue
            motion_mask_paths[sequence][motion_path.stem] = motion_path
    return motion_mask_paths