simcats_datasets.support_functions.pytorch_format_output

Functions for formatting the output of the Pytorch Dataset class.

Every function must accept a measurement (as array), a ground truth (e.g. TCT mask as array) and the image id as input. Output type depends on the ground truth type and the required pytorch datatype (tensor as long, float, …). Ground truth could for example be a pixel mask or defined start end points of lines. Please look at format_dict_csd_float_ground_truth_long for a reference.

@author: f.hader

Module Contents

Functions

format_dict_csd_float_ground_truth_long

Format the output of the Pytorch Dataset class to be a dict with entries 'csd' and 'ground_truth' of dtype float and long, respectively. (default of Pytorch Dataset class.)

format_dict_csd_float16_ground_truth_long

Format the output of the Pytorch Dataset class to be a dict with entries 'csd' and 'ground_truth' of dtype float16 and long, respectively.

format_dict_csd_float_ground_truth_float

Format the output of the Pytorch Dataset class to be a dict with entries 'csd' and 'ground_truth' of dtype float and float, respectively.

format_mmsegmentation

Format the output of the Pytorch Dataset class to be conform to the MMSegmentation CustomDataset of version 0.6.0, see https://github.com/open-mmlab/mmsegmentation/blob/v0.6.0/mmseg/datasets/custom.py.

format_csd_only

Format the output of the Pytorch Dataset class to be just a measurement.

format_csd_float16_only

Format the output of the Pytorch Dataset class to be just a float16 (half precision) measurement.

format_csd_bfloat16_only

Format the output of the Pytorch Dataset class to be just a bfloat16 (half precision) measurement.

format_csd_class_index

Format the output of the Pytorch Dataset class to be the measurement, a class index (which is always 0 as we have no classes) and the index.

format_tuple_csd_float_ground_truth_float

Format the output of the Pytorch Dataset class to be a tuple of the measurement and the ground_truth.

Module Implementation Details

simcats_datasets.support_functions.pytorch_format_output.format_dict_csd_float_ground_truth_long(measurement, ground_truth, idx)

Format the output of the Pytorch Dataset class to be a dict with entries ‘csd’ and ‘ground_truth’ of dtype float and long, respectively. (default of Pytorch Dataset class.)

Parameters:
  • measurement (numpy.ndarray) – The measurement array.

  • ground_truth (numpy.ndarray) – Ground truth as pixel mask.

  • idx (int) – index of the measurement. Not used in this format.

Returns:

Dict with ‘csd’ and ‘ground_truth’ of dtype float and long, respectively.

Return type:

dict[str, torch.Tensor]

simcats_datasets.support_functions.pytorch_format_output.format_dict_csd_float16_ground_truth_long(measurement, ground_truth, idx)

Format the output of the Pytorch Dataset class to be a dict with entries ‘csd’ and ‘ground_truth’ of dtype float16 and long, respectively.

Parameters:
  • measurement (numpy.ndarray) – The measurement array.

  • ground_truth (numpy.ndarray) – Ground truth as pixel mask.

  • idx (int) – index of the measurement. Not used in this format.

Returns:

Dict with ‘csd’ and ‘ground_truth’ of dtype float16 and long, respectively.

Return type:

dict[str, torch.Tensor]

simcats_datasets.support_functions.pytorch_format_output.format_dict_csd_float_ground_truth_float(measurement, ground_truth, idx)

Format the output of the Pytorch Dataset class to be a dict with entries ‘csd’ and ‘ground_truth’ of dtype float and float, respectively.

Parameters:
  • measurement (numpy.ndarray) – The measurement array.

  • ground_truth (numpy.ndarray) – Ground truth as pixel mask.

  • idx (int) – index of the measurement. Not used in this format.

Returns:

Dict with ‘csd’ and ‘ground_truth’ of dtype float and float, respectively.

Return type:

dict[str, torch.Tensor]

simcats_datasets.support_functions.pytorch_format_output.format_mmsegmentation(measurement, ground_truth, idx)

Format the output of the Pytorch Dataset class to be conform to the MMSegmentation CustomDataset of version 0.6.0, see https://github.com/open-mmlab/mmsegmentation/blob/v0.6.0/mmseg/datasets/custom.py.

Parameters:
  • measurement (numpy.ndarray) – The measurement array.

  • ground_truth (numpy.ndarray) – Ground truth as pixel mask.

  • idx (int) – index of the measurement.

Returns:

//github.com/open-mmlab/mmsegmentation/blob/v0.6.0/mmseg/datasets/custom.py.

Return type:

Dict with data conform to the MMSegmentation CustomDataset of version 0.6.0, see https

simcats_datasets.support_functions.pytorch_format_output.format_csd_only(measurement, ground_truth, idx)

Format the output of the Pytorch Dataset class to be just a measurement.

Parameters:
  • measurement (numpy.ndarray) – The measurement array.

  • ground_truth (numpy.ndarray) – Ground truth as pixel mask. Not used in this format.

  • idx (int) – Index of the measurement. Not used in this format.

Returns:

The measurement as tensor.

Return type:

torch.Tensor

simcats_datasets.support_functions.pytorch_format_output.format_csd_float16_only(measurement, ground_truth, idx)

Format the output of the Pytorch Dataset class to be just a float16 (half precision) measurement.

Parameters:
  • measurement (numpy.ndarray) – The measurement array.

  • ground_truth (numpy.ndarray) – Ground truth as pixel mask. Not used in this format.

  • idx (int) – Index of the measurement. Not used in this format.

Returns:

The float 16 (half precision) measurement as tensor.

Return type:

torch.Tensor

simcats_datasets.support_functions.pytorch_format_output.format_csd_bfloat16_only(measurement, ground_truth, idx)

Format the output of the Pytorch Dataset class to be just a bfloat16 (half precision) measurement.

Parameters:
  • measurement (numpy.ndarray) – The measurement array.

  • ground_truth (numpy.ndarray) – Ground truth as pixel mask. Not used in this format.

  • idx (int) – Index of the measurement. Not used in this format.

Returns:

The brain float 16 (half precision) measurement as tensor.

Return type:

torch.Tensor

simcats_datasets.support_functions.pytorch_format_output.format_csd_class_index(measurement, ground_truth, idx)

Format the output of the Pytorch Dataset class to be the measurement, a class index (which is always 0 as we have no classes) and the index.

This is needed to be conform to the datasets used in DeepSVDD, see https://github.com/lukasruff/Deep-SVDD-PyTorch.

Parameters:
  • measurement (numpy.ndarray) – The measurement array.

  • ground_truth (numpy.ndarray) – Ground truth as pixel mask. Not used in this format.

  • idx (int) – Index of the measurement.

Returns:

A tuple of measurement, class index, and the index.

Return type:

Tuple[torch.Tensor, torch.Tensor, int]

simcats_datasets.support_functions.pytorch_format_output.format_tuple_csd_float_ground_truth_float(measurement, ground_truth, idx)

Format the output of the Pytorch Dataset class to be a tuple of the measurement and the ground_truth.

Parameters:
  • measurement (numpy.ndarray) – The measurement array.

  • ground_truth (numpy.ndarray) – Ground truth as pixel mask.

  • idx (int) – index of the measurement. Not used in this format.

Returns:

Tuple with measurement and ground_truth of dtype float and float, respectively.

Return type:

dict[str, torch.Tensor]