lazyslide.tl.image_generation

lazyslide.tl.image_generation#

image_generation(wsi=None, model='cytosyn', prompt_tiles=None, tile_key='tiles', device=None, amp=None, autocast_dtype=None, num_images_per_tiles=2, seed=0, **kwargs)#

Generation of tile images unconditionally or conditionally.

Currently only supports cytosyn model, conditionally generation relied on H0-mini features.

Parameters:
wsiWSIData

The WSIData object to work on.

modelstr, default: “cytosyn”

The image generation model.

prompt_tilesslice, default: None

The tiles to generate images for, please use index to select tiles. If None, unconditional generation is performed.

tile_keystr, default: “tiles”

Which tile table to use.

devicestr, optional

The device to use for inference. If not provided, the device will be automatically selected.

ampbool, default: False

Whether to use automatic mixed precision.

autocast_dtypetorch.dtype, default: torch.float16

The dtype for automatic mixed precision.

num_images_per_tilesint, default: 2

The number of images to generate for each tile if conditional generation is used. Otherwise, it’s the total number of images to generate if unconditional generation is used.

seedint, default: 0

The random seed to ensure reproducible image generation (May not work for all models).

kwargsdict, optional

Please refer to the documentation of the specific model for additional parameters.

Returns:
PIL.Image.Image

The function returns a list of generated images in PIL format.

Examples

>>> import lazyslide as zs
>>> # Unconditional generation
>>> imgs = zs.tl.image_generation()
>>> # Conditional generation
>>> wsi = zs.datasets.sample()
>>> zs.tl.feature_extraction(wsi, "h0-mini")
>>> imgs = zs.tl.image_generation(wsi, prompt_tiles=slice(0, 2)) # Generate images for the first two tiles