Skip to content

Convert Prediction

Source

Module containing functions to convert prediction outputs to desired form.

combine_samples(predictions, restore_shape=False)

Combine predictions by data_idx.

Images are first grouped by their data_idx found in their region_spec, then sorted by ascending sample_idx before being stacked along the S dimension.

Parameters:

  • predictions (list of ImageRegionData) –

    List of ImageRegionData.

  • restore_shape (bool, default: False ) –

    If True, restore predictions to their original shape and dimension order.

Returns:

  • list of numpy.ndarray

    List of combined predictions, one per unique data_idx.

  • list of str

    List of sources, one per unique data_idx.

convert_prediction(predictions, tiled, restore_shape=False)

Convert the Lightning trainer outputs to the desired form.

This method allows decollating batches and stitching back together tiled predictions.

If the source of all predictions is "array" (see InMemoryImageStack), then the returned sources list will be empty.

Parameters:

  • predictions (list[ImageRegionData]) –

    Output from Trainer.predict, list of batches.

  • tiled (bool) –

    Whether the predictions are tiled.

  • restore_shape (bool, default: False ) –

    If True, restore predictions to their original shape and dimension order.

Returns:

  • list of numpy.ndarray

    List of arrays with the axes SC(Z)YX, or original axes if restore_shape=True.

  • list of str

    List of sources, one per output or empty if all equal to array.

decollate_image_region_data(batch)

Decollate a batch of ImageRegionData into a list of ImageRegionData.

Input batch has the following structure: - data: (B, C, (Z), Y, X) numpy.ndarray - source: sequence of str, length B - data_shape: sequence of tuple of int, each tuple being of length B - dtype: list of numpy.dtype, length B - axes: list of str, length B - region_spec: dict of {str: sequence}, each sequence being of length B - additional_metadata: dict of {str: Any}, each sequence being of length B

Parameters:

Returns:

  • list of ImageRegionData

    List of ImageRegionData.