Skip to content

in_memory_pred_dataset

In-memory prediction dataset.

InMemoryPredDataset #

Bases: Dataset

Simple prediction dataset returning images along the sample axis.

Parameters:

Name Type Description Default
prediction_config InferenceConfig

Prediction configuration.

required
inputs NDArray

Input data.

required
Source code in src/careamics/dataset/in_memory_pred_dataset.py
class InMemoryPredDataset(Dataset):
    """Simple prediction dataset returning images along the sample axis.

    Parameters
    ----------
    prediction_config : InferenceConfig
        Prediction configuration.
    inputs : NDArray
        Input data.
    """

    def __init__(
        self,
        prediction_config: InferenceConfig,
        inputs: NDArray,
    ) -> None:
        """Constructor.

        Parameters
        ----------
        prediction_config : InferenceConfig
            Prediction configuration.
        inputs : NDArray
            Input data.

        Raises
        ------
        ValueError
            If data_path is not a directory.
        """
        self.pred_config = prediction_config
        self.input_array = inputs
        self.axes = self.pred_config.axes
        self.image_means = self.pred_config.image_means
        self.image_stds = self.pred_config.image_stds

        # Reshape data
        self.data = reshape_array(self.input_array, self.axes)

        # get transforms
        self.patch_transform = Compose(
            transform_list=[
                NormalizeModel(image_means=self.image_means, image_stds=self.image_stds)
            ],
        )

    def __len__(self) -> int:
        """
        Return the length of the dataset.

        Returns
        -------
        int
            Length of the dataset.
        """
        return len(self.data)

    def __getitem__(self, index: int) -> NDArray:
        """
        Return the patch corresponding to the provided index.

        Parameters
        ----------
        index : int
            Index of the patch to return.

        Returns
        -------
        NDArray
            Transformed patch.
        """
        transformed_patch, _ = self.patch_transform(patch=self.data[index])

        return transformed_patch

__getitem__(index) #

Return the patch corresponding to the provided index.

Parameters:

Name Type Description Default
index int

Index of the patch to return.

required

Returns:

Type Description
NDArray

Transformed patch.

Source code in src/careamics/dataset/in_memory_pred_dataset.py
def __getitem__(self, index: int) -> NDArray:
    """
    Return the patch corresponding to the provided index.

    Parameters
    ----------
    index : int
        Index of the patch to return.

    Returns
    -------
    NDArray
        Transformed patch.
    """
    transformed_patch, _ = self.patch_transform(patch=self.data[index])

    return transformed_patch

__init__(prediction_config, inputs) #

Constructor.

Parameters:

Name Type Description Default
prediction_config InferenceConfig

Prediction configuration.

required
inputs NDArray

Input data.

required

Raises:

Type Description
ValueError

If data_path is not a directory.

Source code in src/careamics/dataset/in_memory_pred_dataset.py
def __init__(
    self,
    prediction_config: InferenceConfig,
    inputs: NDArray,
) -> None:
    """Constructor.

    Parameters
    ----------
    prediction_config : InferenceConfig
        Prediction configuration.
    inputs : NDArray
        Input data.

    Raises
    ------
    ValueError
        If data_path is not a directory.
    """
    self.pred_config = prediction_config
    self.input_array = inputs
    self.axes = self.pred_config.axes
    self.image_means = self.pred_config.image_means
    self.image_stds = self.pred_config.image_stds

    # Reshape data
    self.data = reshape_array(self.input_array, self.axes)

    # get transforms
    self.patch_transform = Compose(
        transform_list=[
            NormalizeModel(image_means=self.image_means, image_stds=self.image_stds)
        ],
    )

__len__() #

Return the length of the dataset.

Returns:

Type Description
int

Length of the dataset.

Source code in src/careamics/dataset/in_memory_pred_dataset.py
def __len__(self) -> int:
    """
    Return the length of the dataset.

    Returns
    -------
    int
        Length of the dataset.
    """
    return len(self.data)