torch_em.data.datasets.electron_microscopy.isbi2012
The ISBI2012 dataset was the first neuron segmentation challenge, held at the ISBI 2012 competition. It contains a small annotated EM volume from the fruit-fly brain.
If you use this dataset in your research please cite the following publication: https://doi.org/10.3389/fnana.2015.00142.
1"""The ISBI2012 dataset was the first neuron segmentation challenge, held at the ISBI 2012 competition. 2It contains a small annotated EM volume from the fruit-fly brain. 3 4If you use this dataset in your research please cite the following publication: 5https://doi.org/10.3389/fnana.2015.00142. 6""" 7 8import os 9from typing import List, Optional, Tuple, Union 10 11from torch.utils.data import Dataset, DataLoader 12 13import torch_em 14from .. import util 15 16 17ISBI_URL = "https://oc.embl.de/index.php/s/h0TkwqxU0PJDdMd/download" 18CHECKSUM = "0e10fe909a1243084d91773470856993b7d40126a12e85f0f1345a7a9e512f29" 19 20 21def get_isbi_data(path: Union[os.PathLike, str], download: bool = False): 22 """Download the ISBI2012 dataset. 23 24 Args: 25 path: Filepath to a folder where the downloaded data will be saved. 26 download: Whether to download the data if it is not present. 27 """ 28 os.makedirs(path, exist_ok=True) 29 util.download_source(os.path.join(path, "isbi.h5"), ISBI_URL, download, CHECKSUM) 30 31 32def get_isbi_paths(path: Union[os.PathLike, str], download: bool = False) -> str: 33 """Get path to ISBI data. 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 The filepath for the stored data. 41 """ 42 get_isbi_data(path, download) 43 volume_path = os.path.join(path, "isbi.h5") 44 return volume_path 45 46 47def get_isbi_dataset( 48 path: Union[os.PathLike, str], 49 patch_shape: Tuple[int, int, int], 50 download: bool = False, 51 offsets: Optional[List[List[int]]] = None, 52 boundaries: bool = False, 53 use_original_labels: bool = False, 54 **kwargs 55) -> Dataset: 56 """Get the dataset for EM neuron segmentation in ISBI 2012. 57 58 Args: 59 path: Filepath to a folder where the downloaded data will be saved. 60 patch_shape: The patch shape to use for training. 61 download: Whether to download the data if it is not present. 62 offsets: Offset values for affinity computation used as target. 63 boundaries: Whether to compute boundaries as the target. 64 use_original_labels: Whether to use the original annotations or postprocessed 3d annotations. 65 kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset`. 66 67 Returns: 68 The segmentation dataset. 69 """ 70 assert len(patch_shape) == 3 71 72 volume_path = get_isbi_paths(path, download) 73 74 ndim = 2 if patch_shape[0] == 1 else 3 75 kwargs = util.update_kwargs(kwargs, "ndim", ndim) 76 77 kwargs, _ = util.add_instance_label_transform( 78 kwargs, add_binary_target=False, boundaries=boundaries, offsets=offsets 79 ) 80 81 return torch_em.default_segmentation_dataset( 82 raw_paths=volume_path, 83 raw_key="raw", 84 label_paths=volume_path, 85 label_key="labels/membranes" if use_original_labels else "labels/gt_segmentation", 86 patch_shape=patch_shape, 87 **kwargs 88 ) 89 90 91def get_isbi_loader( 92 path: Union[os.PathLike, str], 93 patch_shape: Tuple[int, int, int], 94 batch_size: int, 95 download: bool = False, 96 offsets: Optional[List[List[int]]] = None, 97 boundaries: bool = False, 98 use_original_labels: bool = False, 99 **kwargs 100) -> DataLoader: 101 """Get the DataLoader for EM neuron segmentation in ISBI 2012. 102 103 Args: 104 path: Filepath to a folder where the downloaded data will be saved. 105 patch_shape: The patch shape to use for training. 106 batch_size: The batch size for training. 107 download: Whether to download the data if it is not present. 108 offsets: Offset values for affinity computation used as target. 109 boundaries: Whether to compute boundaries as the target. 110 use_original_labels: Whether to use the original annotations or postprocessed 3d annotations. 111 kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset` or for the PyTorch DataLoader. 112 113 Returns: 114 The DataLoader. 115 """ 116 ds_kwargs, loader_kwargs = util.split_kwargs(torch_em.default_segmentation_dataset, **kwargs) 117 dataset = get_isbi_dataset( 118 path, patch_shape, download=download, offsets=offsets, 119 boundaries=boundaries, use_original_labels=use_original_labels, **ds_kwargs 120 ) 121 return torch_em.get_data_loader(dataset, batch_size, **loader_kwargs)
ISBI_URL =
'https://oc.embl.de/index.php/s/h0TkwqxU0PJDdMd/download'
CHECKSUM =
'0e10fe909a1243084d91773470856993b7d40126a12e85f0f1345a7a9e512f29'
def
get_isbi_data(path: Union[os.PathLike, str], download: bool = False):
22def get_isbi_data(path: Union[os.PathLike, str], download: bool = False): 23 """Download the ISBI2012 dataset. 24 25 Args: 26 path: Filepath to a folder where the downloaded data will be saved. 27 download: Whether to download the data if it is not present. 28 """ 29 os.makedirs(path, exist_ok=True) 30 util.download_source(os.path.join(path, "isbi.h5"), ISBI_URL, download, CHECKSUM)
Download the ISBI2012 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.
def
get_isbi_paths(path: Union[os.PathLike, str], download: bool = False) -> str:
33def get_isbi_paths(path: Union[os.PathLike, str], download: bool = False) -> str: 34 """Get path to ISBI data. 35 36 Args: 37 path: Filepath to a folder where the downloaded data will be saved. 38 download: Whether to download the data if it is not present. 39 40 Returns: 41 The filepath for the stored data. 42 """ 43 get_isbi_data(path, download) 44 volume_path = os.path.join(path, "isbi.h5") 45 return volume_path
Get path to ISBI data.
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:
The filepath for the stored data.
def
get_isbi_dataset( path: Union[os.PathLike, str], patch_shape: Tuple[int, int, int], download: bool = False, offsets: Optional[List[List[int]]] = None, boundaries: bool = False, use_original_labels: bool = False, **kwargs) -> torch.utils.data.dataset.Dataset:
48def get_isbi_dataset( 49 path: Union[os.PathLike, str], 50 patch_shape: Tuple[int, int, int], 51 download: bool = False, 52 offsets: Optional[List[List[int]]] = None, 53 boundaries: bool = False, 54 use_original_labels: bool = False, 55 **kwargs 56) -> Dataset: 57 """Get the dataset for EM neuron segmentation in ISBI 2012. 58 59 Args: 60 path: Filepath to a folder where the downloaded data will be saved. 61 patch_shape: The patch shape to use for training. 62 download: Whether to download the data if it is not present. 63 offsets: Offset values for affinity computation used as target. 64 boundaries: Whether to compute boundaries as the target. 65 use_original_labels: Whether to use the original annotations or postprocessed 3d annotations. 66 kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset`. 67 68 Returns: 69 The segmentation dataset. 70 """ 71 assert len(patch_shape) == 3 72 73 volume_path = get_isbi_paths(path, download) 74 75 ndim = 2 if patch_shape[0] == 1 else 3 76 kwargs = util.update_kwargs(kwargs, "ndim", ndim) 77 78 kwargs, _ = util.add_instance_label_transform( 79 kwargs, add_binary_target=False, boundaries=boundaries, offsets=offsets 80 ) 81 82 return torch_em.default_segmentation_dataset( 83 raw_paths=volume_path, 84 raw_key="raw", 85 label_paths=volume_path, 86 label_key="labels/membranes" if use_original_labels else "labels/gt_segmentation", 87 patch_shape=patch_shape, 88 **kwargs 89 )
Get the dataset for EM neuron segmentation in ISBI 2012.
Arguments:
- path: Filepath to a folder where the downloaded data will be saved.
- patch_shape: The patch shape to use for training.
- download: Whether to download the data if it is not present.
- offsets: Offset values for affinity computation used as target.
- boundaries: Whether to compute boundaries as the target.
- use_original_labels: Whether to use the original annotations or postprocessed 3d annotations.
- kwargs: Additional keyword arguments for
torch_em.default_segmentation_dataset
.
Returns:
The segmentation dataset.
def
get_isbi_loader( path: Union[os.PathLike, str], patch_shape: Tuple[int, int, int], batch_size: int, download: bool = False, offsets: Optional[List[List[int]]] = None, boundaries: bool = False, use_original_labels: bool = False, **kwargs) -> torch.utils.data.dataloader.DataLoader:
92def get_isbi_loader( 93 path: Union[os.PathLike, str], 94 patch_shape: Tuple[int, int, int], 95 batch_size: int, 96 download: bool = False, 97 offsets: Optional[List[List[int]]] = None, 98 boundaries: bool = False, 99 use_original_labels: bool = False, 100 **kwargs 101) -> DataLoader: 102 """Get the DataLoader for EM neuron segmentation in ISBI 2012. 103 104 Args: 105 path: Filepath to a folder where the downloaded data will be saved. 106 patch_shape: The patch shape to use for training. 107 batch_size: The batch size for training. 108 download: Whether to download the data if it is not present. 109 offsets: Offset values for affinity computation used as target. 110 boundaries: Whether to compute boundaries as the target. 111 use_original_labels: Whether to use the original annotations or postprocessed 3d annotations. 112 kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset` or for the PyTorch DataLoader. 113 114 Returns: 115 The DataLoader. 116 """ 117 ds_kwargs, loader_kwargs = util.split_kwargs(torch_em.default_segmentation_dataset, **kwargs) 118 dataset = get_isbi_dataset( 119 path, patch_shape, download=download, offsets=offsets, 120 boundaries=boundaries, use_original_labels=use_original_labels, **ds_kwargs 121 ) 122 return torch_em.get_data_loader(dataset, batch_size, **loader_kwargs)
Get the DataLoader for EM neuron segmentation in ISBI 2012.
Arguments:
- path: Filepath to a folder where the downloaded data will be saved.
- patch_shape: The patch shape to use for training.
- batch_size: The batch size for training.
- download: Whether to download the data if it is not present.
- offsets: Offset values for affinity computation used as target.
- boundaries: Whether to compute boundaries as the target.
- use_original_labels: Whether to use the original annotations or postprocessed 3d annotations.
- kwargs: Additional keyword arguments for
torch_em.default_segmentation_dataset
or for the PyTorch DataLoader.
Returns:
The DataLoader.