-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Crashing during headless processing a folder of 3D z stacks #1038
Comments
Bug Summary: IndexError and Deprecation Warning in dynamics.py Deprecation Warning: Message: UserWarning: The use of IndexError: tuple index out of range Issue Addressed: Deprecation Warning due to the use of .T on tensors with more than 2 dimensions. if ndim==3: Modified Code: if ndim == 3: Reason for Change: Issue Addressed: IndexError due to accessing pt.shape[1] when pt may not have a second dimension. Original Code: Modified Code: Ensure 'pt' is 2D before creating the sparse tensorif pt.dim() == 1: Create sparse COO tensor with error handlingtry: Reason for Change: Function: get_masks_torch (Additional Safety) Issue Addressed: Potential failure when no seeds are found, which could lead to unexpected behavior or errors in subsequent processing. seeds1 = torch.nonzero((h1 - hmax1 > -1e-6) * (h1 > 10)) Reason for Change: Issue Addressed: Ensuring that the creation of the sparse tensor does not fail due to unexpected tensor dimensions. Ensure 'pt' is 2D before creating the sparse tensorif pt.dim() == 1: Create sparse COO tensor with error handlingtry: Reason for Change: Replaced deprecated .T operations with .mT and .permute() to comply with the latest PyTorch standards and prevent future errors. Preventing Index Errors: Enhancing Robustness: |
thanks, I'd really appreciate a PR for this, sorry for the issues |
@carsen-stringer I made a PR and included a minimal change dynamics.py version that addresses the index error as well as an optimized dynamics.py with additional performance optimizations. |
Hello, I encountered the same error as described above on a particular 3D z stack, that works on the GUI but not on the command line. Thanks for the PR! Jorge |
Describe the bug
This crash happens consistently segmenting specific 3D images in a folder with cellpose 3.1.0 . The 3d segmentation of the exact same image works fine with the GUI using same settings so this appears to only occur with headless processing mode.
To Reproduce
Steps to reproduce the behavior:
python -m cellpose --verbose --use_gpu --dir \networkdrive\C2_EGFP_zlibcompressed --pretrained_model cyto3 --restore_type denoise_cyto3 --z_axis 0 --stitch_threshold 0.5 --diameter 80 --flow_threshold 0.0 --cellprob_threshold 0.0 --chan 0 --save_tif --no_npy --min_size 10000 --savedir \networkdrive\CPMask_80_CP310_-1_DefaultIntNorm
Run log
cellpose version: 3.1.0
platform: win32
python version: 3.12.7
torch version: 2.5.1
2024-10-31 14:21:45,152 [INFO] 0%| | 0/101 [00:00<?, ?it/s]
2024-10-31 14:21:45,199 [INFO] No cell pixels found.
C:\Users\derekt.conda\envs\cellpose3.1.0\Lib\site-packages\cellpose\dynamics.py:508: UserWarning: The use of
x.T
on tensors of dimension other than 2 to reverse their shape is deprecated and it will throw an error in a future release. Considerx.mT
to transpose batches of matrices orx.permute(*torch.arange(x.ndim - 1, -1, -1))
to reverse the dimensions of a tensor. (Triggered internally at C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\TensorShape.cpp:3687.)return pt[..., [1, 0]].squeeze().T
2024-10-31 14:21:47,714 [INFO] 41%|#### | 41/101 [00:02<00:03, 16.00it/s]
2024-10-31 14:21:47,714 [INFO] 10%|# | 23/223 [09:54<1:26:13, 25.87s/it]
Traceback (most recent call last):
File "", line 198, in run_module_as_main
File "", line 88, in run_code
File "C:\Users\derekt.conda\envs\cellpose3.1.0\Lib\site-packages\cellpose_main.py", line 358, in
main()
File "C:\Users\derekt.conda\envs\cellpose3.1.0\Lib\site-packages\cellpose_main.py", line 205, in main
out = model.eval(
^^^^^^^^^^^
File "C:\Users\derekt.conda\envs\cellpose3.1.0\Lib\site-packages\cellpose\denoise.py", line 583, in eval
masks, flows, styles = self.cp.eval(
^^^^^^^^^^^^^
File "C:\Users\derekt.conda\envs\cellpose3.1.0\Lib\site-packages\cellpose\models.py", line 534, in eval
masks = self._compute_masks(x.shape, dP, cellprob, flow_threshold=flow_threshold,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\derekt.conda\envs\cellpose3.1.0\Lib\site-packages\cellpose\models.py", line 620, in _compute_masks
outputs = dynamics.resize_and_compute_masks(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\derekt.conda\envs\cellpose3.1.0\Lib\site-packages\cellpose\dynamics.py", line 839, in resize_and_compute_masks
mask = compute_masks(dP, cellprob, niter=niter,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\derekt.conda\envs\cellpose3.1.0\Lib\site-packages\cellpose\dynamics.py", line 906, in compute_masks
mask = get_masks_torch(p_final, inds, dP.shape[1:],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\derekt.conda\envs\cellpose3.1.0\Lib\site-packages\cellpose\dynamics.py", line 757, in get_masks_torch
coo = torch.sparse_coo_tensor(pt, torch.ones(pt.shape[1], device=pt.device, dtype=torch.int),
~~~~~~~~^^^
IndexError: tuple index out of range
The text was updated successfully, but these errors were encountered: