MouseLand / cellpose

a generalist algorithm for cellular segmentation with human-in-the-loop capabilities
https://www.cellpose.org/
BSD 3-Clause "New" or "Revised" License
1.36k stars 390 forks source link

[BUG] NET ERROR: index 1024 is out of bounds for axis 1 with size 1024 #1004

Open FranJGonCal opened 1 month ago

FranJGonCal commented 1 month ago

Hello, I'm new to cellpose and I find an error when upload my file to the program. When I upload an RGB image and run the cyto3 model to segment the image (to later train a custom model) using the gui, an error NET ERROR: index 1024 is out of bounds for axis 1 with size 1024 appears, so no mask are found, and also no segmentation is performed. I don't really know if I need to manually draw the mask of the cells that I want to segment before running the cyto3 model.

Captura de pantalla 2024-08-29 a las 12 35 43
carsen-stringer commented 1 month ago

is this image a z-stack or a single image? does it show up correctly in the GUI? if you have a z-stack then you want to open cellpose with python -m cellpose --Zstack

FranJGonCal commented 1 month ago

is this image a z-stack or a single image? does it show up correctly in the GUI? if you have a z-stack then you want to open cellpose with python -m cellpose --Zstack

It's a single image.

Trying different approaches, I found a way in which It's run correctly. When uploading the image to the program, I was using the "use GPU" option and the problem which I was commenting appeared. However, if I do not choose this option, the progrma runs correctly.

Anyway, thanks so much for your answer.

carsen-stringer commented 1 month ago

Weird thanks for the update, somehow the GPU torch version isn't work, I would also try updating to the latest version v3.0.11 (pip install cellpose --upgrade) and upgrading torch in the same way

carsen-stringer commented 1 month ago

GPU in this case is MPS

mpiersonsmela commented 3 weeks ago

I am also having this problem, only when running on GPU (CPU works OK). The error trace is:

`./run_segmentation.sh 2024-09-30 13:35:19,050 - INFO - TORCH MPS version installed and working. 2024-09-30 13:35:19,050 - INFO - >>>> using GPU (MPS) 2024-09-30 13:35:19,050 - INFO - >> nuclei << model set to be used 2024-09-30 13:35:19,153 - INFO - >>>> loading model /Users/merrickpiersonsmela/.cellpose/models/nucleitorch_0 2024-09-30 13:35:19,223 - INFO - >>>> model diam_mean = 17.000 (ROIs rescaled to this size during training) 2024-09-30 13:35:23,835 - INFO - channels set to [0, 0] 2024-09-30 13:35:23,835 - INFO - ~ FINDING MASKS ~ /Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/dynamics.py:189: RuntimeWarning: invalid value encountered in divide mu /= (1e-60 + (mu2).sum(axis=0)0.5) Traceback (most recent call last): File "/Users/merrickpiersonsmela/Documents/Church_Lab/oogenesis/Images/Segmentation_analysis/2024-09-30_meiosis_BOLL_RNA/../src/segmentation.py", line 93, in process_files(FOLDER_PATH, OUTPUT_FOLDER) File "/Users/merrickpiersonsmela/Documents/Church_Lab/oogenesis/Images/Segmentation_analysis/2024-09-30_meiosis_BOLL_RNA/../src/segmentation.py", line 61, in process_files masks, flows, styles, diams = MODEL.eval([dapi_data], diameter=DIAMETER, channels=[0,0]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/models.py", line 202, in eval masks, flows, styles = self.cp.eval(x, channels=channels, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/models.py", line 414, in eval maski, flowi, stylei = self.eval( ^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/models.py", line 454, in eval masks, styles, dP, cellprob, p = self._run_cp( ^^^^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/models.py", line 561, in _run_cp outputs = dynamics.resize_and_compute_masks( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/dynamics.py", line 783, in resize_and_compute_masks mask, p = compute_masks(dP, cellprob, p=p, niter=niter, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/dynamics.py", line 840, in compute_masks mask = remove_bad_flow_masks(mask, dP, threshold=flow_threshold, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/dynamics.py", line 660, in remove_bad_flowmasks merrors, = metrics.flow_error(masks, flows, device0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/metrics.py", line 256, in flow_error dP_masks = dynamics.masks_to_flows(maski, device=device) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/dynamics.py", line 360, in masks_to_flows mu, mu_c = masks_to_flows_device(masks, device=device, niter=niter) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/merrickpiersonsmela/miniforge3/envs/imageprocessing2/lib/python3.11/site-packages/cellpose/dynamics.py", line 194, in masks_to_flows_gpu mu0[:, y.cpu().numpy() - 1, x.cpu().numpy() - 1] = mu


IndexError: index 2834 is out of bounds for axis 1 with size 2834`
tathey1 commented 3 weeks ago

Having the same issue on MacOS, cellpose 3.0.11, 2D images (IndexError in line 194 dynamics.py). However the issue went away when I reverted using pip install cellpose==3.0.8. Happy to share more info if useful.

carsen-stringer commented 1 day ago

hmm nothing in that function has changed in the past 7 months.

can you upgrade to the latest github version? pip install git+https://github.com/mouseland/cellpose.git

if that doesn't work, could you please check if masks_padded is a reasonable size? https://github.com/MouseLand/cellpose/blob/52f75f9636250979dcff48da18d24aaff41c2c86/cellpose/dynamics.py#L159