Skip to content

cellposesam: default to cpsam_v2 checkpoint, keep legacy cpsam#149

Merged
arjunrajlab merged 2 commits into
masterfrom
claude/cellposesam-cpsam-v2
Jul 1, 2026
Merged

cellposesam: default to cpsam_v2 checkpoint, keep legacy cpsam#149
arjunrajlab merged 2 commits into
masterfrom
claude/cellposesam-cpsam-v2

Conversation

@arjunrajlab

Copy link
Copy Markdown
Collaborator

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'), and cellpose==4.2.1.1 is the latest PyPI release (cpsam_v2 landed in the 4.2.x line).

Changes

File Change
environment.yml cellpose==4.0.14.2.1.1
models_config.py (new) Import-free single source of truth mapping dropdown labels → checkpoints (cellpose-samcpsam_v2, cellpose-sam (legacy cpsam)cpsam)
entrypoint.py Base models pass pretrained_model explicitly (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.py Pre-downloads both checkpoints at build time
Dockerfile Copies models_config.py before the download step
CELLPOSESAM.md Documents the new default, legacy option, and version bump
tests/test_models_config.py (new) 4 unit tests for the label→checkpoint mapping

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/4 mapping unit tests pass locally; all worker .py files compile.
  • Not yet validated: the CUDA Docker build and GPU inference require an amd64/GPU host (cannot run in the dev environment). The main thing to confirm on build is that the arjunrajlaboratory/DeepTile fork's cellpose_segmentation is 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

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
@arjunrajlab

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: b7baf7d39d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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
@arjunrajlab arjunrajlab merged commit 0b4cf7f into master Jul 1, 2026
1 check passed
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