Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Insert proper ROI into sample when None (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricMarcus-ai authored Dec 8, 2023
1 parent 041c515 commit 21d9f74
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ahcore/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def __getitem__(self, idx: int) -> dict[str, Any]:
target, roi = self._get_annotation_data(coordinates)
if roi is not None:
sample["roi"] = roi.astype(np.uint8)
else:
sample["roi"] = None # type: ignore
sample["target"] = target

return sample
Expand Down Expand Up @@ -199,15 +201,15 @@ def _get_annotation_data(
raise ValueError("Index map is not provided.")

_annotations = self._annotations.read_region(coordinates, self._scaling, self._region_size)

if self._data_description.remap_labels:
_annotations = rename_labels(_annotations, remap_labels=self._data_description.remap_labels)

points, boxes, region, roi = convert_annotations(
_annotations,
self._region_size,
index_map=self._data_description.index_map,
roi_name="roi",
roi_name=self._data_description.roi_name,
)
encoded_region = one_hot_encoding(index_map=self._data_description.index_map, mask=region)
if roi is not None:
Expand Down Expand Up @@ -681,7 +683,7 @@ def compute_metrics_for_case(
for sample in dataset_of_validation_image:
prediction = torch.from_numpy(sample["prediction"]).unsqueeze(0).float()
target = torch.from_numpy(sample["target"]).unsqueeze(0)
roi = torch.from_numpy(sample["roi"]).unsqueeze(0)
roi = torch.from_numpy(sample["roi"]).unsqueeze(0) if sample["roi"] is not None else None

wsi_metrics.process_batch(
predictions=prediction,
Expand Down

0 comments on commit 21d9f74

Please sign in to comment.