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.33k stars 382 forks source link

3D segmentation not working with the GUI #867

Closed bpavie closed 7 months ago

bpavie commented 7 months ago

Describe the bug The 3D segmentationis failing using the last version of cellpose (3.0.4) using the GUI

To Reproduce Steps to reproduce the behavior:

  1. Install cellpose using conda with the following yaml file:
    name: cellpose-aiscimageio-napari-gpu
    channels:
    - pytorch
    - nvidia
    - conda-forge
    dependencies:
    - python==3.11.4
    - pytorch-cuda=11.7
    - pytorch
    - mahotas=1.4.13
    - scikit-image
    - napari==0.4.18
    - napari-aicsimageio==0.7.2
    - napari-czifile2==0.2.7
    - libxml2=2.10.4
    - bioformats_jar
    - pandas
    - seaborn
    - natsort
    - stackview
    - pip
    - pip:
    - cellpose==3.0.4
    - cellpose[gui]
    - fsspec>=2022.7.1
    - openpyxl 
  2. Dataset Raw Carcinoma Confocal microscopy 3D single channel 8 bit specifically Patch076.tif
  3. start cellpose 3d
    python -m cellpose --Zstack
  4. Click on cyto3
  5. See error

Run log

C:\Users\u0094799\Documents\Projects\CODE>python -m cellpose --Zstack
2024-02-19 14:58:26,337 [INFO] WRITING LOG OUTPUT TO C:\Users\u00xxxxx\.cellpose\run.log
2024-02-19 14:58:26,337 [INFO]
cellpose version:       3.0.4
platform:               win32
python version:         3.11.4
torch version:          2.2.0
2024-02-19 14:58:26,541 [INFO] TORCH CUDA version not installed/working.
GUI_INFO: loading image: C:/Users/u00xxxxx/Downloads/3d_dataset/Carcinoma_human_breast_cells_raw/Patch076.tif
2024-02-19 14:58:30,124 [INFO] reading tiff with 26 planes
100%|████████████████████████████████████████████████████████████████████████████████| 26/26 [00:00<00:00, 5767.50it/s]
GUI_INFO: converted to float and normalized values to 0.0->255.0
GUI_INFO: normalization checked: computing saturation levels (and optionally filtered image)
{'lowhigh': None, 'percentile': [1.0, 99.0], 'normalize': True, 'norm3D': False, 'sharpen_radius': 0, 'smooth_radius': 0, 'tile_norm_blocksize': 0, 'tile_norm_smooth3D': 1, 'invert': False}
2024-02-19 14:58:34,727 [INFO] >>>> using CPU
2024-02-19 14:58:34,728 [INFO] >> cyto3 << model set to be used
2024-02-19 14:58:34,876 [INFO] >>>> model diam_mean =  30.000 (ROIs rescaled to this size during training)
{'lowhigh': None, 'percentile': [1.0, 99.0], 'normalize': True, 'norm3D': False, 'sharpen_radius': 0, 'smooth_radius': 0, 'tile_norm_blocksize': 0, 'tile_norm_smooth3D': 1, 'invert': False}
2024-02-19 14:58:34,885 [INFO] ~~~ FINDING MASKS ~~~
2024-02-19 14:58:34,885 [INFO] multi-stack tiff read in as having 26 planes 1 channels
2024-02-19 14:58:34,941 [INFO] running YX: 26 planes of size (202, 262)
2024-02-19 14:58:34,945 [INFO] 0%|          | 0/2 [00:00<?, ?it/s]
2024-02-19 14:58:40,332 [INFO] 50%|#####     | 1/2 [00:05<00:05,  5.39s/it]
2024-02-19 14:58:44,826 [INFO] 100%|##########| 2/2 [00:09<00:00,  4.86s/it]
2024-02-19 14:58:44,826 [INFO] 100%|##########| 2/2 [00:09<00:00,  4.94s/it]
2024-02-19 14:58:44,905 [INFO] running ZY: 202 planes of size (26, 262)
2024-02-19 14:58:44,916 [INFO] 0%|          | 0/13 [00:00<?, ?it/s]
2024-02-19 14:58:45,989 [INFO] 8%|7         | 1/13 [00:01<00:12,  1.07s/it]
2024-02-19 14:58:46,914 [INFO] 15%|#5        | 2/13 [00:01<00:10,  1.01it/s]
2024-02-19 14:58:47,817 [INFO] 23%|##3       | 3/13 [00:02<00:09,  1.05it/s]
2024-02-19 14:58:48,706 [INFO] 31%|###       | 4/13 [00:03<00:08,  1.08it/s]
2024-02-19 14:58:49,598 [INFO] 38%|###8      | 5/13 [00:04<00:07,  1.10it/s]
2024-02-19 14:58:50,504 [INFO] 46%|####6     | 6/13 [00:05<00:06,  1.10it/s]
2024-02-19 14:58:51,382 [INFO] 54%|#####3    | 7/13 [00:06<00:05,  1.11it/s]
2024-02-19 14:58:52,287 [INFO] 62%|######1   | 8/13 [00:07<00:04,  1.11it/s]
2024-02-19 14:58:53,180 [INFO] 69%|######9   | 9/13 [00:08<00:03,  1.11it/s]
2024-02-19 14:58:54,060 [INFO] 77%|#######6  | 10/13 [00:09<00:02,  1.12it/s]
2024-02-19 14:58:55,006 [INFO] 85%|########4 | 11/13 [00:10<00:01,  1.10it/s]
2024-02-19 14:58:55,911 [INFO] 92%|#########2| 12/13 [00:10<00:00,  1.10it/s]
2024-02-19 14:58:56,813 [INFO] 100%|##########| 13/13 [00:11<00:00,  1.10it/s]
2024-02-19 14:58:56,814 [INFO] 100%|##########| 13/13 [00:11<00:00,  1.09it/s]
2024-02-19 14:58:56,868 [INFO] running ZX: 262 planes of size (26, 202)
2024-02-19 14:58:56,876 [INFO] 0%|          | 0/9 [00:00<?, ?it/s]
2024-02-19 14:58:57,762 [INFO] 11%|#1        | 1/9 [00:00<00:07,  1.13it/s]
2024-02-19 14:58:58,682 [INFO] 22%|##2       | 2/9 [00:01<00:06,  1.10it/s]
2024-02-19 14:58:59,582 [INFO] 33%|###3      | 3/9 [00:02<00:05,  1.11it/s]
2024-02-19 14:59:00,499 [INFO] 44%|####4     | 4/9 [00:03<00:04,  1.10it/s]
2024-02-19 14:59:01,402 [INFO] 56%|#####5    | 5/9 [00:04<00:03,  1.10it/s]
2024-02-19 14:59:02,302 [INFO] 67%|######6   | 6/9 [00:05<00:02,  1.11it/s]
2024-02-19 14:59:03,206 [INFO] 78%|#######7  | 7/9 [00:06<00:01,  1.11it/s]
2024-02-19 14:59:04,110 [INFO] 89%|########8 | 8/9 [00:07<00:00,  1.11it/s]
2024-02-19 14:59:05,003 [INFO] 100%|##########| 9/9 [00:08<00:00,  1.11it/s]
2024-02-19 14:59:05,003 [INFO] 100%|##########| 9/9 [00:08<00:00,  1.11it/s]
2024-02-19 14:59:05,055 [INFO] network run in 30.16s
2024-02-19 14:59:06,173 [INFO] masks created in 1.12s
2024-02-19 14:59:06,276 [INFO] >>>> TOTAL TIME 31.39 sec
Traceback (most recent call last):
  File "C:\GBW_MyPrograms\mambaforge\envs\cellpose-aiscimageio-napari-gpu\Lib\site-packages\cellpose\gui\guiparts.py", line 139, in <lambda>
    self.clicked.connect(lambda: self.press(parent))
                                 ^^^^^^^^^^^^^^^^^^
  File "C:\GBW_MyPrograms\mambaforge\envs\cellpose-aiscimageio-napari-gpu\Lib\site-packages\cellpose\gui\guiparts.py", line 143, in press
    parent.compute_segmentation(model_name=self.model_name)
  File "C:\GBW_MyPrograms\mambaforge\envs\cellpose-aiscimageio-napari-gpu\Lib\site-packages\cellpose\gui\gui.py", line 2228, in compute_segmentation
    self.flows.append(resize_image(self.flows[j], Ly=self.Ly,
                                   ~~~~~~~~~~^^^
IndexError: list index out of range

before running any Cellpose functions.

Screenshots image

carsen-stringer commented 7 months ago

sorry about that can you please pip install git+https://github.com/mouseland/cellpose.git and let us know if it's still not working

derekthirstrup commented 7 months ago

I also get an error attempting to segment 3d tif stacks using the new 3.0.5 git branch that you posted earlier. It seems to always crash at the end at the resize_image interpolation step when using the GUI. Seems to work in headless runs but without the gui it is hard to evaluate and train a new 3d model. Here is the traceback. 2024-02-19 15:49:09,151 [INFO] network run in 105.47s 2024-02-19 15:50:10,917 [INFO] masks created in 61.77s 2024-02-19 15:50:28,334 [INFO] >>>> TOTAL TIME 185.30 sec Traceback (most recent call last): File "C:\Users\derekt.conda\envs\cellpose3dev\Lib\site-packages\cellpose\gui\guiparts.py", line 147, in self.clicked.connect(lambda: self.press(parent)) ^^^^^^^^^^^^^^^^^^ File "C:\Users\derekt.conda\envs\cellpose3dev\Lib\site-packages\cellpose\gui\guiparts.py", line 151, in press parent.compute_segmentation(model_name=self.model_name) File "C:\Users\derekt.conda\envs\cellpose3dev\Lib\site-packages\cellpose\gui\gui.py", line 2445, in compute_segmentation resize_image(flows_new[j], Ly=self.Ly, Lx=self.Lx, File "C:\Users\derekt.conda\envs\cellpose3dev\Lib\site-packages\cellpose\transforms.py", line 838, in resize_image imgs = cv2.resize(img0, (Lx, Ly), interpolation=interpolation) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cv2.error: OpenCV(4.9.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\resize.cpp:3789: error: (-215:Assertion failed) !dsize.empty() in function 'cv::hal::resize'

bpavie commented 7 months ago

pip install git+https://github.com/mouseland/cellpose.git

Thanks, using the git repository fixed the problem. I also tried the other image restoration deblur, run cyto3 segmentation and everything for fine!

Congrats for this new release, it looks really great !

image

oliviajmcg commented 7 months ago

sorry about that can you please pip install git+https://github.com/mouseland/cellpose.git and let us know if it's still not working

I had the same original issue as bpavie. Using a fresh install of pip install git+https://github.com/mouseland/cellpose.git solved the problem when using the images bpavie provided, but fails when I try to 3d segment my own images. Image restoration works fine on my data after installing via git. Here is the traceback for 3D segmentation on my images:


Traceback (most recent call last):
  File "/home/olivia/miniconda3/envs/cellpose-git/lib/python3.9/site-packages/cellpose/gui/guiparts.py", line 147, in <lambda>
    self.clicked.connect(lambda: self.press(parent))
  File "/home/olivia/miniconda3/envs/cellpose-git/lib/python3.9/site-packages/cellpose/gui/guiparts.py", line 151, in press
    parent.compute_segmentation(model_name=self.model_name)
  File "/home/olivia/miniconda3/envs/cellpose-git/lib/python3.9/site-packages/cellpose/gui/gui.py", line 2445, in compute_segmentation
    resize_image(flows_new[j], Ly=self.Ly, Lx=self.Lx,
  File "/home/olivia/miniconda3/envs/cellpose-git/lib/python3.9/site-packages/cellpose/transforms.py", line 838, in resize_image
    imgs = cv2.resize(img0, (Lx, Ly), interpolation=interpolation)
cv2.error: OpenCV(4.9.0) /io/opencv/modules/imgproc/src/resize.cpp:3789: error: (-215:Assertion failed) !dsize.empty() in function 'resize'
carsen-stringer commented 7 months ago

what is the size of your 3D stack? sorry I can't reproduce this

derekthirstrup commented 7 months ago

That is the same error I get when trying to segment H2B 3D nuclei in the GUI. The image dimensions are 2048x2048x41. I could upload a stack if you want to use it for debugging.

oliviajmcg commented 7 months ago

Thanks for replying so quickly! The size of my 3D stack is 1024x1024x271. This stack is quite large, so I'm uploading a cropped substack which also gives the same error (size 544x566x26) test_crop_substack_drosophila_neuron_nuclei.zip. To reproduce the error, I open the cellpose GUI from terminal with python -m cellpose --Zstack, drag in my stack, and click run cyto3 (no adjustments or image restoration). It runs YX, ZY, and ZX. Here is the traceback again after that point:

2024-02-22 12:21:03,031 [INFO] network run in 10.62s
2024-02-22 12:21:06,785 [INFO] masks created in 3.75s
2024-02-22 12:21:07,274 [INFO] >>>> TOTAL TIME 14.88 sec
Traceback (most recent call last):
  File "/home/olivia/miniconda3/envs/cellpose-git/lib/python3.9/site-packages/cellpose/gui/guiparts.py", line 147, in <lambda>
    self.clicked.connect(lambda: self.press(parent))
  File "/home/olivia/miniconda3/envs/cellpose-git/lib/python3.9/site-packages/cellpose/gui/guiparts.py", line 151, in press
    parent.compute_segmentation(model_name=self.model_name)
  File "/home/olivia/miniconda3/envs/cellpose-git/lib/python3.9/site-packages/cellpose/gui/gui.py", line 2445, in compute_segmentation
    resize_image(flows_new[j], Ly=self.Ly, Lx=self.Lx,
  File "/home/olivia/miniconda3/envs/cellpose-git/lib/python3.9/site-packages/cellpose/transforms.py", line 838, in resize_image
    imgs = cv2.resize(img0, (Lx, Ly), interpolation=interpolation)
cv2.error: OpenCV(4.9.0) /io/opencv/modules/imgproc/src/resize.cpp:3789: error: (-215:Assertion failed) !dsize.empty() in function 'resize'
carsen-stringer commented 7 months ago

also seen in #870

carsen-stringer commented 7 months ago

thanks @oliviajmcg for sharing your stack! I downloaded it but I am not getting the error. Can you please try updating again to the latest git release?

oliviajmcg commented 7 months ago

thanks @oliviajmcg for sharing your stack! I downloaded it but I am not getting the error. Can you please try updating again to the latest git release?

I tried updating again and it's working now. Apologies, must have missed an update somewhere along the thread. Thanks for your help!

carsen-stringer commented 7 months ago

no worries, thanks so much for your helpful feedback!