cellposesam: default to cpsam_v2 checkpoint, keep legacy cpsam#149
Merged
Conversation
Cellpose 4.2.x ships a new Cellpose-SAM checkpoint, cpsam_v2 (SAM-ViTL,
June 2026), which reduces spurious masks in low-contrast regions vs the
original April 2025 cpsam. Make it the default while keeping the old
model selectable for reproducibility.
- environment.yml: cellpose 4.0.1 -> 4.2.1.1 (cpsam_v2 lands in 4.2.x)
- models_config.py: new import-free single source of truth mapping
dropdown labels -> checkpoints ('cellpose-sam' -> cpsam_v2,
'cellpose-sam (legacy cpsam)' -> cpsam). Unit-tested in the local venv.
- entrypoint.py: pass pretrained_model explicitly for base models so
behavior is pinned to the selection, not cellpose's internal default
(which can shift between versions). Default stays the string
'cellpose-sam', so saved tool configs keep working (now -> cpsam_v2).
- download_models.py: pre-download both checkpoints at build time.
- Dockerfile: copy models_config.py before the download step.
- CELLPOSESAM.md: document the new default, legacy option, and version.
Verified locally: 4/4 mapping unit tests pass; all worker .py files
compile. The CUDA build + GPU inference smoke test must be run on an
amd64/GPU host (cannot run in this environment).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xrXEVpvb4c4ScEVjN1VsM
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Follow-up to the code review on this branch. - models_config.build_model_items(): new pure helper that merges the built-in labels with custom Girder model names and drops any custom name that collides with a reserved base label (compute() routes those to the built-in checkpoint, so a same-named custom model could never load). Wired into interface() in place of the inline sorted(set(...)) merge. Unit-tested (4 new cases). - CLAUDE.md: reconcile the contradictory worker-doc guidance — the "do not edit manually" bullet now matches the rest of the doc (docs are hand-maintained; the generator only stubs missing docs; the auto-doc hook is disabled; avoid --force). This is what made the CELLPOSESAM.md edit on this branch correct. The other review findings were intentional (cpsam_v2 default, ~1.2GB image growth from baking in both checkpoints) or justified (mapping pattern differs from sibling cellpose workers because label != checkpoint here), so no change. Verified: 8/8 mapping unit tests pass; worker .py files compile. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015xrXEVpvb4c4ScEVjN1VsM
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
Cellpose 4.2.x ships a new Cellpose-SAM checkpoint, cpsam_v2 (SAM-ViTL backbone, June 2026), which reduces spurious masks in low-contrast regions compared to the original April 2025 cpsam. This PR makes cpsam_v2 the default for the cellposesam worker while keeping the original model selectable for reproducibility.
Verified against authoritative sources before implementing: cpsam_v2 is a real built-in checkpoint (cellpose docs, HuggingFace), loaded via
CellposeModel(pretrained_model='cpsam_v2'), andcellpose==4.2.1.1is the latest PyPI release (cpsam_v2 landed in the 4.2.x line).Changes
environment.ymlcellpose==4.0.1→4.2.1.1models_config.py(new)cellpose-sam→cpsam_v2,cellpose-sam (legacy cpsam)→cpsam)entrypoint.pypretrained_modelexplicitly (pins behavior to the selection instead of cellpose's internal default, which can shift between versions). Default stays the string'cellpose-sam', so existing saved tool configs keep working (now resolving to cpsam_v2)download_models.pyDockerfilemodels_config.pybefore the download stepCELLPOSESAM.mdtests/test_models_config.py(new)Backward compatibility
The default dropdown value is unchanged (
'cellpose-sam'); it now resolves to cpsam_v2 under the hood. Saved tool configurations that reference'cellpose-sam'continue to work. The original cpsam remains available as'cellpose-sam (legacy cpsam)'.Testing
4/4mapping unit tests pass locally; all worker.pyfiles compile.arjunrajlaboratory/DeepTilefork'scellpose_segmentationis compatible with cellpose 4.2.1.1 (last used with 4.0.1; its API surface —CellposeModel(**model_parameters).eval(...)— is stable, so risk is low).Build command for validation:
docker build . -f ./workers/annotations/cellposesam/Dockerfile -t annotations/cellposesam_worker:latest🤖 Generated with Claude Code
https://claude.ai/code/session_015xrXEVpvb4c4ScEVjN1VsM