cellmap_flow.models.registry
The model types cellmap-flow knows, and how a model config is built from strings.
Every ModelConfig subclass is a model type: the built-in ones in
models/configs (imported from models_config) and any that a plugin
defines. The model CLIs
(cellmap_flow infer, cellmap_flow serve, cellmap_flow yaml), YAML
configs, the dashboard’s model form and the finetune CLI’s model entries
all look types up here, so a plugin type is a type everywhere.
Nothing is cached. Plugins are loaded when cellmap_flow is imported, and
a plugin or a test can define a type at any time, so each call walks the
subclasses as they are at that moment.
Strings become constructor arguments in three ways, kept apart on purpose because each reproduces what its caller has always done:
coerce_cli_args: click’s strings."8,8,8"for a tuple becomes(8, 8, 8), ints.coerce_form_params: the dashboard form’s strings. JSON, or"8,8,8"becomes(8.0, 8.0, 8.0), floats;instantiate_model_configbuilds the form’s model with them.build_model: YAML values, afterYAML_ALIASESand the voxel-size shorthands, thencoerce_cli_args;build_modelsfor a YAML’s wholemodels.
A bad YAML entry or type name is a config.yaml.ConfigError.
A model entry’s env (the environment its server runs in, see
models.envs) is not a constructor argument: build_model and
instantiate_model_config check it and set it on the built config, and
the dashboard’s form offers it beside each type’s arguments. Left out, the
type’s default_env applies (ModelConfig.effective_env).
Importing this module imports neither torch, flask, huggingface_hub nor
cellmap_flow.globals. The model config classes, which bring numpy and
funlib (most of a second), are imported only when a function needs them.
describe_types reads constructor signatures only, so it never imports
bioimageio, dacapo or cellmap_models either.
Attributes
Functions
|
The name |
|
Every model type, by the name the CLIs and YAML |
|
The class registered as |
|
Every model type by class name ( |
|
The constructor arguments a user must give: no default, and not name or scale. |
|
A model config from a YAML model entry; |
|
The model configs for a YAML's |
|
|
|
The |
|
Print every model type and its constructor arguments, for |
|
The model form's values, as constructor arguments for |
|
The model config the dashboard's model form describes. |
|
Each constructor argument of |
|
What the dashboard's model form offers, by class name. |
Module Contents
- cellmap_flow.models.registry.logger
- cellmap_flow.models.registry.YAML_ALIASES
- cellmap_flow.models.registry.ENV_KEY = 'env'
- cellmap_flow.models.registry.cli_name_of(cls: type) str
The name
clsis registered under: its owncli_name, else one from its class name.Only a
cli_namethe class sets itself counts. A plugin’sclass MyScript(ScriptModelConfig)inheritscli_name = "script"; taking that as its name would either replace the script type or lose the name clash and leave MyScript without a type, and itscommandwould ask the server for a plain ScriptModelConfig. It is “myscript”.
- cellmap_flow.models.registry.model_types() Dict[str, type]
Every model type, by the name the CLIs and YAML
type:use.Plugins included, subclasses of subclasses too. When two classes claim a name the first one found keeps it, and the other is left out with a warning.
- cellmap_flow.models.registry.model_type(name: str) type
The class registered as
name, matched as a YAMLtype:is.- Raises:
ConfigError – no type has that name; the message lists the valid ones.
- cellmap_flow.models.registry.model_classes() Dict[str, type]
Every model type by class name (
"ScriptModelConfig"), plugins included.
- cellmap_flow.models.registry.required_params(cls) List[str]
The constructor arguments a user must give: no default, and not name or scale.
- cellmap_flow.models.registry.build_model(entry: Dict[str, Any], name: str)
A model config from a YAML model entry;
nameis its key in the YAML.- Raises:
ConfigError – the entry does not describe a model that can be built.
- cellmap_flow.models.registry.build_models(model_entries) list
The model configs for a YAML’s
models:build_modelfor each entry.model_entriesmaps each model’s name to its entry, or is a list of entries that each have aname:models: my_model_1: type: cellmap checkpoint_path: /path/to/checkpoint my_model_2: type: dacapo run_name: my_run iteration: 50000
- Raises:
ConfigError – an entry does not describe a model that can be built.
- cellmap_flow.models.registry.coerce_cli_args(cls, kwargs: Dict[str, Any]) Dict[str, Any]
kwargsfrom the command line, as constructor arguments forcls.Only list and tuple arguments given as strings are converted (from comma-separated values); None values and names
clsdoes not take are dropped, and everything else is passed through as it is.
- cellmap_flow.models.registry.click_options(cls, reserved_short) List[dict]
The
click.optionarguments for each ofcls’s constructor arguments.In signature order, which is also the order short flags are handed out in: an argument gets its first letter unless an earlier argument has it already (
script -sis--script-path, and--scalehas no short flag).reserved_shortholds the command’s own short flags (-dand so on), which no argument gets.
- cellmap_flow.models.registry.print_available_models(cli_command_name: str = 'cellmap_flow')
Print every model type and its constructor arguments, for
list-models.cli_command_nameis the command the closing hint names.
- cellmap_flow.models.registry.coerce_form_params(cls, params: Dict[str, Any]) Dict[str, Any]
The model form’s values, as constructor arguments for
cls.- Raises:
ValueError – a required argument is missing or empty.
- cellmap_flow.models.registry.instantiate_model_config(class_name: str, params: Dict[str, Any]) Any
The model config the dashboard’s model form describes.
class_nameis a model type’s class name ("ScriptModelConfig"), plugins’ included, andparamsthe form’s values (coerce_form_params).- Raises:
ValueError – the class is unknown, or the values do not build one.
- cellmap_flow.models.registry.parameter_info(cls) Dict[str, Any]
Each constructor argument of
cls: name, required, description, type and default.
- cellmap_flow.models.registry.describe_types(classes=None) Dict[str, Dict[str, Any]]
What the dashboard’s model form offers, by class name.
classes(class name -> class) defaults tomodel_classes().