def get_relative_path(to_path, from_path, from_file=True):
    """Return string with relative path to given to_path from given from_path.
    :type to_path: Path
    :type from_path: Path
    :type from_file: bool
    :rtype: str

    >>> to_path = Path('/root/dir1/subdir1/file.txt')
    >>> print(get_relative_path(to_path, Path('/root/dir2/subdir2/image.jpg')))
    ../../dir1/subdir1/file.txt

    >>> print(get_relative_path(to_path, Path('/root/dir1/subdir1/image.jpg')))
    file.txt

    >>> print(get_relative_path(to_path, Path('/root/dir1/subdir2'), from_file=False))
    ../subdir1/file.txt

    >>> print(get_relative_path(to_path, to_path))
    file.txt

    >>> print(get_relative_path(to_path, to_path, from_file=False))
    .
    """
    from_path = from_path.absolute()
    to_path = to_path.absolute()
    if from_path == to_path:
        return to_path.name if from_file else '.'

    from_parts = from_path.parts
    to_parts = to_path.parts

    for i, (from_part, to_part) in enumerate(zip(from_parts, to_parts)):
        if from_part != to_part:
            from_parts = from_parts[i:]
            to_parts = to_parts[i:]
            break

    backs_count = len(from_parts)
    if from_file and backs_count > 0:
        backs_count -= 1
    res = ['..'] * backs_count
    res.extend(to_parts)
    return '/'.join(res)