Skip to content

Add cellpose v4 support; migrate to npe2 and pyproject.toml#62

Open
jeskowagner wants to merge 9 commits into
MouseLand:mainfrom
jeskowagner:cellpose-v4
Open

Add cellpose v4 support; migrate to npe2 and pyproject.toml#62
jeskowagner wants to merge 9 commits into
MouseLand:mainfrom
jeskowagner:cellpose-v4

Conversation

@jeskowagner

Copy link
Copy Markdown

The plugin now detects the installed cellpose major version at import time and adapts accordingly. On v4, model/channel selection and image- based diameter estimation are hidden because cellpose-sam only provides the one model.

Other changes:

  • Migrate from npe1 (napari-plugin-engine) to npe2: remove legacy hook registrations, add napari.yaml manifest with valid python_name entries
  • Replace setup.cfg/requirements.txt/tox.ini/MANIFEST.in with a single pyproject.toml (tox config embedded under [tool.tox])
  • Remove the Cells 2D sample data contribution; the source URL was broken
  • Guard _compute_diameter_shape against no shape layer being selected

Fixes #61.

The plugin now detects the installed cellpose major version at import
time and adapts accordingly. On v4, model/channel selection and image-
based diameter estimation are hidden because cellpose-sam only provides the one model.

Other changes:
- Migrate from npe1 (napari-plugin-engine) to npe2: remove legacy hook
  registrations, add napari.yaml manifest with valid python_name entries
- Replace setup.cfg/requirements.txt/tox.ini/MANIFEST.in with a single
  pyproject.toml (tox config embedded under [tool.tox])
- Remove the Cells 2D sample data contribution; the source URL was broken
- Guard _compute_diameter_shape against no shape layer being selected
@carsen-stringer
carsen-stringer self-requested a review April 20, 2026 17:16
@jeskowagner

Copy link
Copy Markdown
Author

Just saw the unit test failures, will investigate in the next days and ping again when fixed :)

- For cellpose V4, show z_axis and channel_axis dropdowns for 4D images (required)
  and 3D images (optional; -1 sentinel = pure spatial ZYX); defaults inferred
  from napari axis labels
- Fix 3D flow/cellprob handling: skip resize_image for 3D outputs to avoid
  collapsing the Z axis and leaving layers in a broken vispy state
- Remove output_flows/output_outlines checkboxes; always write all output layers
- Replace sample data source with OSF zip (rgb_2D_tif + rgb_3D); add
  rgb_2D sample ("Cells (2D+2Ch)") to napari.yaml
- Exclude build/ directory from setuptools package discovery
- Update tests: switch sample from local file to 'rgb_2D' napari sample, fix
  dock_widgets API (drop underscore prefix), update expected mask counts for
 cellpose V4 vs V3, and adjust diameter tolerance for Windows/CPU
- Rewrite sample data loader: fetch from OSF zip instead of per-file URLs,
  add rgb_2D sample, set axis_labels on rgb_3D so z/channel dropdowns
  auto-populate correctly
@jeskowagner

Copy link
Copy Markdown
Author

@carsen-stringer I have changed out some of the tests - Cellpose-SAM on CPU in 3D simply takes too long. I also had to make sure that torch is loaded in before pyqt due to pytorch/pytorch#166628. I added some new tests, and a CI test for cellpose=3 to make sure the GUI stays compatible. With these changes in place, all tests are passing now!

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 48.16754% with 99 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.98%. Comparing base (ef6d108) to head (8e96e2e).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
cellpose_napari/_dock_widget.py 44.11% 95 Missing ⚠️
cellpose_napari/_sample_data.py 80.95% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #62      +/-   ##
==========================================
- Coverage   54.31%   52.98%   -1.33%     
==========================================
  Files           3        3              
  Lines         232      285      +53     
==========================================
+ Hits          126      151      +25     
- Misses        106      134      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jeskowagner

Copy link
Copy Markdown
Author

Looks like there were two problems with CI:

  1. Windows runners were failing because torch could not detect a directory to download the model weights into. This is fixed with 14624a4
  2. Cellpose-SAM in CPU-only mode sometimes exceeds the 6 min timeout - this seems a bit hit and miss depending on the runner. Would be nice to have GPUs in the runners, but I don't think we can get those for free. Since some of the runners are passing this check, I feel this is not really a showstopper. Alternatively, I can increase the timeout. Let me know what you prefer.

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.

Support for Cellpose 4

2 participants