torch_em.data.datasets.medical.acouslic_ai

The Acouslic AI dataset contains annotations for fetal segmentation in ultrasound images.

This dataset is from the challenge: https://acouslic-ai.grand-challenge.org/. Please cite the challenge if you use this dataset for your publication.

  1"""The Acouslic AI dataset contains annotations for fetal segmentation in ultrasound images.
  2
  3This dataset is from the challenge: https://acouslic-ai.grand-challenge.org/.
  4Please cite the challenge if you use this dataset for your publication.
  5"""
  6
  7import os
  8from glob import glob
  9from natsort import natsorted
 10from typing import Tuple, Union, List
 11
 12from torch.utils.data import Dataset, DataLoader
 13
 14import torch_em
 15
 16from .. import util
 17
 18
 19URL = "https://zenodo.org/records/11005384/files/acouslic-ai-train-set.zip"
 20CHECKSUM = "187602dd243a3a872502b57b8ea56e28c67a9ded547b6e816b00c6d41f8b8767"
 21
 22
 23def get_acouslic_ai_data(path: Union[os.PathLike, str], download: bool = False) -> str:
 24    """Download the Acouslic AI dataset.
 25
 26    Args:
 27        path: Filepath to a folder where the data is downloaded for further processing.
 28        download: Whether to download the data if it is not present.
 29
 30    Returns:
 31        Filepath where the data is downlaoded.
 32    """
 33    data_dir = os.path.join(path, "data")
 34    if os.path.exists(data_dir):
 35        return data_dir
 36
 37    os.makedirs(path, exist_ok=True)
 38
 39    zip_path = os.path.join(path, "acouslic-ai-train-set.zip")
 40    util.download_source(path=zip_path, url=URL, download=download, checksum=CHECKSUM)
 41    util.unzip(zip_path=zip_path, dst=data_dir, remove=False)
 42
 43    return data_dir
 44
 45
 46def get_acouslic_ai_paths(path: Union[os.PathLike, str], download: bool = False) -> Tuple[List[str], List[str]]:
 47    """Get paths to the Acouslic AI data.
 48
 49    Args:
 50        path: Filepath to a folder where the data is downloaded for further processing.
 51        download: Whether to download the data if it is not present.
 52
 53    Returns:
 54        List of filepaths for the image data.
 55        List of filepaths for the label data.
 56    """
 57    data_dir = get_acouslic_ai_data(path=path, download=download)
 58
 59    image_paths = natsorted(glob(os.path.join(data_dir, "images", "stacked_fetal_ultrasound", "*.mha")))
 60    gt_paths = natsorted(glob(os.path.join(data_dir, "masks", "stacked_fetal_abdomen", "*.mha")))
 61
 62    return image_paths, gt_paths
 63
 64
 65def get_acouslic_ai_dataset(
 66    path: Union[os.PathLike, str],
 67    patch_shape: Tuple[int, ...],
 68    resize_inputs: bool = False,
 69    download: bool = False,
 70    **kwargs
 71) -> Dataset:
 72    """Get the Acouslic AI dataset for fetal segmentation.
 73
 74    Args:
 75        path: Filepath to a folder where the data is downloaded for further processing.
 76        patch_shape: The patch shape to use for training.
 77        resize_inputs: Whether to resize inputs to the desired patch shape.
 78        download: Whether to download the data if it is not present.
 79        kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset`.
 80
 81    Returns:
 82        The segmentation dataset.
 83    """
 84    image_paths, gt_paths = get_acouslic_ai_paths(path=path, download=download)
 85
 86    if resize_inputs:
 87        resize_kwargs = {"patch_shape": patch_shape, "is_rgb": False}
 88        kwargs, patch_shape = util.update_kwargs_for_resize_trafo(
 89            kwargs=kwargs, patch_shape=patch_shape, resize_inputs=resize_inputs, resize_kwargs=resize_kwargs
 90        )
 91
 92    return torch_em.default_segmentation_dataset(
 93        raw_paths=image_paths,
 94        raw_key=None,
 95        label_paths=gt_paths,
 96        label_key=None,
 97        patch_shape=patch_shape,
 98        **kwargs
 99    )
100
101
102def get_acouslic_ai_loader(
103    path: Union[os.PathLike, str],
104    batch_size: int,
105    patch_shape: Tuple[int, ...],
106    resize_inputs: bool = False,
107    download: bool = False,
108    **kwargs
109) -> DataLoader:
110    """Get the Acouslic AI dataloader for fetal segmentation.
111
112    Args:
113        path: Filepath to a folder where the data is downloaded for further processing.
114        batch_size: The batch size for training.
115        patch_shape: The patch shape to use for training.
116        resize_inputs: Whether to resize inputs to the desired patch shape.
117        download: Whether to download the data if it is not present.
118        kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset` or for the PyTorch DataLoader.
119
120    Returns:
121        The DataLoader.
122    """
123    ds_kwargs, loader_kwargs = util.split_kwargs(torch_em.default_segmentation_dataset, **kwargs)
124    dataset = get_acouslic_ai_dataset(path, patch_shape, resize_inputs, download, **ds_kwargs)
125    return torch_em.get_data_loader(dataset, batch_size, **loader_kwargs)
URL = 'https://zenodo.org/records/11005384/files/acouslic-ai-train-set.zip'
CHECKSUM = '187602dd243a3a872502b57b8ea56e28c67a9ded547b6e816b00c6d41f8b8767'
def get_acouslic_ai_data(path: Union[os.PathLike, str], download: bool = False) -> str:
24def get_acouslic_ai_data(path: Union[os.PathLike, str], download: bool = False) -> str:
25    """Download the Acouslic AI dataset.
26
27    Args:
28        path: Filepath to a folder where the data is downloaded for further processing.
29        download: Whether to download the data if it is not present.
30
31    Returns:
32        Filepath where the data is downlaoded.
33    """
34    data_dir = os.path.join(path, "data")
35    if os.path.exists(data_dir):
36        return data_dir
37
38    os.makedirs(path, exist_ok=True)
39
40    zip_path = os.path.join(path, "acouslic-ai-train-set.zip")
41    util.download_source(path=zip_path, url=URL, download=download, checksum=CHECKSUM)
42    util.unzip(zip_path=zip_path, dst=data_dir, remove=False)
43
44    return data_dir

Download the Acouslic AI dataset.

Arguments:
  • path: Filepath to a folder where the data is downloaded for further processing.
  • download: Whether to download the data if it is not present.
Returns:

Filepath where the data is downlaoded.

def get_acouslic_ai_paths( path: Union[os.PathLike, str], download: bool = False) -> Tuple[List[str], List[str]]:
47def get_acouslic_ai_paths(path: Union[os.PathLike, str], download: bool = False) -> Tuple[List[str], List[str]]:
48    """Get paths to the Acouslic AI data.
49
50    Args:
51        path: Filepath to a folder where the data is downloaded for further processing.
52        download: Whether to download the data if it is not present.
53
54    Returns:
55        List of filepaths for the image data.
56        List of filepaths for the label data.
57    """
58    data_dir = get_acouslic_ai_data(path=path, download=download)
59
60    image_paths = natsorted(glob(os.path.join(data_dir, "images", "stacked_fetal_ultrasound", "*.mha")))
61    gt_paths = natsorted(glob(os.path.join(data_dir, "masks", "stacked_fetal_abdomen", "*.mha")))
62
63    return image_paths, gt_paths

Get paths to the Acouslic AI data.

Arguments:
  • path: Filepath to a folder where the data is downloaded for further processing.
  • 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_acouslic_ai_dataset( path: Union[os.PathLike, str], patch_shape: Tuple[int, ...], resize_inputs: bool = False, download: bool = False, **kwargs) -> torch.utils.data.dataset.Dataset:
 66def get_acouslic_ai_dataset(
 67    path: Union[os.PathLike, str],
 68    patch_shape: Tuple[int, ...],
 69    resize_inputs: bool = False,
 70    download: bool = False,
 71    **kwargs
 72) -> Dataset:
 73    """Get the Acouslic AI dataset for fetal segmentation.
 74
 75    Args:
 76        path: Filepath to a folder where the data is downloaded for further processing.
 77        patch_shape: The patch shape to use for training.
 78        resize_inputs: Whether to resize inputs to the desired patch shape.
 79        download: Whether to download the data if it is not present.
 80        kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset`.
 81
 82    Returns:
 83        The segmentation dataset.
 84    """
 85    image_paths, gt_paths = get_acouslic_ai_paths(path=path, download=download)
 86
 87    if resize_inputs:
 88        resize_kwargs = {"patch_shape": patch_shape, "is_rgb": False}
 89        kwargs, patch_shape = util.update_kwargs_for_resize_trafo(
 90            kwargs=kwargs, patch_shape=patch_shape, resize_inputs=resize_inputs, resize_kwargs=resize_kwargs
 91        )
 92
 93    return torch_em.default_segmentation_dataset(
 94        raw_paths=image_paths,
 95        raw_key=None,
 96        label_paths=gt_paths,
 97        label_key=None,
 98        patch_shape=patch_shape,
 99        **kwargs
100    )

Get the Acouslic AI dataset for fetal segmentation.

Arguments:
  • path: Filepath to a folder where the data is downloaded for further processing.
  • patch_shape: The patch shape to use for training.
  • resize_inputs: Whether to resize inputs to the desired patch shape.
  • 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_acouslic_ai_loader( path: Union[os.PathLike, str], batch_size: int, patch_shape: Tuple[int, ...], resize_inputs: bool = False, download: bool = False, **kwargs) -> torch.utils.data.dataloader.DataLoader:
103def get_acouslic_ai_loader(
104    path: Union[os.PathLike, str],
105    batch_size: int,
106    patch_shape: Tuple[int, ...],
107    resize_inputs: bool = False,
108    download: bool = False,
109    **kwargs
110) -> DataLoader:
111    """Get the Acouslic AI dataloader for fetal segmentation.
112
113    Args:
114        path: Filepath to a folder where the data is downloaded for further processing.
115        batch_size: The batch size for training.
116        patch_shape: The patch shape to use for training.
117        resize_inputs: Whether to resize inputs to the desired patch shape.
118        download: Whether to download the data if it is not present.
119        kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset` or for the PyTorch DataLoader.
120
121    Returns:
122        The DataLoader.
123    """
124    ds_kwargs, loader_kwargs = util.split_kwargs(torch_em.default_segmentation_dataset, **kwargs)
125    dataset = get_acouslic_ai_dataset(path, patch_shape, resize_inputs, download, **ds_kwargs)
126    return torch_em.get_data_loader(dataset, batch_size, **loader_kwargs)

Get the Acouslic AI dataloader for fetal segmentation.

Arguments:
  • path: Filepath to a folder where the data is downloaded for further processing.
  • batch_size: The batch size for training.
  • patch_shape: The patch shape to use for training.
  • resize_inputs: Whether to resize inputs to the desired patch shape.
  • download: Whether to download the data if it is not present.
  • kwargs: Additional keyword arguments for torch_em.default_segmentation_dataset or for the PyTorch DataLoader.
Returns:

The DataLoader.