Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasteuwen committed Oct 10, 2023
2 parents 0ffe6d3 + 33fd2b9 commit 8c5c534
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions ahcore/transforms/pre_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
dataset."""
from __future__ import annotations

from typing import Callable, Any
from typing import Any, Callable

import numpy as np
import numpy.typing as npt
import torch
from dlup.data.dataset import TileSample, TileSampleWithAnnotationData
from dlup.data.transforms import ContainsPolygonToLabel, ConvertAnnotationsToMask, RenameLabels
from torchvision.transforms import functional as F

from ahcore.exceptions import ConfigurationError
from ahcore.utils.data import DataDescription
from ahcore.utils.io import get_logger
from ahcore.utils.types import DlupDatasetSample
from dlup.data.dataset import TileSample, TileSampleWithAnnotationData

PreTransformCallable = Callable[[TileSample], TileSampleWithAnnotationData]

Expand Down Expand Up @@ -194,10 +194,15 @@ def __call__(self, sample: TileSample) -> dict[str, Any]:
# Path objects cannot be collated
sample["path"] = str(sample["path"])

# This would prevent collate
if sample["annotations"] is None:
# Not required anymore
if "annotation_data" in sample:
del sample["annotation_data"]

# Not required anymore
if "annotations" in sample:
del sample["annotations"]
if sample["labels"] is None:

if sample.get("labels") is None:
del sample["labels"]

return sample
Expand Down Expand Up @@ -229,11 +234,6 @@ def __call__(self, sample: DlupDatasetSample) -> dict[str, DlupDatasetSample]:
roi = sample["annotation_data"]["roi"]
sample["roi"] = torch.from_numpy(roi[np.newaxis, ...]).float()

# Not required anymore
del sample["annotation_data"]
# This might be empty.
del sample["annotations"]

return sample

def __repr__(self) -> str:
Expand Down

0 comments on commit 8c5c534

Please sign in to comment.