Skip to content

Commit

Permalink
replace 255 ambigous class with class index 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaenzig committed Oct 10, 2024
1 parent fbd46aa commit 2f0c375
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
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

0 comments on commit 2f0c375

Please sign in to comment.