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 resize functionality for SIIM ACR #308

Merged
merged 1 commit into from
Jun 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from torch_em.data.datasets.medical import get_siim_acr_loader


ROOT = "/media/anwai/ANWAI/data/siim_acr"
ROOT = "/scratch/share/cidas/cca/data/siim_acr"


def check_siim_acr():
Expand All @@ -13,10 +13,10 @@ def check_siim_acr():
patch_shape=(512, 512),
batch_size=2,
download=True,
resize_inputs=False,
resize_inputs=True,
sampler=MinInstanceSampler()
)
check_loader(loader, 8)
check_loader(loader, 8, plt=True, save_path="./siim_acr.png")


if __name__ == "__main__":
Expand Down
31 changes: 14 additions & 17 deletions torch_em/data/datasets/medical/siim_acr.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import os
from glob import glob
from typing import Union, Tuple
from typing import Union, Tuple, Literal

import torch_em
from torch_em.transform.generic import ResizeInputs

from .. import util
from ... import ImageCollectionDataset


KAGGLE_DATASET_NAME = "vbookshelf/pneumothorax-chest-xray-images-and-masks"
Expand Down Expand Up @@ -42,7 +40,7 @@ def _get_siim_acr_paths(path, split, download):

def get_siim_acr_dataset(
path: Union[os.PathLike, str],
split: str,
split: Literal["train", "test"],
patch_shape: Tuple[int, int],
download: bool = False,
resize_inputs: bool = False,
Expand All @@ -60,19 +58,18 @@ def get_siim_acr_dataset(
image_paths, gt_paths = _get_siim_acr_paths(path=path, split=split, download=download)

if resize_inputs:
raw_trafo = ResizeInputs(target_shape=patch_shape, is_label=False)
label_trafo = ResizeInputs(target_shape=patch_shape, is_label=True)
patch_shape = None
else:
patch_shape = patch_shape
raw_trafo, label_trafo = None, None

dataset = ImageCollectionDataset(
raw_image_paths=image_paths,
label_image_paths=gt_paths,
resize_kwargs = {"patch_shape": patch_shape, "is_rgb": False}
kwargs, patch_shape = util.update_kwargs_for_resize_trafo(
kwargs=kwargs, patch_shape=patch_shape, resize_inputs=resize_inputs, resize_kwargs=resize_kwargs
)

dataset = torch_em.default_segmentation_dataset(
raw_paths=image_paths,
raw_key=None,
label_paths=gt_paths,
label_key=None,
patch_shape=patch_shape,
raw_transform=raw_trafo,
label_transform=label_trafo,
is_seg_dataset=False,
**kwargs
)
dataset.max_sampling_attempts = 5000
Expand All @@ -82,7 +79,7 @@ def get_siim_acr_dataset(

def get_siim_acr_loader(
path: Union[os.PathLike, str],
split: str,
split: Literal["train", "test"],
patch_shape: Tuple[int, int],
batch_size: int,
download: bool = False,
Expand Down