load_image¶
- torchtune.data.load_image(image_loc: Union[Path, str]) PIL.Image.Image [source]¶
Convenience method to load an image in PIL format from a local file path or remote source.
- Parameters:
image_loc (Union[Path, str]) – Local file path or remote source pointing to the image which will be loaded in PIL format.
Note
If loading an image from a remote source, the function expects the URL provided in
image_loc
to start with “http” or “https” e.g. “https://www.wikipedia.org/en/bird.jpg”.- Raises:
ValueError – If the image cannot be loaded from remote source.
ValueError – If the image cannot be opened as a
Image
.
Examples
>>> # Load from remote source >>> image = load_image("https://www.wikipedia.org/en/bird.jpg")
>>> # Load from local file path >>> image = load_image(Path("/home/user/bird.jpg"))
- Returns:
The loaded image.
- Return type: