medigan.execute_model package

Submodules

medigan.execute_model.install_model_dependencies module

Functionality for automated installation of a model’s python package dependencies.

medigan.execute_model.install_model_dependencies.install_model(model_id: str, config_manager: Optional[medigan.config_manager.ConfigManager] = None, execution_config: Optional[dict] = None)[source]

installing the dependencies required for this model as stated in config

medigan.execute_model.install_model_dependencies.parse_args() argparse.Namespace[source]

medigan.execute_model.model_executor module

Model executor class that downloads models, loads them as python packages, and runs their generate functions.

class medigan.execute_model.model_executor.ModelExecutor(model_id: str, execution_config: dict, download_package: bool = True, install_dependencies: bool = False)[source]

Bases: object

ModelExecutor class: Find config links to download models, init models as python packages, run generate methods.

Parameters
  • model_id (str) – The generative model’s unique id

  • execution_config (dict) – The part of the config below the ‘execution’ key

  • download_package (bool) – Flag indicating, if True, that the model’s package should be downloaded instead of using an existing one that was downloaded previously

  • install_dependencies (bool) – flag indicating whether a generative model’s dependencies are automatically installed. Else error is raised if missing dependencies are detected.

model_id

The generative model’s unique id

Type

str

execution_config

The part of the config below the ‘execution’ key

Type

dict

download_package

Flag indicating, if True, that the model’s package should be downloaded instead of using an existing one that was downloaded previously

Type

bool

image_size

Pixel dimension of the generated samples, where images are assumed to have the same width and height

Type

int

dependencies

List of the dependencies of a models python package.

Type

list

model_name

Name of the generative model

Type

str

model_extension

File extension of the generative model’s weights file.

Type

str

package_name

Name of the model’s python package i.e. the name of the model’s zip file and unzipped package folder

Type

str

The link to the zipped model package. Note: Convention is to host models on Zenodo (reason: static doi content)

Type

str

generate_method_name

The name of the model’s generate method inside the model package. This method is called to generate samples.

Type

str

generate_method_args

The args of the model’s generate method inside the model package

Type

dict

serialised_model_file_path

Path as string to the generative model’s weights file

Type

str

package_path

Path as string to the generative model’s python package containing an __init__.py file

Type

str

deserialized_model_as_lib

The generative model’s package imported as python library. Generate method inside this library can be called.

generate(num_samples: int = 20, output_path: Optional[str] = None, save_images: bool = True, is_gen_function_returned: bool = False, batch_size: int = 32, **kwargs)[source]

Generate samples using the generative model or return the model’s generate function.

The name amd additional parameters of the generate function of the respective generative model are retrieved from the model’s execution_config.

Parameters
  • num_samples (int) – the number of samples that will be generated

  • output_path (str) – the path as str to the output folder where the generated samples will be stored

  • save_images (bool) – flag indicating whether generated samples are returned (i.e. as list of numpy arrays) or rather stored in file system (i.e in output_path)

  • is_gen_function_returned (bool) – flag indicating whether, instead of generating samples, the sample generation function will be returned

  • batch_size (int) – the batch size for the sample generation function

  • **kwargs – arbitrary number of keyword arguments passed to the model’s sample generation function

Returns

Returns images as list of numpy arrays if save_images is False. However, if is_gen_function_returned is True, it returns the internal generate function of the model.

Return type

list

Raises

Exception – If the generate method of the model does not exist, cannot be called, or is called with missing params, or if the sample generation inside the model package returns an exception.

is_model_already_unpacked() bool[source]

Check if a valid path to the model files exists and, if so, set the package_path

medigan.execute_model.synthetic_dataset module

SyntheticDataset allows to return a generative model as torch dataset.

class medigan.execute_model.synthetic_dataset.SyntheticDataset(samples, masks=None, other_imaging_output=None, labels=None, transform=None)[source]

Bases: torch.utils.data.dataset.Dataset

A synthetic dataset containing data generated by a model of medigan

Parameters
  • samples (list) – List of data points in the dataset e.g. generated images as numpy array.

  • masks (list) – List of segmentation masks, if applicable, pertaining to the samples items

  • other_imaging_output (list) – List of other imaging output produced by the generative model (e.g. specific types of other masks/modalities)

  • labels (list) – list of labels, if applicable, pertaining to the samples items

  • transform – torch compose transform functions that are applied to the torch dataset.

samples

List of data points in the dataset e.g. generated images as numpy array.

Type

list

masks

List of segmentation masks, if applicable, pertaining to the samples items

Type

list

other_imaging_output

List of other imaging output produced by the generative model (e.g. specific types of other masks/modalities)

Type

list

labels

list of labels, if applicable, pertaining to the samples items

Type

list

transform

torch compose transform functions that are applied to the torch dataset.

Module contents