feat: central class registry replaces per-class CLI flags#29
Open
torms3 wants to merge 2 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deepem/data/classes.pywith a singleREGISTRY: dict[str, ClassSpec]that owns per-class wiring (out_name, channels, binarize, semantic_id).train/option.pyandtest/option.pyauto-declare per-class flags from the registry; the hardcodedclass_dict/semantic_mapping/requires_binarizeare derived from it.'ribo': ClassSpec(out_name='ribosome', binarize=True)) is now a one-line edit. No new argparse declarations, no newif opt.X:blocks.--psd,--glia,--syn, …) keep their CLI shape, so seuron's argv generation needs no change.Notable details
--longwas double-declared (Long-range affinity section + registry); the explicit declaration is removed.test/utils.py:SEMANTIC_MAPPINGis derived from the registry;ARGMAX_ORDERstays hardcoded as a frozen contract with chunkflow.--vec,--long,--aff_deprecated) and side-effect cases (--mito_to_cell,--sem) stay explicit.Test plan
semantic_mapping(),requires_binarize(opt)) match legacy values forsem/blv_num_channelstoggles.train/option.pyparses--psd --glia --mit --blv --blv_num_channels 2 --aff --vec --mito_emband produces the expectedout_spec,loss_weight,class_keys,requires_binarize.--sempath correctly dropsglia/soma/blood_vesselfromrequires_binarizeand passes the semantic mapping to the dataset.test/option.pyproduces correctout_spec/in_specfor--psd --glia --blv --blv_num_channels 2 --aff --vec 12 --long 6 --mito_to_cell.'ribo': ClassSpec(out_name='ribosome', binarize=True)toREGISTRYmakes--ribo 1.5work end-to-end with zero edits to option.py.🤖 Generated with Claude Code