dival.reference_reconstructors module

dival.reference_reconstructors.CONFIGURATIONS = {'diptv': {'datasets': ['ellipses', 'lodopab'], 'type': {'cls': 'DeepImagePriorCTReconstructor', 'module': 'dival.reconstructors.dip_ct_reconstructor'}}, 'fbp': {'datasets': ['ellipses', 'lodopab'], 'type': {'cls': 'FBPReconstructor', 'module': 'dival.reconstructors.odl_reconstructors'}}, 'fbpunet': {'datasets': ['ellipses', 'lodopab'], 'learned_params_spec': {'ext': '.pt'}, 'type': {'cls': 'FBPUNetReconstructor', 'module': 'dival.reconstructors.fbpunet_reconstructor'}}, 'iradonmap': {'datasets': ['ellipses', 'lodopab'], 'learned_params_spec': {'ext': '.pt'}, 'type': {'cls': 'IRadonMapReconstructor', 'module': 'dival.reconstructors.iradonmap_reconstructor'}}, 'learnedgd': {'datasets': ['ellipses', 'lodopab'], 'learned_params_spec': {'ext': '.pt'}, 'type': {'cls': 'LearnedGDReconstructor', 'module': 'dival.reconstructors.learnedgd_reconstructor'}}, 'learnedpd': {'datasets': ['ellipses', 'lodopab'], 'learned_params_spec': {'ext': '.pt'}, 'type': {'cls': 'LearnedPDReconstructor', 'module': 'dival.reconstructors.learnedpd_reconstructor'}}, 'tvadam': {'datasets': ['ellipses', 'lodopab'], 'type': {'cls': 'TVAdamCTReconstructor', 'module': 'dival.reconstructors.tvadam_ct_reconstructor'}}}

Specification of reference configurations.

For each configuration key name a dict with the following fields is specified:

'type'dict

The reconstructor class, given by the following fields:

'cls'str

The class name.

'module'str

The module to import the class from.

'datasets'list of str

List of standard dataset names the configuration is available for.

'learned_params_spec'dict, optional

How learned parameters are stored. See also LearnedReconstructor.save_learned_params() and LearnedReconstructor.load_learned_params(). Valid fields are:

'ext'str, optional

A single file with the given extension (e.g. '.pt'). The param path (returned by get_params_path()) is suffixed by this.

'dir'?, optional

A directory. The param path (returned by get_params_path()) is equal to the directory path. not implemented yet

dival.reference_reconstructors.DATASETS = ['ellipses', 'lodopab']

List of standard datasets for which (some) reference reconstructor configurations are available.

dival.reference_reconstructors.construct_reconstructor(reconstructor_key_name_or_type, dataset_name, **kwargs)[source]

Construct reference reconstructor object (not loading parameters).

Note: see :func:get_reference_reconstructor to retrieve a reference reconstructor with optimized parameters.

This function implements the constructors calls which are potentially specific to each configuration.

Parameters
  • reconstructor_key_name_or_type (str or type) – Key name of configuration or reconstructor type.

  • dataset_name (str) – Standard dataset name.

  • kwargs (dict) – Keyword arguments. For CT configurations this includes the 'impl' used by odl.tomo.RayTransform.

Raises
  • ValueError – If the configuration does not exist.

  • NotImplementedError – If construction is not implemented for the configuration.

Returns

reconstructor – The reconstructor instance.

Return type

Reconstructor

dival.reference_reconstructors.validate_reconstructor_key_name_or_type(reconstructor_key_name_or_type, dataset_name)[source]

Validate that a configuration exists and return both its key name and the reconstructor type.

Parameters
  • reconstructor_key_name_or_type (str or type) – Key name of configuration or reconstructor type.

  • dataset_name (str) – Standard dataset name.

Raises

ValueError – If the configuration does not exist.

Returns

  • r_key_name (str) – Key name of the configuration.

  • r_type (type) – Reconstructor type.

dival.reference_reconstructors.get_params_path(reconstructor_key_name_or_type, dataset_name)[source]

Return path of the parameters for a configuration. It can be passed to Reconstructor.load_params as a single argument to load all parameters (hyper params and learned params).

Parameters
  • reconstructor_key_name_or_type (str or type) – Key name of configuration or reconstructor type.

  • dataset_name (str) – Standard dataset name.

Returns

params_path – Parameter path.

Return type

str

dival.reference_reconstructors.get_hyper_params_path(reconstructor_key_name_or_type, dataset_name)[source]

Return path of the hyper parameters for a configuration.

Parameters
  • reconstructor_key_name_or_type (str or type) – Key name of configuration or reconstructor type.

  • dataset_name (str) – Standard dataset name.

Returns

hyper_params_path – Hyper parameter path.

Return type

str

dival.reference_reconstructors.download_params(reconstructor_key_name_or_type, dataset_name, include_learned=True)[source]

Download parameters for a configuration.

Parameters
  • reconstructor_key_name_or_type (str or type) – Key name of configuration or reconstructor type.

  • dataset_name (str) – Standard dataset name.

  • include_learned (bool, optional) – Whether to include learned parameters. Otherwise only hyper parameters are downloaded. Default: True.

Raises
  • NotImplementedError – If trying to download learned parameters that are stored in a directory (instead of as a single file).

  • ValueError – If trying to download learned parameters for a configuration that does not specify how they are stored (as a single file or in a directory).

dival.reference_reconstructors.download_hyper_params(reconstructor_key_name_or_type, dataset_name)[source]

Download hyper parameters for a configuration.

Parameters
  • reconstructor_key_name_or_type (str or type) – Key name of configuration or reconstructor type.

  • dataset_name (str) – Standard dataset name.

dival.reference_reconstructors.check_for_params(reconstructor_key_name_or_type, dataset_name, include_learned=True, return_missing=False)[source]

Return whether the parameter file(s) can be found.

Parameters
  • reconstructor_key_name_or_type (str or type) – Key name of configuration or reconstructor type.

  • dataset_name (str) – Standard dataset name.

  • include_learned (bool, optional) – Whether to check for learned parameters, too. Default: True.

  • return_missing (bool, optional) – Whether to return a list of missing files as second return value. Default: False.

Raises
  • NotImplementedError – If trying to check for learned parameters that are stored in a directory (instead of as a single file).

  • ValueError – If trying to check for learned parameters for a configuration that does not specify how they are stored (as a single file or in a directory).

Returns

  • params_exist (bool) – Whether the parameter file(s) can be found.

  • missing (list of str, optional) – List of missing files. Only returned if return_missing=True.

dival.reference_reconstructors.check_for_hyper_params(reconstructor_key_name_or_type, dataset_name)[source]

Return whether the hyper parameter file can be found.

Parameters
  • reconstructor_key_name_or_type (str or type) – Key name of configuration or reconstructor type.

  • dataset_name (str) – Standard dataset name.

Returns

params_exist – Whether the hyper parameter file can be found.

Return type

bool

dival.reference_reconstructors.get_reference_reconstructor(reconstructor_key_name_or_type, dataset_name, pretrained=True, **kwargs)[source]

Return a reference reconstructor.

Parameters
  • reconstructor_key_name_or_type (str or type) – Key name of configuration or reconstructor type.

  • dataset_name (str) – Standard dataset name.

  • pretrained (bool, optional) – Whether learned parameters should be loaded (if any). Default: True.

  • kwargs (dict) – Keyword arguments (passed to construct_reconstructor()). For CT configurations this includes the 'impl' used by odl.tomo.RayTransform.

Raises

RuntimeError – If parameter files are missing and the user chooses not to download.

Returns

reconstructor – The reference reconstructor.

Return type

Reconstructor