Migrate Cellpose Segmentation Workflows to Cellpose 4#406
Open
falconsmilie wants to merge 16 commits into
Open
Migrate Cellpose Segmentation Workflows to Cellpose 4#406falconsmilie wants to merge 16 commits into
falconsmilie wants to merge 16 commits into
Conversation
…and dummy filehandler
… and CytosolOnly workflows
…l size filter parameter wiring
…r pretrained and custom models
…ion critical checks
…mbined Phenix parser paths
Contributor
Author
|
I'm running pre-commit locally, no idea why it fails on the server (and is being run under a unit test job?). The pre-commit.ci action should work now (i ticked the box). I figure the build will succeed now, if you can restart it. |
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
This PR migrates scPortrait’s Cellpose segmentation workflow support toward Cellpose 4 compatibility while adding a stronger test safety net around the existing workflow behaviour.
The main change is the introduction of a narrow Cellpose backend adapter that owns Cellpose-specific model loading and eval-call compatibility. The segmentation workflows continue to own image preparation, channel selection, post-processing, finalisation, filtering, mask matching, and saving.
This should make the Cellpose 4 migration easier to maintain without spreading Cellpose-version-specific logic across the workflow layer.
Why this change was needed
Cellpose 4 changed the supported model-loading API and channel/eval semantics compared with the previous Cellpose 3-era integration. The previous workflow code called Cellpose APIs directly, which made the dependency upgrade risky because model loading, eval parameters, workflow orchestration, and post-processing were tightly coupled.
This PR separates those responsibilities and adds tests around the behaviours most likely to regress during the migration.
Main changes
Test harness and workflow characterisation
DummyFileHandlerFakeCellposeModelModel-loading and backend migration
_cellpose_backend.pywith:CellposeBackendCellposeModelSpecCellposeEvalParametersCellposeModel(pretrained_model=...)behaviour.os.fspath(...)before passing them to Cellpose.Validation and robustness fixes
_load_model(...)validation so invalid config fails clearly when neithermodelnormodel_pathis configured._check_input_image_dtype(...)so invalid image dtypes raiseValueErrorinstead of silently constructing an error object._check_seg_dtype(...)so it checksmask.dtype, emits a real warning, and converts to the configured segmentation dtype when needed.Cellpose 4 dependency and integration smoke tests
cellpose>=4.1,<5.integrationcellposeDocumentation
modelusagemodel_pathusageAdditional compatibility fixes
spatialdata-plotversions that do not support themethodargument.Testing
The branch adds or updates tests covering:
Recommended test commands:
pytest tests/unit_tests/pipeline -qpytest tests/unit_tests --disable-warningsFocused Cellpose test run:
pytest tests/unit_tests/pipeline/test_cellpose_backend.py tests/unit_tests/pipeline/test_cellpose_model_loading.py tests/unit_tests/pipeline/test_cellpose_eval_contract.py tests/unit_tests/pipeline/test_cellpose_postprocessing.py tests/unit_tests/pipeline/test_segmentation_channel_selection.py -qOptional real Cellpose smoke test:
SCPORTRAIT_RUN_CELLPOSE_INTEGRATION=1 pytest tests -m "cellpose or integration" -qNotes for reviewers
The intended responsibility boundary is:
The real Cellpose smoke tests intentionally assert only structural output properties. They do not attempt to validate scientific segmentation quality or exact label values.
Areas to review carefully
Please pay special attention to:
CellposeModel(pretrained_model=...)usageScope note
This PR includes a small amount of adjacent compatibility work for plotting and combined Phenix XML path handling.