diff --git a/configs/vision/pathology/offline/segmentation/monusac.yaml b/configs/vision/pathology/offline/segmentation/monusac.yaml index b44e688c..0a2d41e8 100644 --- a/configs/vision/pathology/offline/segmentation/monusac.yaml +++ b/configs/vision/pathology/offline/segmentation/monusac.yaml @@ -63,7 +63,7 @@ model: init_args: softmax: true batch: true - ignore_index: &IGNORE_INDEX 255 + ignore_index: &IGNORE_INDEX 5 optimizer: class_path: torch.optim.AdamW init_args: @@ -84,17 +84,17 @@ model: evaluation: - class_path: eva.vision.metrics.defaults.MulticlassSegmentationMetrics init_args: - num_classes: *NUM_CLASSES + num_classes: 6 ignore_index: *IGNORE_INDEX - class_path: torchmetrics.ClasswiseWrapper init_args: metric: class_path: eva.vision.metrics.GeneralizedDiceScore init_args: - num_classes: *NUM_CLASSES + num_classes: 6 weight_type: linear - per_class: true ignore_index: *IGNORE_INDEX + per_class: true data: class_path: eva.DataModule init_args: diff --git a/configs/vision/pathology/online/segmentation/monusac.yaml b/configs/vision/pathology/online/segmentation/monusac.yaml index 234b30e4..2cb8310b 100644 --- a/configs/vision/pathology/online/segmentation/monusac.yaml +++ b/configs/vision/pathology/online/segmentation/monusac.yaml @@ -54,7 +54,7 @@ model: init_args: softmax: true batch: true - ignore_index: &IGNORE_INDEX 255 + ignore_index: &IGNORE_INDEX 5 lr_multiplier_encoder: 0.0 optimizer: class_path: torch.optim.AdamW @@ -76,14 +76,14 @@ model: evaluation: - class_path: eva.vision.metrics.defaults.MulticlassSegmentationMetrics init_args: - num_classes: *NUM_CLASSES + num_classes: 6 ignore_index: *IGNORE_INDEX - class_path: torchmetrics.ClasswiseWrapper init_args: metric: class_path: eva.vision.metrics.GeneralizedDiceScore init_args: - num_classes: *NUM_CLASSES + num_classes: 6 weight_type: linear ignore_index: *IGNORE_INDEX per_class: true diff --git a/src/eva/vision/data/datasets/segmentation/monusac.py b/src/eva/vision/data/datasets/segmentation/monusac.py index 35e43bb9..edca6c2f 100644 --- a/src/eva/vision/data/datasets/segmentation/monusac.py +++ b/src/eva/vision/data/datasets/segmentation/monusac.py @@ -84,7 +84,7 @@ def __init__( @property @override def classes(self) -> List[str]: - return ["Epithelial", "Lymphocyte", "Neutrophil", "Macrophage"] + return ["Background", "Epithelial", "Lymphocyte", "Neutrophil", "Macrophage", "Ambiguous"] @functools.cached_property @override @@ -107,8 +107,8 @@ def validate(self) -> None: _validators.check_dataset_integrity( self, length=self._expected_dataset_lengths.get(self._split, 0), - n_classes=4, - first_and_last_labels=("Epithelial", "Macrophage"), + n_classes=6, + first_and_last_labels=("Background", "Ambiguous"), ) @override @@ -199,9 +199,9 @@ def _get_semantic_mask(self, index: int) -> npt.NDArray[Any]: semantic_labels = np.zeros((height, width), "uint8") # type: ignore[reportCallIssue] for level in range(len(root)): label = [item.attrib["Name"] for item in root[level][0]][0] - class_id = self.class_to_idx.get(label, 254) + 1 + class_id = self.class_to_idx.get(label, self.class_to_idx["Ambiguous"]) # for the test dataset an additional class 'Ambiguous' was added for - # difficult regions with fuzzy boundaries - we return it as 255 + # difficult regions with fuzzy boundaries regions = [item for child in root[level] for item in child if item.tag == "Region"] for region in regions: vertices = np.array(