cellmap_flow.models.configs.base
ModelConfig, the base of every model type, and the helpers the types share.
A model type is a ModelConfig subclass. The CLIs, YAML type: entries
and the dashboard’s model form are built from its constructor’s signature,
and its _get_config builds the model and returns a Config that
describes it. What the rest of cellmap-flow reads:
config: that Config, built on first use and checked: the required attributes, then the declared shapes against a forward pass, unlessvalidate_model_shapesis off orcheck_shapes_on_warmupleaves it to a ModelRunner’s warmup forward, which callscheck_output_shape.geometry: the Config’s shapes and voxel sizes, as aModelGeometry.chunk_output_axes,output_dtype: what a processed chunk is.to_dict(): the model entryregistry.build_modelrebuilds it from.launch_entry: the entry a launched server rebuilds it from (cellmap_flow serve --model <it, as JSON>).command: thecellmap_flow_server <type>arguments that rebuild it, which launchers passed before 0.3.0; that form of the server goes in the release after it.env: the environment its entry names for its server, when not this one (models.envs). Set after construction, never a constructor argument; to_dict() and launch_entry carry it.default_env: the environment a type’s models run in when their entry names none;effective_env: the one a model runs in, of the two.
Attributes
Exceptions
A model that runs in its own environment was built in another, which |
Classes
What a model type's |
|
Functions
|
The model entry |
|
|
Module Contents
- cellmap_flow.models.configs.base.logger
- cellmap_flow.models.configs.base.model_entry(cls, params: dict) dict
The model entry
cellmap_flow serve --modelbuildscls(**params)from.{"type": <the name the registry has cls under>, **params}, leaving out None. The server rebuilds it withregistry.build_model, as a YAML’s entry is rebuilt, soparamsmay be to_dict()’s, extra keys and all.
- cellmap_flow.models.configs.base.command_argv(cls, params: dict) list
cellmap_flow_serverarguments that buildcls(**params).The name the server CLI registers
clsunder, then--arg valuefor each constructor argument in signature order, leaving out None. Each value is written the way the server CLI parses it back.
- exception cellmap_flow.models.configs.base.ModelEnvError
A model that runs in its own environment was built in another, which lacks its packages (
ModelConfig.config).
- cellmap_flow.models.configs.base.DEFAULT_AXES_NAMES = ['x', 'y', 'z']
- class cellmap_flow.models.configs.base.Config(**kwargs)
What a model type’s
_get_configreturns: the model, its geometry and anything else its script or checkpoint defines, as attributes.Built from keyword arguments (a script’s globals, for a script model), which
to_dict()andget()read back.axes_namesdefaults to x, y, z.- axes_names
- kwargs
- to_dict()
Returns the configuration as a dictionary.
- get(key: str, default: Any = None) Any
Gets the value of a configuration key.
- class cellmap_flow.models.configs.base.ModelConfig
- env = None
- default_env = None
- display_channel = None
- finetunable = False
- finetune_modes()
What this model can be finetuned with: (“lora”, “full”), (“full”,) or (). For the dashboard, so it must not build the network: a type whose networks differ (a compiled one takes no LoRA adapter) reads it from what describes the model. The trainer checks the module it gets the same way (
finetune.trainable.finetune_modes).
- trainable_model()
The torch module the finetune trainer trains, or None for
config.modelas it is (finetune.model_loading.load_trainable_model).The trainer feeds it a float tensor (B, 1, Z, Y, X), normalized as the dashboard’s input normalization does, at the input voxel size and read shape, and wants (B, C, Z’, Y’, X’) at the write shape back. A type whose
config.modelis not such a module (a bioimage.io prediction pipeline, a Cellpose model object) returns one that is, sharing its parameters, so that what is trained is what is served.
- serve_trained(config, module)
Make
configservemodule, the trainedtrainable_model().configis this model’s own Config (the trainer’s live server) or a new one with its geometry (a finetuned model’s,FinetuneModelConfig). By default the module is the model, run by the inferencer’s own forward; a type that predicts through its ownprocess_chunksets that up here instead.
- validate_model_shapes = True
- check_shapes_on_warmup = False
- property effective_env
The environment this model’s server and finetuning job run in, or None for this one:
env, elsedefault_env(envs.effective).
- property config
- check_output_shape(output_shape)
Raise ValueError if a forward’s
output_shape(batch first) contradicts the declared write_shape, block_shape or output_channels.
- property geometry: cellmap_flow.models.geometry.ModelGeometry
The config’s geometry as one ModelGeometry, read once per built config.
- property chunk_output_axes: tuple[str, ...]
The axes of a processed chunk; by default
geometry.DEFAULT_OUTPUT_AXES, (“c”, “z”, “y”, “x”).Models can override by setting config.chunk_output_axes. The server and blockwise read it only for whether a chunk has a channel axis: one that has must have it first, and its spatial axes are the raw data’s, in the raw data’s order.
- property output_dtype
Returns the output dtype of the model. Defaults to np.float32.
- to_dict()
This config as a model entry, which
registry.build_modelrebuilds.{"type": <registered name>, **the constructor arguments given}, leaving out None as the built-in types leave out an unset name or scale. The built-in types write their own; this one serves a plugin type that does not, so exporting its config and launching its server work without one.
- property launch_entry: dict
The model entry a launched server rebuilds this exact config from.
to_dict(), less what only the pipeline builder shows (a Hugging Face repo’s downloaded metadata), under the name the registry has this class under (
registry.cli_name_of), so that the server rebuilds this class and not a parent it inherited cli_name from. With the entry’s ownenv, if it has one, whichserving.launchtakes off again; the server’s environment iseffective_env, which it reads from the config.
- property command: str
cellmap_flow_serverarguments that rebuild this exact config.Generated from to_dict() so no constructor argument is left behind (hand-written commands dropped Fly’s input/output size, which then silently fell back to 178/56, and Bio’s required voxel size), with every token shell-quoted: bsub runs it through
bash -cand local launches throughshlex.split. The class is named as the server CLI registers it (registry.cli_name_of), so it rebuilds this class and not a parent it inherited cli_name from.