torch_em.data.datasets.light_microscopy.phmamm
The PhMamm dataset contains 3D light-sheet microscopy volumes of Phallusia mammillata embryos with cell membrane segmentations.
The dataset is located at https://figshare.com/articles/dataset/3D_Mask_R-CNN_data/26973085. The original data is from the publication https://doi.org/10.1126/science.aar5663. Please cite it if you use this dataset in your research.
1"""The PhMamm dataset contains 3D light-sheet microscopy volumes of Phallusia mammillata 2embryos with cell membrane segmentations. 3 4The dataset is located at https://figshare.com/articles/dataset/3D_Mask_R-CNN_data/26973085. 5The original data is from the publication https://doi.org/10.1126/science.aar5663. 6Please cite it if you use this dataset in your research. 7""" 8 9import os 10from glob import glob 11from natsort import natsorted 12from typing import Union, Tuple, Optional, List, Sequence 13 14from torch.utils.data import Dataset, DataLoader 15 16import torch_em 17 18from .. import util 19 20 21URLS = { 22 "inputs": "https://ndownloader.figshare.com/files/51130115", 23 "ground_truth": "https://ndownloader.figshare.com/files/51130100", 24} 25CHECKSUMS = { 26 "inputs": None, 27 "ground_truth": None, 28} 29 30 31def get_phmamm_data(path: Union[os.PathLike, str], download: bool = False) -> str: 32 """Download the PhMamm dataset. 33 34 Args: 35 path: Filepath to a folder where the downloaded data will be saved. 36 download: Whether to download the data if it is not present. 37 38 Returns: 39 Filepath where the dataset is stored. 40 """ 41 data_dir = os.path.join(path, "data") 42 if os.path.exists(data_dir): 43 return data_dir 44 45 os.makedirs(path, exist_ok=True) 46 47 inputs_zip = os.path.join(path, "Inputs.zip") 48 util.download_source(inputs_zip, URLS["inputs"], download, checksum=CHECKSUMS["inputs"]) 49 util.unzip(inputs_zip, data_dir, remove=True) 50 51 gt_zip = os.path.join(path, "ASTEC_Ground_truth.zip") 52 util.download_source(gt_zip, URLS["ground_truth"], download, checksum=CHECKSUMS["ground_truth"]) 53 util.unzip(gt_zip, data_dir, remove=True) 54 55 return data_dir 56 57 58def get_phmamm_paths( 59 path: Union[os.PathLike, str], timepoints: Optional[Sequence[int]] = None, download: bool = False, 60) -> Tuple[List[str], List[str]]: 61 """Get paths to the PhMamm data. 62 63 Args: 64 path: Filepath to a folder where the downloaded data will be saved. 65 timepoints: The timepoints of the time-lapse to restrict to, e.g. range(1, 81). By default all 100 are used. 66 download: Whether to download the data if it is not present. 67 68 Returns: 69 List of filepaths for the image data. 70 List of filepaths for the label data. 71 """ 72 data_dir = get_phmamm_data(path, download) 73 74 raw_paths = natsorted(glob(os.path.join(data_dir, "Inputs", "*.tiff"))) 75 label_paths = natsorted(glob(os.path.join(data_dir, "ASTEC_Ground_truth", "*.tiff"))) 76 assert len(raw_paths) == len(label_paths) and len(raw_paths) > 0 77 78 if timepoints is not None: 79 timepoints = set(timepoints) 80 keep = [int(os.path.basename(p).split("_t")[1][:3]) in timepoints for p in raw_paths] 81 raw_paths = [p for p, k in zip(raw_paths, keep) if k] 82 label_paths = [p for p, k in zip(label_paths, keep) if k] 83 84 return raw_paths, label_paths 85 86 87def get_phmamm_dataset( 88 path: Union[os.PathLike, str], 89 patch_shape: Tuple[int, int, int], 90 offsets: Optional[List[List[int]]] = None, 91 boundaries: bool = False, 92 binary: bool = False, 93 timepoints: Optional[Sequence[int]] = None, 94 download: bool = False, 95 **kwargs 96) -> Dataset: 97 """Get the PhMamm dataset for cell segmentation in light-sheet microscopy. 98 99 Args: 100 path: Filepath to a folder where the downloaded data will be saved. 101 patch_shape: The patch shape to use for training. 102 offsets: Offset values for affinity computation used as target. 103 boundaries: Whether to compute boundaries as the target. 104 binary: Whether to use a binary segmentation target. 105 timepoints: The timepoints of the time-lapse to restrict to, e.g. range(1, 81). By default all 100 are used. 106 download: Whether to download the data if it is not present. 107 kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset`. 108 109 Returns: 110 The segmentation dataset. 111 """ 112 raw_paths, label_paths = get_phmamm_paths(path, timepoints, download) 113 114 kwargs, _ = util.add_instance_label_transform( 115 kwargs, add_binary_target=True, offsets=offsets, boundaries=boundaries, binary=binary 116 ) 117 118 return torch_em.default_segmentation_dataset( 119 raw_paths=raw_paths, 120 raw_key=None, 121 label_paths=label_paths, 122 label_key=None, 123 patch_shape=patch_shape, 124 **kwargs 125 ) 126 127 128def get_phmamm_loader( 129 path: Union[os.PathLike, str], 130 batch_size: int, 131 patch_shape: Tuple[int, int, int], 132 offsets: Optional[List[List[int]]] = None, 133 boundaries: bool = False, 134 binary: bool = False, 135 timepoints: Optional[Sequence[int]] = None, 136 download: bool = False, 137 **kwargs 138) -> DataLoader: 139 """Get the PhMamm dataloader for cell segmentation in light-sheet microscopy. 140 141 Args: 142 path: Filepath to a folder where the downloaded data will be saved. 143 batch_size: The batch size for training. 144 patch_shape: The patch shape to use for training. 145 offsets: Offset values for affinity computation used as target. 146 boundaries: Whether to compute boundaries as the target. 147 binary: Whether to use a binary segmentation target. 148 timepoints: The timepoints of the time-lapse to restrict to, e.g. range(1, 81). By default all 100 are used. 149 download: Whether to download the data if it is not present. 150 kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset` or for the PyTorch DataLoader. 151 152 Returns: 153 The DataLoader. 154 """ 155 ds_kwargs, loader_kwargs = util.split_kwargs(torch_em.default_segmentation_dataset, **kwargs) 156 dataset = get_phmamm_dataset( 157 path=path, 158 patch_shape=patch_shape, 159 offsets=offsets, 160 boundaries=boundaries, 161 binary=binary, 162 timepoints=timepoints, 163 download=download, 164 **ds_kwargs, 165 ) 166 return torch_em.get_data_loader(dataset=dataset, batch_size=batch_size, **loader_kwargs)
URLS =
{'inputs': 'https://ndownloader.figshare.com/files/51130115', 'ground_truth': 'https://ndownloader.figshare.com/files/51130100'}
CHECKSUMS =
{'inputs': None, 'ground_truth': None}
def
get_phmamm_data(path: Union[os.PathLike, str], download: bool = False) -> str:
32def get_phmamm_data(path: Union[os.PathLike, str], download: bool = False) -> str: 33 """Download the PhMamm dataset. 34 35 Args: 36 path: Filepath to a folder where the downloaded data will be saved. 37 download: Whether to download the data if it is not present. 38 39 Returns: 40 Filepath where the dataset is stored. 41 """ 42 data_dir = os.path.join(path, "data") 43 if os.path.exists(data_dir): 44 return data_dir 45 46 os.makedirs(path, exist_ok=True) 47 48 inputs_zip = os.path.join(path, "Inputs.zip") 49 util.download_source(inputs_zip, URLS["inputs"], download, checksum=CHECKSUMS["inputs"]) 50 util.unzip(inputs_zip, data_dir, remove=True) 51 52 gt_zip = os.path.join(path, "ASTEC_Ground_truth.zip") 53 util.download_source(gt_zip, URLS["ground_truth"], download, checksum=CHECKSUMS["ground_truth"]) 54 util.unzip(gt_zip, data_dir, remove=True) 55 56 return data_dir
Download the PhMamm dataset.
Arguments:
- path: Filepath to a folder where the downloaded data will be saved.
- download: Whether to download the data if it is not present.
Returns:
Filepath where the dataset is stored.
def
get_phmamm_paths( path: Union[os.PathLike, str], timepoints: Optional[Sequence[int]] = None, download: bool = False) -> Tuple[List[str], List[str]]:
59def get_phmamm_paths( 60 path: Union[os.PathLike, str], timepoints: Optional[Sequence[int]] = None, download: bool = False, 61) -> Tuple[List[str], List[str]]: 62 """Get paths to the PhMamm data. 63 64 Args: 65 path: Filepath to a folder where the downloaded data will be saved. 66 timepoints: The timepoints of the time-lapse to restrict to, e.g. range(1, 81). By default all 100 are used. 67 download: Whether to download the data if it is not present. 68 69 Returns: 70 List of filepaths for the image data. 71 List of filepaths for the label data. 72 """ 73 data_dir = get_phmamm_data(path, download) 74 75 raw_paths = natsorted(glob(os.path.join(data_dir, "Inputs", "*.tiff"))) 76 label_paths = natsorted(glob(os.path.join(data_dir, "ASTEC_Ground_truth", "*.tiff"))) 77 assert len(raw_paths) == len(label_paths) and len(raw_paths) > 0 78 79 if timepoints is not None: 80 timepoints = set(timepoints) 81 keep = [int(os.path.basename(p).split("_t")[1][:3]) in timepoints for p in raw_paths] 82 raw_paths = [p for p, k in zip(raw_paths, keep) if k] 83 label_paths = [p for p, k in zip(label_paths, keep) if k] 84 85 return raw_paths, label_paths
Get paths to the PhMamm data.
Arguments:
- path: Filepath to a folder where the downloaded data will be saved.
- timepoints: The timepoints of the time-lapse to restrict to, e.g. range(1, 81). By default all 100 are used.
- download: Whether to download the data if it is not present.
Returns:
List of filepaths for the image data. List of filepaths for the label data.
def
get_phmamm_dataset( path: Union[os.PathLike, str], patch_shape: Tuple[int, int, int], offsets: Optional[List[List[int]]] = None, boundaries: bool = False, binary: bool = False, timepoints: Optional[Sequence[int]] = None, download: bool = False, **kwargs) -> torch.utils.data.dataset.Dataset:
88def get_phmamm_dataset( 89 path: Union[os.PathLike, str], 90 patch_shape: Tuple[int, int, int], 91 offsets: Optional[List[List[int]]] = None, 92 boundaries: bool = False, 93 binary: bool = False, 94 timepoints: Optional[Sequence[int]] = None, 95 download: bool = False, 96 **kwargs 97) -> Dataset: 98 """Get the PhMamm dataset for cell segmentation in light-sheet microscopy. 99 100 Args: 101 path: Filepath to a folder where the downloaded data will be saved. 102 patch_shape: The patch shape to use for training. 103 offsets: Offset values for affinity computation used as target. 104 boundaries: Whether to compute boundaries as the target. 105 binary: Whether to use a binary segmentation target. 106 timepoints: The timepoints of the time-lapse to restrict to, e.g. range(1, 81). By default all 100 are used. 107 download: Whether to download the data if it is not present. 108 kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset`. 109 110 Returns: 111 The segmentation dataset. 112 """ 113 raw_paths, label_paths = get_phmamm_paths(path, timepoints, download) 114 115 kwargs, _ = util.add_instance_label_transform( 116 kwargs, add_binary_target=True, offsets=offsets, boundaries=boundaries, binary=binary 117 ) 118 119 return torch_em.default_segmentation_dataset( 120 raw_paths=raw_paths, 121 raw_key=None, 122 label_paths=label_paths, 123 label_key=None, 124 patch_shape=patch_shape, 125 **kwargs 126 )
Get the PhMamm dataset for cell segmentation in light-sheet microscopy.
Arguments:
- path: Filepath to a folder where the downloaded data will be saved.
- patch_shape: The patch shape to use for training.
- offsets: Offset values for affinity computation used as target.
- boundaries: Whether to compute boundaries as the target.
- binary: Whether to use a binary segmentation target.
- timepoints: The timepoints of the time-lapse to restrict to, e.g. range(1, 81). By default all 100 are used.
- download: Whether to download the data if it is not present.
- kwargs: Additional keyword arguments for
torch_em.default_segmentation_dataset.
Returns:
The segmentation dataset.
def
get_phmamm_loader( path: Union[os.PathLike, str], batch_size: int, patch_shape: Tuple[int, int, int], offsets: Optional[List[List[int]]] = None, boundaries: bool = False, binary: bool = False, timepoints: Optional[Sequence[int]] = None, download: bool = False, **kwargs) -> torch.utils.data.dataloader.DataLoader:
129def get_phmamm_loader( 130 path: Union[os.PathLike, str], 131 batch_size: int, 132 patch_shape: Tuple[int, int, int], 133 offsets: Optional[List[List[int]]] = None, 134 boundaries: bool = False, 135 binary: bool = False, 136 timepoints: Optional[Sequence[int]] = None, 137 download: bool = False, 138 **kwargs 139) -> DataLoader: 140 """Get the PhMamm dataloader for cell segmentation in light-sheet microscopy. 141 142 Args: 143 path: Filepath to a folder where the downloaded data will be saved. 144 batch_size: The batch size for training. 145 patch_shape: The patch shape to use for training. 146 offsets: Offset values for affinity computation used as target. 147 boundaries: Whether to compute boundaries as the target. 148 binary: Whether to use a binary segmentation target. 149 timepoints: The timepoints of the time-lapse to restrict to, e.g. range(1, 81). By default all 100 are used. 150 download: Whether to download the data if it is not present. 151 kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset` or for the PyTorch DataLoader. 152 153 Returns: 154 The DataLoader. 155 """ 156 ds_kwargs, loader_kwargs = util.split_kwargs(torch_em.default_segmentation_dataset, **kwargs) 157 dataset = get_phmamm_dataset( 158 path=path, 159 patch_shape=patch_shape, 160 offsets=offsets, 161 boundaries=boundaries, 162 binary=binary, 163 timepoints=timepoints, 164 download=download, 165 **ds_kwargs, 166 ) 167 return torch_em.get_data_loader(dataset=dataset, batch_size=batch_size, **loader_kwargs)
Get the PhMamm dataloader for cell segmentation in light-sheet microscopy.
Arguments:
- path: Filepath to a folder where the downloaded data will be saved.
- batch_size: The batch size for training.
- patch_shape: The patch shape to use for training.
- offsets: Offset values for affinity computation used as target.
- boundaries: Whether to compute boundaries as the target.
- binary: Whether to use a binary segmentation target.
- timepoints: The timepoints of the time-lapse to restrict to, e.g. range(1, 81). By default all 100 are used.
- download: Whether to download the data if it is not present.
- kwargs: Additional keyword arguments for
torch_em.default_segmentation_datasetor for the PyTorch DataLoader.
Returns:
The DataLoader.