Skip to content

Commit

Permalink
fixing divergent behavior in Cellpose and CellposeModel (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed Feb 21, 2024
1 parent af4f8e9 commit 2570475
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cellpose/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def eval(self, x, batch_size=8, channels=None, channel_axis=None, invert=False,

tic0 = time.time()
channels = [0, 0] if channels is None else channels
models_logger.warning("channels not specified, using [0,0] (grayscale + no nuclei)")

diam0 = diameter[0] if isinstance(diameter, (np.ndarray, list)) else diameter
estimate_size = True if (diameter is None or diam0 == 0) else False
Expand Down Expand Up @@ -539,6 +540,9 @@ def _run_cp(self, x, compute_masks=True, normalize=True, invert=False, niter=Non
masks = utils.stitch3D(masks, stitch_threshold=stitch_threshold)
masks = utils.fill_holes_and_remove_small_masks(
masks, min_size=min_size)
elif nimg > 1:
models_logger.warning("3D stack used, but stitch_threshold=0 and do_3D=False, so masks are made per plane only")


flow_time = time.time() - tic
if nimg > 1:
Expand Down
6 changes: 3 additions & 3 deletions cellpose/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,9 @@ def convert_image(x, channels, channel_axis=None, z_axis=None, do_3D=False, ncha
% (nchan, nchan))
x = x[..., :nchan]

if not do_3D and x.ndim > 3:
transforms_logger.critical("ERROR: cannot process 4D images in 2D mode")
raise ValueError("ERROR: cannot process 4D images in 2D mode")
#if not do_3D and x.ndim > 3:
# transforms_logger.critical("ERROR: cannot process 4D images in 2D mode")
# raise ValueError("ERROR: cannot process 4D images in 2D mode")

if nchan is not None and x.shape[-1] < nchan:
x = np.concatenate((x, np.tile(np.zeros_like(x), (1, 1, nchan - 1))),
Expand Down

0 comments on commit 2570475

Please sign in to comment.