cellmap_flow.finetune.crop_loader
YAML manifest schema and helpers for importing externally annotated crops.
Each manifest entry points at a 3D zarr (typically OME-NGFF) of instance
labels or class IDs. The dashboard’s YAML loader (see
cellmap_flow.dashboard.routes.finetune.yaml_crops) reads these crops,
remaps their values into the trainer’s
0 = unannotated, 1 = background, >=2 = foreground instance convention,
and writes them into the session’s annotation_volume.zarr at the crops’
physical offsets.
- This module owns:
The pydantic schema (
CropEntry,CropsConfig).The label remap function (
remap_labels()).Small zarr-attrs helpers used by the loader to derive a crop’s voxel size, offset, and the array sub-path inside an OME-NGFF group.
Attributes
Classes
One annotation crop to import. |
|
Top-level YAML schema. |
Functions
|
Parse a YAML string OR the path to a YAML file into a validated config. |
|
Map source label values to |
Module Contents
- cellmap_flow.finetune.crop_loader.logger
- class cellmap_flow.finetune.crop_loader.CropEntry(/, **data: Any)
One annotation crop to import.
- Fields other than
pathare optional with sensible defaults: fg_ids=Nonemeans “every nonzero source value is foreground”bg_ids=[]means “no explicit BG ids, see mode for what 0 means”mode='dense'treats unmatched voxels (incl. 0) as backgroundmode='sparse'treats unmatched voxels as unannotatedconnected_components=Falsekeeps source ids as instance ids; set True with a single-idfg_idsto split same-id blobs into per-instance ids for affinity-style training.
- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- path: str
- name: str | None = None
- fg_ids: List[int] | None = None
- bg_ids: List[int] = None
- mode: Literal['dense', 'sparse'] = 'dense'
- connected_components: bool = False
- Fields other than
- class cellmap_flow.finetune.crop_loader.CropsConfig(/, **data: Any)
Top-level YAML schema.
patches_per_epoch,jitter_voxels, andseedare passed through to theVirtualPatchDatasetmanifest the loader writes — they govern epoch length, patch-center jitter (in voxels), and the per-worker RNG base seed for reproducible patch sampling across runs.patches_per_epoch=None(the default) means “cover every populated chunk roughly once per epoch” — the dataset substitutes the total populated-chunk count at index build time. Override with an explicit int to cap the epoch length.dense_to_sparse_ratio=None(the default) means “auto-balance”: 50/50 split between dense imported crops and sparse painted scribbles when both pools exist; degrades to 1.0 (all from the surviving pool) when only one pool has FG voxels.- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- patches_per_epoch: int | None = None
- jitter_voxels: List[int] | None = None
- seed: int = 0
- dense_to_sparse_ratio: float | None = None
- cellmap_flow.finetune.crop_loader.parse_crops_yaml(yaml_text_or_path: str) CropsConfig
Parse a YAML string OR the path to a YAML file into a validated config.
- cellmap_flow.finetune.crop_loader.remap_labels(source: numpy.ndarray, fg_ids: Iterable[int] | None, bg_ids: Iterable[int], mode: Literal['dense', 'sparse'], connected_components: bool) numpy.ndarray
Map source label values to
0=unannotated, 1=BG, >=2=FG instance.- Mapping rules:
source value in
fg_ids(or any nonzero iffg_ids is None) becomes a unique instance id >=2. Ifconnected_componentsis True, each connected blob within an fg_id class gets its own instance. Otherwise, source ids map to consecutive 2,3,… in order.source value in
bg_ids-> 1 (background).everything else -> 1 if
mode='dense', else 0 (unannotated).
Returns
uint8. If the number of distinct instances would overflowuint8, all FG voxels collapse to id=2 and a warning is emitted.