ModelContributor
- class medigan.contribute_model.model_contributor.ModelContributor(model_id: str, init_py_path: str)[source]
Bases:
object
ModelContributor class: Contributes a user’s local model to the public medigan library
- Parameters
model_id (str) – The generative model’s unique id
init_py_path (str) – The path to the local model’s __init__.py file needed for importing and running this model.
- model_id
The generative model’s unique id
- Type
str
- init_py_path
The path to the local model’s __init__.py file needed for importing and running this model.
- Type
str
- package_path
Path as string to the generative model’s python package
- 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
- metadata_file_path
Path as string to the generative model’s metadata file e.g. default is relative path to package root.
- Type
str
- zenodo_model_uploader
An instance of the ZenodoModelUploader class
- Type
str
- github_model_uploader
An instance of the GithubModelUploader class.
- Type
str
Methods Summary
add_metadata_from_file
(metadata_file_path)Read and parse the metadata of a local model, identified by model_id, from a metadata file in json format.
add_metadata_from_input
([...])Create a metadata dict for a local model, identified by model_id, given the necessary minimum metadata contents.
is_value_for_key_already_set
(key, metadata, ...)Check if the value of a key in a metadata dictionary is already set and e.g.
Loads and parses (json to dict) a default medigan metadata template.
push_to_github
(access_token[, package_link, ...])Upload the model's metadata inside a github issue to the medigan github repository.
push_to_zenodo
(access_token, creator_name, ...)Upload the model files as zip archive to a public Zenodo repository where the model will be persistently stored.
Check if the model files can be found in the package_path or based on the path_to_metadata.
validate_init_py_path
(init_py_path)Asserts whether the init_py_path exists and points to a valid __init__.py correct file.
Check if the model package in the package_path can be imported as python library using importlib.
validate_model_id
(model_id[, max_chars, ...])Asserts if the model_id is in the correct format and has a valid length
Methods Documentation
- add_metadata_from_file(metadata_file_path) dict [source]
Read and parse the metadata of a local model, identified by model_id, from a metadata file in json format.
- Parameters
model_id (str) – The generative model’s unique id
metadata_file_path (str) – the path pointing to the metadata file
- Returns
Returns a dict containing the contents of parsed metadata json file.
- Return type
dict
- add_metadata_from_input(model_weights_name: Optional[str] = None, model_weights_extension: Optional[str] = None, generate_method_name: Optional[str] = None, dependencies: list = [], fill_more_fields_interactively: bool = True, output_path: str = 'config')[source]
Create a metadata dict for a local model, identified by model_id, given the necessary minimum metadata contents.
- Parameters
model_id (str) – The generative model’s unique id
model_weights_name (str) – the name of the checkpoint file containing the model’s weights
model_weights_extension (str) – the extension (e.g. .pt) of the checkpoint file containing the model’s weights
generate_method_name (str) – the name of the sample generation method inside the models __init__.py file
dependencies (list) – the list of dependencies that need to be installed via pip to run the model.
fill_more_fields_interactively (bool) – flag indicating whether a user will be interactively asked via command line for further input to fill out missing metadata content
output_path (str) – the path where the created metadata json file will be stored.
- Returns
Returns a dict containing the contents of the metadata json file.
- Return type
dict
- is_value_for_key_already_set(key: str, metadata: dict, nested_key) bool [source]
Check if the value of a key in a metadata dictionary is already set and e.g. not an empty string, dict or list.
- Parameters
key (str) – The key in the currently traversed part of the model’s metadata dictionary
metadata (dict) – The currently traversed part of the model’s metadata dictionary
nested_key (str) – the nested_key indicates which subpart of the model’s metadata we are currently traversing
- Returns
Flag indicating whether a value exists for the key in the dict
- Return type
bool
- load_metadata_template() dict [source]
Loads and parses (json to dict) a default medigan metadata template.
- Returns
Returns the metadata template as dict
- Return type
dict
- push_to_github(access_token: str, package_link: Optional[str] = None, creator_name: str = '', creator_affiliation: str = '', model_description: str = '')[source]
Upload the model’s metadata inside a github issue to the medigan github repository.
To add your model to medigan, your metadata will be reviewed on Github and added to medigan’s official model metadata
The medigan repository issues page: https://github.com/RichardObi/medigan/issues
Get your Github access token here: https://github.com/settings/tokens
- Parameters
access_token (str) – a personal access token linked to your github user account, used as means of authentication
package_link – a package link
creator_name (str) – the creator name that will appear on the corresponding github issue
creator_affiliation (str) – the creator affiliation that will appear on the corresponding github issue
model_description (list) – the model_description that will appear on the corresponding github issue
- Returns
Returns the url pointing to the corresponding issue on github
- Return type
str
- push_to_zenodo(access_token: str, creator_name: str, creator_affiliation: str, model_description: str = '')[source]
Upload the model files as zip archive to a public Zenodo repository where the model will be persistently stored.
Get your Zenodo access token here: https://zenodo.org/account/settings/applications/tokens/new/ (Enable scopes deposit:actions and deposit:write)
- Parameters
access_token (str) – a personal access token in Zenodo linked to a user account for authentication
creator_name (str) – the creator name that will appear on the corresponding Zenodo model upload homepage
creator_affiliation (str) – the creator affiliation that will appear on the corresponding Zenodo model upload homepage
model_description (list) – the model_description that will appear on the corresponding Zenodo model upload homepage
- Returns
Returns the url pointing to the corresponding Zenodo model upload homepage
- Return type
str
- validate_and_update_model_weights_path() dict [source]
Check if the model files can be found in the package_path or based on the path_to_metadata.
Ideally, the user provided package_path and the path_to_metadata should both point to the same model package containing weights, config, license, etc. Here we check both of these paths to find the model weights.
- Returns
Returns the metadata after updating the path to the model’s checkpoint’s weights
- Return type
dict
- validate_init_py_path(init_py_path) bool [source]
Asserts whether the init_py_path exists and points to a valid __init__.py correct file.
- Parameters
init_py_path (str) – The path to the local model’s __init__.py file needed for importing and running this model.
- validate_local_model_import()[source]
Check if the model package in the package_path can be imported as python library using importlib.
- validate_model_id(model_id: str, max_chars: int = 30, min_chars: int = 13) bool [source]
Asserts if the model_id is in the correct format and has a valid length
- Parameters
model_id (str) – The generative model’s unique id
max_chars (int) – the maximum of chars allowed in the model_id
min_chars (int) – the minimum of chars allowed in the model_id
- Returns
Returns flag indicating whether the model_id is correctly formatted.
- Return type
bool