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

Minor updates to CAMUS dataset #292

Merged
merged 2 commits into from
Jun 5, 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
50 changes: 0 additions & 50 deletions scripts/datasets/check_camus.py

This file was deleted.

21 changes: 21 additions & 0 deletions scripts/datasets/medical/check_camus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from torch_em.util.debug import check_loader
from torch_em.data.datasets.medical import get_camus_loader


ROOT = "/media/anwai/ANWAI/data/camus"


def check_camus():
loader = get_camus_loader(
path=ROOT,
patch_shape=(1, 512, 512),
batch_size=2,
chamber=2,
resize_inputs=True,
download=True,
)
check_loader(loader, 8)


if __name__ == "__main__":
check_camus()
19 changes: 8 additions & 11 deletions torch_em/data/datasets/medical/camus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from typing import Union, Tuple, Optional

import torch_em
from torch_em.transform.generic import ResizeInputs

from .. import util


URL = "https://humanheart-project.creatis.insa-lyon.fr/database/api/v1/folder/63fde55f73e9f004868fb7ac/download"
CHECKSUM = "43745d640db5d979332bda7f00f4746747a2591b46efc8f1966b573ce8d65655"

# TODO: the checksums are different with each download, not sure why
# CHECKSUM = "43745d640db5d979332bda7f00f4746747a2591b46efc8f1966b573ce8d65655"


def get_camus_data(path, download):
Expand All @@ -20,7 +21,7 @@ def get_camus_data(path, download):
return data_dir

zip_path = os.path.join(path, "CAMUS.zip")
util.download_source(path=zip_path, url=URL, download=download, checksum=CHECKSUM)
util.download_source(path=zip_path, url=URL, download=download, checksum=None)
util.unzip(zip_path=zip_path, dst=path)

return data_dir
Expand Down Expand Up @@ -60,21 +61,17 @@ def get_camus_dataset(
image_paths, gt_paths = _get_camus_paths(path=path, chamber=chamber, 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
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="data",
label_paths=gt_paths,
label_key="data",
patch_shape=patch_shape,
raw_transform=raw_trafo,
label_transform=label_trafo,
**kwargs
)

Expand Down