cellmil.datamodels.transforms.base_label_transform

Base classes for label transforms.

Classes

FittableLabelTransform(name)

Base class for label transforms that need to be fitted on training data.

LabelTransform(name)

Base class for all label transforms.

class cellmil.datamodels.transforms.base_label_transform.LabelTransform(name: str)[source]

Bases: ABC

Base class for all label transforms.

__init__(name: str)[source]

Initialize the transform.

Parameters:

name – Name of the transform for identification

abstract transform_labels(labels: Dict[str, Union[int, Tuple[float, int]]]) Dict[str, Union[int, Tuple[float, int]]][source]

Apply the transform to labels.

Parameters:

labels – Dictionary mapping slide IDs to labels For classification: int labels For survival: (duration, event) tuples

Returns:

Transformed labels dictionary

abstract get_config() Dict[str, Any][source]

Get the configuration dictionary for this transform.

Returns:

Dictionary containing transform configuration

abstract classmethod from_config(config: Dict[str, Any]) LabelTransform[source]

Create transform instance from configuration dictionary.

Parameters:

config – Configuration dictionary

Returns:

LabelTransform instance

save(path: Path) None[source]

Save the transform to disk.

Parameters:

path – Path to save the transform

classmethod load(path: Path) LabelTransform[source]

Load transform from disk.

Parameters:

path – Path to load the transform from

Returns:

LabelTransform instance

class cellmil.datamodels.transforms.base_label_transform.FittableLabelTransform(name: str)[source]

Bases: LabelTransform

Base class for label transforms that need to be fitted on training data.

__init__(name: str)[source]

Initialize the fittable label transform.

Parameters:

name – Name of the transform for identification

abstract fit(labels: Dict[str, Union[int, Tuple[float, int]]], **kwargs: Any) FittableLabelTransform[source]

Fit the transform on training labels.

Parameters:
  • labels – Training labels dictionary mapping slide IDs to labels

  • **kwargs – Additional keyword arguments for fitting

Returns:

Self for method chaining

fit_transform(labels: Dict[str, Union[int, Tuple[float, int]]], **kwargs: Any) Dict[str, Union[int, Tuple[float, int]]][source]

Fit the transform and apply it to the labels.

Parameters:
  • labels – Labels to fit and transform

  • **kwargs – Additional keyword arguments for fitting

Returns:

Transformed labels

transform_labels(labels: Dict[str, Union[int, Tuple[float, int]]]) Dict[str, Union[int, Tuple[float, int]]][source]

Apply the transform to labels.

Parameters:

labels – Labels dictionary to transform

Returns:

Transformed labels dictionary

Raises:

RuntimeError – If transform hasn’t been fitted yet

abstract _transform_labels_impl(labels: Dict[str, Union[int, Tuple[float, int]]]) Dict[str, Union[int, Tuple[float, int]]][source]

Implementation of the label transform operation.

Parameters:

labels – Input labels dictionary

Returns:

Transformed labels dictionary