Skip to content
SR-Forge

IO Utilities

load_image(filepath: Union[str, Path]) -> torch.Tensor

Load image from the given path to format [C, H, W].

:param filepath: Path to the image :return: Loaded image

load_file(filepath: Union[str, Path]) -> Union[Any, List[Any]]

Load file from the given path.

:param filepath: Path of the file or directory to load :return: Loaded file

list_subdirs(directory: Union[str, Path], allowed_dirs: Union[str, List[str], None] = None) -> List[Path]

Returns a list of subdirectories (as pathlib.Path objects) in a folder directory. allowed_dirs specifies which folders should be included. If allowed_dirs is empty or None, all subdirectories will be included.

:param directory: A Path object pointing to the directory to scan. :param allowed_dirs: A string or list of strings specifying folder names to include. :return: A list of Path objects corresponding to subdirectories.

deep_list_subdirs(directory: Path, depth: int = 0, allowed_dirs: Union[str, List[str], None] = None) -> List[Path]

Returns a list of subdirectories (as Path objects) for all folders located depth levels deeper. If depth is 0, it behaves just like list_subdirs.

:param directory: Path to the root directory. :param depth: How many levels deeper to recurse. :param allowed_dirs: If provided, only these subdirectory names are returned or scanned further. :return: A list of Path objects corresponding to discovered subdirectories.