cellmap_flow.models.geometry
A model’s geometry: what it reads and writes, and at what voxel size.
The inference server, blockwise, the server’s model_info and the
dashboard’s geometry cache each read these numbers off ModelConfig.config
one attribute at a time, with their own conversions. ModelGeometry is
them, read once: sizes in nm as given (whole numbers as ints, so 5.24 nm
stays 5.24), and the shapes in voxels, the context and the block shape
derived from them.
from_config reads anything with the config attributes: a built config, or
the stand-ins serving.client and models.geometry_cache build from a
server’s model_info or the cache, which carry no block shape.
Importing this module is cheap: numpy and funlib.geometry only.
Attributes
Classes
What a model reads and writes. Sizes are in nm unless named |
Functions
|
The base model's geometry at the voxel sizes a finetune was trained at. |
|
|
|
|
|
The channel names a config gives, as a tuple, or None: the first |
Module Contents
- cellmap_flow.models.geometry.DEFAULT_OUTPUT_AXES = ('c', 'z', 'y', 'x')
- cellmap_flow.models.geometry.trained_at_geometry(base_cfg, input_voxel_size=None, output_voxel_size=None) dict
The base model’s geometry at the voxel sizes a finetune was trained at.
A volume made without resampling lies on the raw level nearest the model’s voxel size, and the trainer read that level as it is: the model learnt that scale, so the finetuned model really is a model at the level’s voxel size (16 nm data read as 8 nm by an 8 nm model gives a 16 nm model). Declaring it, the served model reads that level exactly, instead of the nearest one relabelled with a warning. The shapes in nm scale with the voxel size; the voxel counts are the base’s.
Returns
input_voxel_size,output_voxel_size,read_shapeandwrite_shape; each size None keeps the base’s.
- cellmap_flow.models.geometry.run_voxel_sizes(input_voxel_size, output_voxel_size, run_voxel_size) tuple
(input, output)voxel sizes of a model that readsinput_voxel_sizeand writesoutput_voxel_size, run atrun_voxel_size: that, and the output scaled per axis as the input is (a 16 nm model writing 8 nm voxels, run at 32 nm, writes 16 nm ones).
- cellmap_flow.models.geometry.run_at_geometry(config, run_voxel_size) dict
config’s geometry when the model is run atrun_voxel_size(nm, z, y, x) instead of its own input voxel size:trained_at_geometryatrun_voxel_sizes, so the voxel counts are the model’s own and the shapes in nm scale with the voxel sizes.ModelConfig.run_voxel_size.
- cellmap_flow.models.geometry.channel_names_of(config)
The channel names a config gives, as a tuple, or None: the first non-empty one of channels, channels_names (Hugging Face), classes, or a ModelGeometry’s channel_names. A string is one name, so
channels = "mito"is("mito",).
- class cellmap_flow.models.geometry.ModelGeometry
What a model reads and writes. Sizes are in nm unless named
*_shapein voxels.- input_voxel_size: Tuple[float, ...]
- output_voxel_size: Tuple[float, ...]
- read_shape: Tuple[float, ...]
- write_shape: Tuple[float, ...]
- output_channels: int
- channel_names: Tuple[str, ...] | None = None
- chunk_output_axes: Tuple[str, ...] = ('c', 'z', 'y', 'x')
- output_dtype: numpy.dtype | None = None
- input_channels: int = 1
- declared_block_shape: Tuple[int, ...] | None = None
- property ndim: int
Spatial dimensions.
- property input_shape: Tuple[int, ...]
Voxels the model reads.
- property output_shape: Tuple[int, ...]
Voxels the model writes.
- property context: funlib.geometry.Coordinate
nm read beyond the written region on each side.
funlib arithmetic, as the Inferencer and blockwise always computed it: Coordinate truncates each size to an int, and
/floors.
- property has_channel_axis: bool
Whether a chunk the model outputs has a channel axis.
- classmethod from_config(config, chunk_output_axes=None, output_dtype=None) ModelGeometry
From
ModelConfig.config, or anything with its geometry attributes.chunk_output_axesandoutput_dtype, when given, win over the config’s own (ModelConfigpasses its properties, with their defaults); otherwise the config’s are used, if it has them.
- to_model_info(spatial_axes=None, actual_input_voxel_size=None) dict
The geometry keys of the server’s
/__control__/model_info.spatial_axes: the served array’s, which are the raw data’s (the spatial axes of chunk_output_axes by default).output_axesis them in order, then “c” when the output has a channel axis.actual_input_voxel_size: what the input really is. When it is not input_voxel_size, the data was read at another level as if it were at input_voxel_size, voxel for voxel, so an output voxel really isactual_in * output_voxel_size / input_voxel_size: that iseffective_output_voxel_size, otherwise output_voxel_size. The served .zattrs still say output_voxel_size.