ahcore.metrics package#

Submodules#

ahcore.metrics.metrics module#

Metrics module, including factory.

class ahcore.metrics.metrics.DiceMetric(data_description: DataDescription)[source]#

Bases: TileMetric

Metric computing dice over classes. The classes are derived from the index_map that’s defined in the data_description.

First, a softmax is taken over the predictions, followed by a softmax. Then, if there is a ROI available, the input and target are masked with this ROI. This is followed by an argmax over the predictions and target, resulting in a tensor of shape (batch_size, height, width) with values in [0, num_classes - 1]. The dice is then computed over each class.

We use as definition for the dice score: \(\text{dice} = 2 * \frac{|X| \intersection |Y|}{|X| + |Y|}\) where \(|X|\) is the number of voxels in the prediction, \(|Y|\) is the number of voxels in the target, and \(\intersection\) is the intersection of \(X\) and \(Y\).

The __call__ returns the dice score for each class, with the class name (prefixed with dice/) as key in a dictionary.

Parameters:
data_descriptionDataDescription
class ahcore.metrics.metrics.MetricFactory(metrics: list[ahcore.metrics.metrics.TileMetric])[source]#

Bases: object

Factory to create the metrics. These are fixed for the different tasks (e.g., segmentation, detection, whole-slide-level classification.

Parameters:
metricslist

List of metrics of type AhCoreMetric.

classmethod for_segmentation(*args: Any, **kwargs: Any) MetricFactory[source]#
classmethod for_tile_classification(*args: Any, **kwargs: Any) MetricFactory[source]#
classmethod for_wsi_classification(*args: Any, **kwargs: Any) MetricFactory[source]#
class ahcore.metrics.metrics.TileMetric(data_description: DataDescription)[source]#

Bases: object

Initialize the metric class

class ahcore.metrics.metrics.WSIDiceMetric(data_description: DataDescription, compute_overall_dice: bool = False)[source]#

Bases: WSIMetric

WSI Dice metric class, computes the dice score over the whole WSI

Initialize the WSI metric class

get_average_score(precomputed_output: list[list[dict[str, dict[str, float]]]] | None = None) dict[Any, Any][source]#
get_wsi_score(wsi_name: str) None[source]#
property name: str#
process_batch(predictions: Tensor, target: Tensor, roi: Tensor | None, wsi_name: str) None[source]#
reset() None[source]#
static static_average_wsi_dice(precomputed_output: list[list[dict[str, dict[str, float]]]]) dict[str, float][source]#

Static method to compute the average WSI dice score over a list of WSI dice scores, useful for multiprocessing.

class ahcore.metrics.metrics.WSIMetric(data_description: DataDescription)[source]#

Bases: ABC

Initialize the WSI metric class

abstract get_average_score(*args: Any, **kwargs: Any) dict[str, float][source]#
abstract get_wsi_score(*args: Any, **kwargs: Any) None[source]#
abstract property name: str#
abstract process_batch(*args: Any, **kwargs: Any) None[source]#
abstract reset() None[source]#
class ahcore.metrics.metrics.WSIMetricFactory(metrics: list[ahcore.metrics.metrics.WSIMetric])[source]#

Bases: object

classmethod for_segmentation(*args: Any, **kwargs: Any) WSIMetricFactory[source]#
classmethod for_tile_classification(roi_name: str, label: str, threshold: float) WSIMetricFactory[source]#
classmethod for_wsi_classification(*args: Any, **kwargs: Any) WSIMetricFactory[source]#
get_average_score(precomputed_output: list[list[dict[str, dict[str, float]]]] | None = None) dict[str, float][source]#
process_batch(predictions: Tensor, target: Tensor, wsi_name: str, roi: Tensor | None) None[source]#
reset() None[source]#

Module contents#

Ahcore’s metrics

class ahcore.metrics.DiceMetric(data_description: DataDescription)[source]#

Bases: TileMetric

Metric computing dice over classes. The classes are derived from the index_map that’s defined in the data_description.

First, a softmax is taken over the predictions, followed by a softmax. Then, if there is a ROI available, the input and target are masked with this ROI. This is followed by an argmax over the predictions and target, resulting in a tensor of shape (batch_size, height, width) with values in [0, num_classes - 1]. The dice is then computed over each class.

We use as definition for the dice score: \(\text{dice} = 2 * \frac{|X| \intersection |Y|}{|X| + |Y|}\) where \(|X|\) is the number of voxels in the prediction, \(|Y|\) is the number of voxels in the target, and \(\intersection\) is the intersection of \(X\) and \(Y\).

The __call__ returns the dice score for each class, with the class name (prefixed with dice/) as key in a dictionary.

Parameters:
data_descriptionDataDescription
class ahcore.metrics.MetricFactory(metrics: list[ahcore.metrics.metrics.TileMetric])[source]#

Bases: object

Factory to create the metrics. These are fixed for the different tasks (e.g., segmentation, detection, whole-slide-level classification.

Parameters:
metricslist

List of metrics of type AhCoreMetric.

classmethod for_segmentation(*args: Any, **kwargs: Any) MetricFactory[source]#
classmethod for_tile_classification(*args: Any, **kwargs: Any) MetricFactory[source]#
classmethod for_wsi_classification(*args: Any, **kwargs: Any) MetricFactory[source]#
class ahcore.metrics.TileMetric(data_description: DataDescription)[source]#

Bases: object

Initialize the metric class

class ahcore.metrics.WSIMetric(data_description: DataDescription)[source]#

Bases: ABC

Initialize the WSI metric class

abstract get_average_score(*args: Any, **kwargs: Any) dict[str, float][source]#
abstract get_wsi_score(*args: Any, **kwargs: Any) None[source]#
abstract property name: str#
abstract process_batch(*args: Any, **kwargs: Any) None[source]#
abstract reset() None[source]#
class ahcore.metrics.WSIMetricFactory(metrics: list[ahcore.metrics.metrics.WSIMetric])[source]#

Bases: object

classmethod for_segmentation(*args: Any, **kwargs: Any) WSIMetricFactory[source]#
classmethod for_tile_classification(roi_name: str, label: str, threshold: float) WSIMetricFactory[source]#
classmethod for_wsi_classification(*args: Any, **kwargs: Any) WSIMetricFactory[source]#
get_average_score(precomputed_output: list[list[dict[str, dict[str, float]]]] | None = None) dict[str, float][source]#
process_batch(predictions: Tensor, target: Tensor, wsi_name: str, roi: Tensor | None) None[source]#
reset() None[source]#