cellmap_segmentation_challenge.utils.dataloader

Contents

cellmap_segmentation_challenge.utils.dataloader#

Functions

get_dataloader(datasplit_path, classes, ...)

Get the train and validation dataloaders.

cellmap_segmentation_challenge.utils.dataloader.get_dataloader(datasplit_path: str, classes: Sequence[str], batch_size: int, array_info: Mapping[str, Sequence[int | float]] | None = None, input_array_info: Mapping[str, Sequence[int | float]] | None = None, target_array_info: Mapping[str, Sequence[int | float]] | None = None, spatial_transforms: Mapping[str, Any] | None = None, iterations_per_epoch: int = 1000, device: str | device = 'cuda') tuple[CellMapDataLoader, DataLoader][source]#

Get the train and validation dataloaders.

This function gets the train and validation dataloaders for the given datasplit file, classes, batch size, array info, spatial transforms, iterations per epoch, number of workers, and device.

Parameters:
  • datasplit_path (str) – Path to the datasplit file that defines the train/val split the dataloader should use.

  • classes (Sequence[str]) – List of classes to segment.

  • batch_size (int) – Batch size for the dataloader.

  • array_info (Optional[Mapping[str, Sequence[int | float]]]) – Dictionary containing the shape and scale of the data to load for the input and target. Either array_info or input_array_info & target_array_info must be provided.

  • input_array_info (Optional[Mapping[str, Sequence[int | float]]]) – Dictionary containing the shape and scale of the data to load for the input.

  • target_array_info (Optional[Mapping[str, Sequence[int | float]]]) – Dictionary containing the shape and scale of the data to load for the target.

  • spatial_transforms (Optional[Mapping[str, any]]) – Dictionary containing the spatial transformations to apply to the data. For example the dictionary could contain transformations like mirror, transpose, and rotate.

  • { (spatial_transforms =) –

    # 3D

    # Probability of applying mirror for each axis # Values range from 0 (no mirroring) to 1 (will always mirror)

    ”mirror”: {“axes”: {“x”: 0.5, “y”: 0.5, “z”: 0.5}},

    # Specifies the axes that will be invovled in the trasposition

    ”transpose”: {“axes”: [“x”, “y”, “z”]},

    # Defines rotation range for each axis. # Rotation angle for each axis is randomly chosen within the specified range (-180, 180).

    ”rotate”: {“axes”: {“x”: [-180, 180], “y”: [-180, 180], “z”: [-180, 180]}},

    # 2D (used when there is no z axis) # “mirror”: {“axes”: {“x”: 0.5, “y”: 0.5}}, # “transpose”: {“axes”: [“x”, “y”]}, # “rotate”: {“axes”: {“x”: [-180, 180], “y”: [-180, 180]}},

  • }

  • iterations_per_epoch (int)

  • device (str | device)

Return type:

tuple[CellMapDataLoader, DataLoader]

iterations_per_epochint

Number of iterations per epoch.

devicestr or torch.device

Device to use for the dataloaders.

Returns:

Tuple containing the train and validation dataloaders.

Return type:

tuple[torch.utils.data.DataLoader, torch.utils.data.DataLoader]

Parameters:
  • datasplit_path (str)

  • classes (Sequence[str])

  • batch_size (int)

  • array_info (Mapping[str, Sequence[int | float]] | None)

  • input_array_info (Mapping[str, Sequence[int | float]] | None)

  • target_array_info (Mapping[str, Sequence[int | float]] | None)

  • spatial_transforms (Mapping[str, Any] | None)

  • iterations_per_epoch (int)

  • device (str | device)