Skip to content

Write Strategy

Source

Module containing different strategies for writing predictions.

CacheTiles

Bases: WriteStrategy

A write strategy that will cache tiles.

Tiles are cached until a whole image is predicted on. Then the stitched prediction is saved.

Parameters:

  • write_func (WriteFunc) –

    Function used to save predictions.

  • write_extension (str) –

    Extension added to prediction file paths.

  • write_func_kwargs (dict of {str: Any}) –

    Extra kwargs to pass to write_func.

Attributes:

  • write_func (WriteFunc) –

    Function used to save predictions.

  • write_extension (str) –

    Extension added to prediction file paths.

  • write_func_kwargs (dict of {str: Any}) –

    Extra kwargs to pass to write_func.

  • tile_cache (list of numpy.ndarray) –

    Tiles cached for stitching prediction.

  • tile_info_cache (list of TileInformation) –

    Cached tile information for stitching prediction.

last_tiles property

List of bool to determine whether each tile in the cache is the last tile.

Returns:

  • list of bool

    Whether each tile in the tile cache is the last tile.

__init__(write_func, write_extension, write_func_kwargs)

A write strategy that will cache tiles.

Tiles are cached until a whole image is predicted on. Then the stitched prediction is saved.

Parameters:

  • write_func (WriteFunc) –

    Function used to save predictions.

  • write_extension (str) –

    Extension added to prediction file paths.

  • write_func_kwargs (dict of {str: Any}) –

    Extra kwargs to pass to write_func.

write_batch(trainer, pl_module, prediction, batch_indices, batch, batch_idx, dataloader_idx, dirpath)

Cache tiles until the last tile is predicted; save the stitched prediction.

Parameters:

  • trainer (Trainer) –

    PyTorch Lightning Trainer.

  • pl_module (LightningModule) –

    PyTorch Lightning LightningModule.

  • prediction (Any) –

    Predictions on batch.

  • batch_indices (sequence of int) –

    Indices identifying the samples in the batch.

  • batch (Any) –

    Input batch.

  • batch_idx (int) –

    Batch index.

  • dataloader_idx (int) –

    Dataloader index.

  • dirpath (Path) –

    Path to directory to save predictions to.

WriteImage

Bases: WriteStrategy

A strategy for writing image predictions (i.e. un-tiled predictions).

Parameters:

  • write_func (WriteFunc) –

    Function used to save predictions.

  • write_extension (str) –

    Extension added to prediction file paths.

  • write_func_kwargs (dict of {str: Any}) –

    Extra kwargs to pass to write_func.

Attributes:

  • write_func (WriteFunc) –

    Function used to save predictions.

  • write_extension (str) –

    Extension added to prediction file paths.

  • write_func_kwargs (dict of {str: Any}) –

    Extra kwargs to pass to write_func.

__init__(write_func, write_extension, write_func_kwargs)

A strategy for writing image predictions (i.e. un-tiled predictions).

Parameters:

  • write_func (WriteFunc) –

    Function used to save predictions.

  • write_extension (str) –

    Extension added to prediction file paths.

  • write_func_kwargs (dict of {str: Any}) –

    Extra kwargs to pass to write_func.

write_batch(trainer, pl_module, prediction, batch_indices, batch, batch_idx, dataloader_idx, dirpath)

Save full images.

Parameters:

  • trainer (Trainer) –

    PyTorch Lightning Trainer.

  • pl_module (LightningModule) –

    PyTorch Lightning LightningModule.

  • prediction (Any) –

    Predictions on batch.

  • batch_indices (sequence of int) –

    Indices identifying the samples in the batch.

  • batch (Any) –

    Input batch.

  • batch_idx (int) –

    Batch index.

  • dataloader_idx (int) –

    Dataloader index.

  • dirpath (Path) –

    Path to directory to save predictions to.

Raises:

  • TypeError

    If trainer prediction dataset is not IterablePredDataset.

WriteStrategy

Bases: Protocol

Protocol for write strategy classes.

write_batch(trainer, pl_module, prediction, batch_indices, batch, batch_idx, dataloader_idx, dirpath)

WriteStrategy subclasses must contain this function to write a batch.

Parameters:

  • trainer (Trainer) –

    PyTorch Lightning Trainer.

  • pl_module (LightningModule) –

    PyTorch Lightning LightningModule.

  • prediction (Any) –

    Predictions on batch.

  • batch_indices (sequence of int) –

    Indices identifying the samples in the batch.

  • batch (Any) –

    Input batch.

  • batch_idx (int) –

    Batch index.

  • dataloader_idx (int) –

    Dataloader index.

  • dirpath (Path) –

    Path to directory to save predictions to.

WriteTilesZarr

Bases: WriteStrategy

Strategy to write tiles to Zarr file.

write_batch(trainer, pl_module, prediction, batch_indices, batch, batch_idx, dataloader_idx, dirpath)

Write tiles to zarr file.

Parameters:

  • trainer (Trainer) –

    PyTorch Lightning Trainer.

  • pl_module (LightningModule) –

    PyTorch Lightning LightningModule.

  • prediction (Any) –

    Predictions on batch.

  • batch_indices (sequence of int) –

    Indices identifying the samples in the batch.

  • batch (Any) –

    Input batch.

  • batch_idx (int) –

    Batch index.

  • dataloader_idx (int) –

    Dataloader index.

  • dirpath (Path) –

    Path to directory to save predictions to.

Raises: