Skip to content

Commit

Permalink
Merge pull request #161 from anwai98/rf-neurips
Browse files Browse the repository at this point in the history
Raise download prompt - NeurIPS CellSeg
  • Loading branch information
constantinpape committed Oct 24, 2023
2 parents e31fe76 + 51f5489 commit 6b614c1
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions torch_em/data/datasets/neurips_cell_seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@
import torch
import torch_em

"""TODO: refactor the loader based on the updated data structure
- Training
- images (multi-modal training inputs)
- labels
- unlabeled (WSI)
- Tuning
- images (multi-modal tuning inputs)
- labels
- Testing
- Public
- images (multi-modal testing inputs)
- labels
- WSI (whole-slide testing inputs)
- WSI-labels
- * (results from `osilab` - ranked 1st in the challenge)
- Hidden
- images (multi-modal hidden testing inputs - unlabeled)
- * (results from `osilab` - ranked 1st in the challenge)
"""
URL = "https://drive.google.com/drive/folders/1NFplvkQzc_nHFwpnB55lw2nD6coc91VV"


def to_rgb(image):
if image.ndim == 2:
Expand All @@ -19,7 +40,8 @@ def to_rgb(image):
# (but we would need to know mapping of images to modality)
def _get_image_and_label_paths(root, split, val_fraction):
path = os.path.join(root, "TrainLabeled")
assert os.path.exists(root), root
assert os.path.exists(root), "Please download the dataset and assort the data as expected here.\
See `get_neurips_cellseg_supervised_dataset`"

image_folder = os.path.join(path, "images")
assert os.path.exists(image_folder)
Expand Down Expand Up @@ -70,14 +92,19 @@ def get_neurips_cellseg_supervised_dataset(
raw_transform=None,
transform=None,
label_dtype=torch.float32,
dtype=torch.float32,
n_samples=None,
sampler=None,
val_fraction=0.1,
):
"""Dataset for the segmentation of cells in light microscopy.
This dataset is part of the NeuRIPS Cell Segmentation challenge: https://neurips22-cellseg.grand-challenge.org/.
NOTE:
- The dataset isn't available to download using an in-built functionality
- Please download the dataset from here:\
https://drive.google.com/drive/folders/1NFplvkQzc_nHFwpnB55lw2nD6coc91VV
- REMEMBER: to convert the available data in the expected directory format
"""
assert split in ("train", "val", None), split
image_paths, label_paths = _get_image_and_label_paths(root, split, val_fraction)
Expand Down Expand Up @@ -109,32 +136,33 @@ def get_neurips_cellseg_supervised_loader(
raw_transform=None,
transform=None,
label_dtype=torch.float32,
dtype=torch.float32,
n_samples=None,
sampler=None,
val_fraction=0.1,
**loader_kwargs
):
"""Dataloader for the segmentation of cells in light microscopy. See 'get_neurips_cellseg_supervised_dataset'."""
"""Dataloader for the segmentation of cells in light microscopy. See `get_neurips_cellseg_supervised_dataset`."""
ds = get_neurips_cellseg_supervised_dataset(
root, split, patch_shape, make_rgb=make_rgb, label_transform=label_transform,
label_transform2=label_transform2, raw_transform=raw_transform, transform=transform,
label_dtype=label_dtype, dtype=dtype, n_samples=n_samples, sampler=sampler, val_fraction=val_fraction,
label_dtype=label_dtype, n_samples=n_samples, sampler=sampler, val_fraction=val_fraction,
)
return torch_em.segmentation.get_data_loader(ds, batch_size, **loader_kwargs)


def _get_image_paths(root):
path = os.path.join(root, "TrainUnlabeled")
assert os.path.exists(path), path
assert os.path.exists(path), "Please download the dataset and assort the data as expected here.\
See `get_neurips_cellseg_unsupervised_dataset`"
image_paths = glob(os.path.join(path, "*"))
image_paths.sort()
return image_paths


def _get_wholeslide_paths(root, patch_shape):
path = os.path.join(root, "TrainUnlabeled_WholeSlide")
assert os.path.exists(path), path
assert os.path.exists(path), "Please download the dataset and assort the data as expected here.\
See `get_neurips_cellseg_unsupervised_dataset`"
image_paths = glob(os.path.join(path, "*"))
image_paths.sort()

Expand Down Expand Up @@ -165,6 +193,12 @@ def get_neurips_cellseg_unsupervised_dataset(
"""Dataset for the segmentation of cells in light microscopy.
This dataset is part of the NeuRIPS Cell Segmentation challenge: https://neurips22-cellseg.grand-challenge.org/.
NOTE:
- The dataset isn't available to download using an in-built functionality
- Please download the dataset from here:\
https://drive.google.com/drive/folders/1NFplvkQzc_nHFwpnB55lw2nD6coc91VV
- REMEMBER: to convert the available data in the expected directory format
"""
if raw_transform is None:
trafo = to_rgb if make_rgb else None
Expand Down Expand Up @@ -205,7 +239,7 @@ def get_neurips_cellseg_unsupervised_loader(
use_wholeslide=True,
**loader_kwargs,
):
"""Dataloader for the segmentation of cells in light microscopy. See 'get_neurips_cellseg_unsupervised_dataset'."""
"""Dataloader for the segmentation of cells in light microscopy. See `get_neurips_cellseg_unsupervised_dataset`."""
ds = get_neurips_cellseg_unsupervised_dataset(
root, patch_shape, make_rgb=make_rgb, raw_transform=raw_transform, transform=transform,
dtype=dtype, sampler=sampler, use_images=use_images, use_wholeslide=use_wholeslide
Expand Down

0 comments on commit 6b614c1

Please sign in to comment.