Skip to content

feat: central class registry replaces per-class CLI flags#29

Open
torms3 wants to merge 2 commits into
feature/sr-zero-padfrom
feature/class-registry
Open

feat: central class registry replaces per-class CLI flags#29
torms3 wants to merge 2 commits into
feature/sr-zero-padfrom
feature/class-registry

Conversation

@torms3
Copy link
Copy Markdown

@torms3 torms3 commented May 14, 2026

Summary

  • New deepem/data/classes.py with a single REGISTRY: dict[str, ClassSpec] that owns per-class wiring (out_name, channels, binarize, semantic_id).
  • train/option.py and test/option.py auto-declare per-class flags from the registry; the hardcoded class_dict / semantic_mapping / requires_binarize are derived from it.
  • Adding a new detection task (e.g. 'ribo': ClassSpec(out_name='ribosome', binarize=True)) is now a one-line edit. No new argparse declarations, no new if opt.X: blocks.
  • Existing flags (--psd, --glia, --syn, …) keep their CLI shape, so seuron's argv generation needs no change.

Notable details

  • --long was double-declared (Long-range affinity section + registry); the explicit declaration is removed.
  • test/utils.py:SEMANTIC_MAPPING is derived from the registry; ARGMAX_ORDER stays hardcoded as a frozen contract with chunkflow.
  • Integer-channel test flags (--vec, --long, --aff_deprecated) and side-effect cases (--mito_to_cell, --sem) stay explicit.

Test plan

  • Registry helpers (semantic_mapping(), requires_binarize(opt)) match legacy values for sem/blv_num_channels toggles.
  • train/option.py parses --psd --glia --mit --blv --blv_num_channels 2 --aff --vec --mito_emb and produces the expected out_spec, loss_weight, class_keys, requires_binarize.
  • --sem path correctly drops glia/soma/blood_vessel from requires_binarize and passes the semantic mapping to the dataset.
  • test/option.py produces correct out_spec/in_spec for --psd --glia --blv --blv_num_channels 2 --aff --vec 12 --long 6 --mito_to_cell.
  • Demoed one-line new task: adding 'ribo': ClassSpec(out_name='ribosome', binarize=True) to REGISTRY makes --ribo 1.5 work end-to-end with zero edits to option.py.
  • Run an actual training step on a real dataset to confirm no runtime regressions.

🤖 Generated with Claude Code

torms3 and others added 2 commits May 14, 2026 15:13
Adding a new detection task no longer requires editing argparse
declarations, class_dict, semantic_mapping, or requires_binarize.
A new task is now a one-line entry in deepem/data/classes.py REGISTRY:

    'ribo': ClassSpec(out_name='ribosome', binarize=True)

The matching --ribo flag (train: float weight; test: store_true)
becomes available automatically, and downstream wiring (out_spec,
loss_weight, requires_binarize, semantic_mapping) is derived from
the registry.

Existing flags (--psd, --glia, --syn, etc.) remain unchanged, so
seuron's argv generation needs no modification.

train/option.py:
  - per-class argparse declarations replaced with a REGISTRY loop
  - hardcoded class_dict / semantic_mapping / requires_binarize
    replaced with calls into deepem.data.classes
  - --long moved out of the Long-range section (it lives in REGISTRY)

test/option.py:
  - per-class store_true declarations replaced with a REGISTRY loop
    (--vec and --long stay explicit since they are integer-valued)
  - if-chain over class flags replaced with a REGISTRY loop;
    integer-channel and side-effect cases (vec, long, aff_deprecated,
    mito_to_cell, sem) kept as explicit blocks

test/utils.py:
  - SEMANTIC_MAPPING derived from REGISTRY via semantic_mapping()
  - ARGMAX_ORDER kept hardcoded (frozen contract with chunkflow)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This name is not just an "out spec key" — it's the load-bearing identifier
used by:
  - PyTorch output submodule (and therefore state_dict / ONNX output names)
  - wandb metric name
  - loss criterion key
  - dataset key consumed by the sampler
  - LHS of zettaset_lookup

The CLI flag (the REGISTRY dict key) can differ freely from internal_name,
e.g. `apex_mit` -> `apex_mitochondria`. Renaming the field makes the
distinction explicit at the call site.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant