Skip to content

Commit 3aa70b7

Browse files
[fix] Cellpose 4.2 compatibility (#260)
* [fix] Ignore removed argument in latest cellpose versions * Remove the invert keyword from the common_args * Raise instead of warn to prevent repetitive warning across all segmentation runners. Make docstrings more informative * Run pre-commit hooks
1 parent df61db9 commit 3aa70b7

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • src/harpy/image/segmentation/segmentation_models

src/harpy/image/segmentation/segmentation_models/_cellpose.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def cellpose_callable(
7171
See documentation of `cellpose.models.CellposeModel.eval` for full description.
7272
invert
7373
Invert image pixel intensity before running network. Defaults to `False`.
74+
Only supported for cellpose versions `<4.2.0` and raises a `ValueError` on newer versions.
7475
diameter
7576
The estimated diameter of cells (in pixels).
7677
flow_threshold
@@ -171,7 +172,6 @@ def cellpose_callable(
171172
"channel_axis": 3 if do_3D_segmentation else 2,
172173
"z_axis": 0 if do_3D_segmentation else None,
173174
"normalize": normalize,
174-
"invert": invert,
175175
"rescale": None, # not supported in harpy.
176176
"diameter": diameter,
177177
"flow_threshold": flow_threshold,
@@ -193,6 +193,13 @@ def cellpose_callable(
193193
else:
194194
common_args["flow3D_smooth"] = flow3D_smooth
195195

196+
if cellpose_version < version.parse("4.2.0"):
197+
common_args["invert"] = invert
198+
elif invert:
199+
raise ValueError(
200+
"`invert` was removed from 'CellposeModel.eval' in cellpose>=4.2.0. "
201+
"Please invert the image before passing with it with `invert=False` to `harpy.im.segment`, or pin 'cellpose<4.2.0'."
202+
)
196203
results = model.eval(**common_args)
197204

198205
masks = results[0][0]

0 commit comments

Comments
 (0)