From 4d6be396c738f41faf0d60744240f5921f385d0d Mon Sep 17 00:00:00 2001 From: Pigache Remi Date: Tue, 4 Aug 2026 18:55:32 +0200 Subject: [PATCH] Fix neighbouring cell gradient contamination in _extend_centers_gpu --- cellpose/dynamics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cellpose/dynamics.py b/cellpose/dynamics.py index c3f30d4d..2cbfa622 100644 --- a/cellpose/dynamics.py +++ b/cellpose/dynamics.py @@ -56,16 +56,20 @@ def _extend_centers_gpu(neighbors, meds, isneighbor, shape, n_iter=200, device=t T_flat[flat_meds] += 1 Tneigh = T_flat[flat_neighbors] T_flat[flat_center] = (Tneigh * isneighbor).sum(dim=0) / nneigh - del flat_meds, neighbors, meds, isneighbor, Tneigh + del flat_meds, neighbors, meds, Tneigh if ndim == 2: grads = T_flat[flat_neighbors[[2, 1, 4, 3]]] + grads *= isneighbor[[2, 1, 4, 3]] + del isneighbor dy = grads[0] - grads[1] dx = grads[2] - grads[3] del grads mu = np.stack((dy.cpu().numpy(), dx.cpu().numpy()), axis=0) else: grads = T_flat[flat_neighbors[1:]] + grads *= isneighbor[1:] + del isneighbor dz = grads[0] - grads[1] dy = grads[2] - grads[3] dx = grads[4] - grads[5]