read_image_batch
- lib.image.read_image_batch(filenames: list[str], with_metadata: Literal[False] = False) ndarray
- lib.image.read_image_batch(filenames: list[str], with_metadata: Literal[True]) tuple[ndarray, list[PNGHeader]]
Load a batch of images from the given file locations.
Leverages multi-threading to load multiple images from disk at the same time leading to vastly reduced image read times.
- Parameters:
filenames (list[str]) – A of full paths to the images to be loaded.
with_metadata (bool) – Only returns a value if the images loaded are extracted Faceswap faces. If
Truethen returns the Faceswap metadata stored within each Face’s .png exif header. Default:False
- Returns:
batch – The batch of images in BGR channel order returned in the order of
filenamesmetadata – The faceswap metadata corresponding to each image in the batch. Only returned if with_metadata is
True
- Return type:
ndarray | tuple[ndarray, list[PNGHeader]]
Notes
As the images are compiled into a batch, they should be all of the same dimensions, otherwise a homogenous array will be returned
Example
>>> image_filenames = ["/path/to/image_1.png", "/path/to/image_2.png", "/path/to/image_3.png"] >>> images = read_image_batch(image_filenames) >>> print(images.shape) ... (3, 64, 64, 3) >>> images, metadata = read_image_batch(image_filenames, with_metadata=True) >>> print(images.shape) ... (3, 64, 64, 3) >>> print(len(metadata)) ... 3