cellmap_flow.models.configs.cellmap

CellMapModelConfig: a model that cellmap_models exported, from its folder.

The folder’s metadata gives the shapes, voxel sizes and channel names; the model is its TorchScript export.

Attributes

logger

Classes

CellMapModelConfig

Configuration class for a CellmapModel.

Functions

runs_at(model, input_shape, output_shape) → bool

Whether the TorchScript model runs on an input of input_shape

export_finetune_modes(file_names) → tuple

How a cellmap_models export whose top-level files are file_names

declared_offsets(value)

affinity_offsets as an export's metadata declares them: one

declared_ids(value)

class_ids as an export's metadata declares them: the id each class

integer_output_refusal(name, output_dtype)

Why a model whose export declares output_dtype cannot be

metadata_geometry(metadata)

ModelConfig.declared_geometry from an export's metadata (metadata

Module Contents

cellmap_flow.models.configs.cellmap.logger
cellmap_flow.models.configs.cellmap.runs_at(model, input_shape, output_shape) → bool

Whether the TorchScript model runs on an input of input_shape voxels and answers output_shape.

cellmap_models traces the export (torch.jit.trace) at whichever shape the exporter passed, and a traced UNet’s crops are baked in, so it runs only at that shape: fed another, it either fails (jrc_mus-livers_16nm_to_8nm_mito, traced at its inference 288³, fails at its training 216³ with “padded input size (1 x 1 x 1)”) or answers the baked-in output (mito_aff_unet_setup_16, traced at its training 178³ → 56³, answers 56³ to a 378³ input). The metadata records both shapes and not which one the export was traced at, so this asks the model.

cellmap_flow.models.configs.cellmap.export_finetune_modes(file_names) → tuple

How a cellmap_models export whose top-level files are file_names can be finetuned, from their names alone: LoRA and full with a model.pt2, which cellmap_models’ train() unflattens into a module adapters attach to; full only without one, as train() then hands the trainer the TorchScript, a compiled network that takes no adapter.

The one rule for an export’s folder (CellMapModelConfig.finetune_modes), its Hugging Face repository (HuggingFaceModelConfig’s) and the model lists’ facts (hf_catalog.weight_facts). fly_organelles’ copies under /nrs/cellmap/models/saalfeldlab (model.pt and model.ts; their Hugging Face copies have a model.pt2) and cellmap/jrc_mus-livers_16nm_to_8nm_mito (model.pt, model.ts and model.onnx) have none: offered LoRA, their jobs failed at their start.

cellmap_flow.models.configs.cellmap.declared_offsets(value)

affinity_offsets as an export’s metadata declares them: one [dz, dy, dx] of whole voxels per affinity channel, in channel order, as lists of ints; None when value is not that (absent, empty, or not three whole numbers each: an OverflowError is a metadata.json’s Infinity).

cellmap_flow.models.configs.cellmap.declared_ids(value)

class_ids as an export’s metadata declares them: the id each class channel has in CellMap’s annotations, in channel order, as a list of ints; None when value is not that (absent, empty, or not whole numbers an ArgmaxPostprocessor takes as ids, 0 to uint32’s largest: an OverflowError is a metadata.json’s Infinity).

cellmap_flow.models.configs.cellmap.integer_output_refusal(name, output_dtype)

Why a model whose export declares output_dtype cannot be finetuned, or None when it can: an integer output (a probability x 255, rounded) passes no gradient back to the network. The finetune_refusal of an export’s folder and of its Hugging Face repository.

cellmap_flow.models.configs.cellmap.metadata_geometry(metadata)

ModelConfig.declared_geometry from an export’s metadata (metadata has its fields as attributes): its training output, when the metadata gives no other shape (_other_shapes), so that it is the one the export runs at; else None, as when a field is missing. setup_16’s metadata gives inference shapes too, and its export runs at the training ones; jrc_mus-livers_16nm_to_8nm_mito’s runs at its inference ones.

class cellmap_flow.models.configs.cellmap.CellMapModelConfig(folder_path, name=None, scale=None)

Configuration class for a CellmapModel.

cli_name = 'cellmap'
finetunable = True
cellmap_model
name = None
scale = None
classmethod from_metadata(metadata, name, scale=None) → CellMapModelConfig

The config of an export not made yet, from the metadata it will have (metadata: cellmap_models’ ModelMetadata, as it will be written into its metadata.json). It answers what the export declares (declared_geometry, declared_input_norm, declared_affinity_offsets, finetune_refusal, finetune_modes, runs_at_native_voxel_size) from that metadata, by the code an export’s folder is answered by, and has no model to serve. A mia model’s before its server converts it (configs/mia.py).

finetune_modes()

export_finetune_modes of its folder’s files, read from their names without loading them: the model list asks on every poll. Both while the folder cannot be listed; none when its output cannot be trained through (finetune_refusal).

declared_geometry()

Its export’s metadata.json’s (metadata_geometry), read without the model; None while cellmap_models cannot parse that file (_parsed_metadata), as the model cannot be built then either.

declared_input_norm(data_range=None)

Its export’s metadata.json’s input_normalization (metadata_input_norm). cellmap_models’ parsed metadata leaves that field out, so the file is read for it, once (_written_metadata).

finetune_refusal()

integer_output_refusal of its export’s output_dtype.

declared_affinity_offsets()

The offsets its export’s metadata declares (affinity_offsets, declared_offsets), read without the model; None without them.

declared_class_ids()

The ids its export’s metadata declares its class channels have (class_ids, declared_ids), read without the model; None without them.

declared_overlap()

The overlap its export’s metadata.json declares, read without the model; None without one.

declared_postprocess()

The step its export’s metadata.json declares is applied after the model (its inference_output_activation, as written: portable/rank.py declared_postprocess), read without the model.

runs_at_native_voxel_size() → bool

Whether its export’s metadata says it runs at the data’s own voxel size (native_voxel_size), its input_voxel_size being a default only.

to_dict()

This config as a model entry, which registry.build_model rebuilds.