Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update class indices in MoNuSAC to make compatible with generalized dice metric #678

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions configs/vision/pathology/offline/segmentation/monusac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions configs/vision/pathology/online/segmentation/monusac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/eva/vision/data/datasets/segmentation/monusac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down