Skip to content

Prediction

Source

Prediction utilities for the NG Dataset.

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.

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.

stitch_single_prediction(tiles, restore_shape=False)

Stitch tiles back together to form a full image.

Tiles are of dimensions C(Z)YX, where C is the number of channels and can be a singleton dimension.

Parameters:

  • tiles (list of ImageRegionData) –

    Cropped tiles and their respective stitching coordinates.

  • restore_shape (bool, default: False ) –

    If True, restore prediction to its original shape and dimension order.

Returns:

  • ndarray

    Full image, with dimensions SC(Z)YX.