Skip to content

Register the pretrained 2D models - #656

Open
aymuos15 wants to merge 4 commits into
ssk/2d-napari-selectionfrom
ssk/2d-model-registry
Open

aymuos15 wants to merge 4 commits into
ssk/2d-napari-selectionfrom
ssk/2d-model-registry

Conversation

@aymuos15

@aymuos15 aymuos15 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Registers the pretrained 2D classification models and resolves the default model from the processing mode. 3D behaviour is unchanged: the 3D defaults are exactly as before.

Stack: fourth of four. Builds on ssk/2d-napari-selection.

Progresses #298.

Changes

  • Adds resnet50_2d and resnet50_2d_1ch to the download registry, hosted on Hugging Face at brainglobe/cellfinder_2d_default.

  • Records each model's dimensionality and channel count, so the default model resolves from the processing mode and whether a background channel is present. This generalises the existing single-channel fallback:

    dimensions background model
    3 yes resnet50_tv
    3 no resnet50_1ch
    2 yes resnet50_2d
    2 no resnet50_2d_1ch
  • Substitution only applies when the model is still the default, so an explicit choice is never overridden.

  • A model whose dimensionality disagrees with the requested mode is now rejected up front, instead of failing later on a shape mismatch.

  • The napari model dropdown lists only models matching the selected dimensionality.

  • Tests: registry consistency, the mode/channel matrix, mismatch rejection, dropdown filtering.

CI cache key

Also rolls the brainglobe cache key, which was the literal string brainglobe. Since actions/cache never overwrites an existing key, the saved entry predated the Hugging Face hosted weights, so every job restored a cache without them, re-downloaded, and then declined to save, which was enough to hit Hugging Face rate limits across the matrix. The key now includes a hash of the model registry with a prefix restore-key, so adding a model only re-downloads the new file. This rides with this layer because it is this layer that changes the registry.

Model provenance

Trained on serial2p data with a held-out test set (n = 10,756), resnet50, 100 epochs. Both are the best-validation checkpoint of their run.

Model Channels Input shape Accuracy F1 ROC-AUC
resnet50_2d 2 (50, 50, 2) 0.974 0.973 0.995
resnet50_2d_1ch 1 (50, 50, 1) 0.964 0.963 0.992

Both are uploaded and public. Verified from a clean environment: download_models fetches each over the registered URL, pooch's hash check passes against the pinned sha256, and the loaded networks report the input shapes above with a 2-class output.

The rest of the stack

# Branch Scope
1 ssk/2d-detection 2D cell candidate detection
2 ssk/2d-training 2D training in the CLI
3 ssk/2d-napari-selection 2D/3D selector in the plugin
4 ssk/2d-model-registry pretrained 2D models

Review bottom up. Branches live in this repository rather than a fork, since GitHub stacks cannot span forks.

@aymuos15 aymuos15 changed the title ssk/2d model registry Register the pretrained 2D models Aug 14, 2026
@aymuos15
aymuos15 marked this pull request as ready for review August 14, 2026 05:19
@aymuos15
aymuos15 force-pushed the ssk/2d-model-registry branch from eb3f000 to 9e1181d Compare August 14, 2026 05:25
@aymuos15
aymuos15 force-pushed the ssk/2d-model-registry branch from 9e1181d to e2a7c20 Compare August 14, 2026 06:30
Add resnet50_2d and resnet50_2d_1ch to the download registry, hosted on
Hugging Face alongside the existing single-channel model. Record each
model's dimensionality and channel count so callers can pick the variant
matching their processing mode, and expose helpers to list the models for
a mode, resolve the default for a mode, and reject a mismatched choice.
The default model now resolves from both the processing mode and whether a
background channel is present, generalising the existing single-channel
fallback, and an explicitly chosen model whose dimensionality disagrees is
rejected with a clear error rather than failing later on a shape mismatch.
The napari training widget offers only the models matching the selected
dimensionality, and its default is named rather than positional so adding
registry entries cannot silently change it.
The cache key was the literal string `brainglobe`, and actions/cache never
overwrites an existing key. The saved entry therefore predated the
HuggingFace-hosted weights, so every job restored a cache without them,
re-downloaded from HuggingFace, and then declined to save. Across the test
matrix this was enough to hit HuggingFace rate limits.

Key on the runner OS and a hash of the model registry, with a prefix
restore-key so adding a model only re-downloads the new file. The brainmapper
job never checks out cellfinder, so add a scoped checkout for the hash to
resolve against.
Reassigning the dropdown choices already resets the value, so the explicit
fallback never ran.
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