kreshuklab / plant-seg

A tool for cell instance aware segmentation in densely packed 3D volumetric images
https://kreshuklab.github.io/plant-seg/
MIT License
97 stars 31 forks source link

Does it has to be cuda11.7 for plantseg 1.5? I have cuda11.4 on my pc. When I try to run plantseg1.5, it told me torch cannot detect cuda and switched to cpu. #154

Closed yw254 closed 1 year ago

lorenzocerrone commented 1 year ago

Hi,

PlantSeg with Cuda 11.4 should work fine. Could you please test your nvidia drivers and cuda? To do so you can just type in your terminal: nvidia-smi What is the output?

yw254 commented 1 year ago

Hi,

Thanks for the quick reply!

Here is my nvidia driver and cuda situation:

(base) yang@firedrop:~$ nvidia-smi Thu Apr 27 15:09:15 2023
+-----------------------------------------------------------------------------+ | NVIDIA-SMI 525.105.17 Driver Version: 525.105.17 CUDA Version: 12.0 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA GeForce ... Off | 00000000:01:00.0 On | N/A | | 0% 36C P8 21W / 240W | 417MiB / 8192MiB | 2% Default | | | | N/A | +-------------------------------+----------------------+----------------------+

(base) yang@firedrop:~$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2021 NVIDIA Corporation Built on Mon_Oct_11_21:27:02_PDT_2021 Cuda compilation tools, release 11.4, V11.4.152 Build cuda_11.4.r11.4/compiler.30521435_0

import torch torch.cuda.is_available() True

I noticed the mamba plantseg installation code specified cuda11.7.

mamba create -n plant-seg -c pytorch -c nvidia -c conda-forge -c lcerrone plantseg pytorch-cuda=11.7

Was wondering should I install cuda 11.7?

Thanks!

lorenzocerrone commented 1 year ago

It's very weird. If torch.cuda.is_available() returns True your cuda must be fine.

Maybe just trying to reinstall using

mamba create -n plant-seg -c pytorch -c nvidia -c conda-forge -c lcerrone plantseg pytorch-cuda=11.7

(just from mamba, without changing the nvidiadrivers or cuda version)

And if this does not work, please copy the error message and describe how you use Plantseg (from napari, the command line, or the standard gui)?

yw254 commented 1 year ago

Thanks, Lorenzo, I reinstalled Plantseg and it works now!

I am new to Pantseg, and trying to test some of my images using both the gui and napari now. It works fantastic on images with smaller voxel sizes similar to the pre-trained models. I also got some mature Arabidopsis leaf images with larger voxel sizes like 1.000x0.577x0.577 um (zxy). After rescaling to the confocal_3D_unet_ovules_ds3x model, which is probably the closest voxel size I can rescale to, the prediction runs slower as expected. But it always kills itself at some point. Not sure if it is my 8GB GPU getting drained or something. Here's an example:

2023-04-28 14:12:09,039 [MainThread] INFO PlantSeg - Executing segmentation pipeline for config: {'path': '/home/yang/Documents/mesophyll project/mature leaf/tif/20230401 measophyll GFP-LTI6b P1 17DAS.tif', 'preprocessing': {'state': True, 'save_directory': 'PreProcessing', 'factor': [4.258360363041215, 2.565337379383448, 2.565337379383448], 'order': '2', 'crop_volume': '[:, :, :]', 'filter': {'state': True, 'type': 'gaussian', 'filter_param': 1.0}}, 'cnn_prediction': {'state': True, 'model_name': 'confocal_3D_unet_ovules_ds3x', 'device': 'cuda', 'patch': [80, 160, 160], 'stride_ratio': 0.75, 'patch_halo': [2, 4, 4], 'model_update': False, 'num_workers': 8}, 'cnn_postprocessing': {'state': True, 'tiff': True, 'output_type': 'data_float32', 'factor': [0.23483216889747324, 0.389812275, 0.389812275], 'order': 2, 'save_raw': False}, 'segmentation': {'state': True, 'name': 'GASP', 'beta': 0.6, 'save_directory': 'GASP', 'run_ws': True, 'ws_2D': True, 'ws_threshold': 0.5, 'ws_minsize': 50, 'ws_sigma': 2.0, 'ws_w_sigma': 0.0, 'post_minsize': 50}, 'segmentation_postprocessing': {'state': True, 'tiff': True, 'factor': [0.23483216889747324, 0.389812275, 0.389812275], 'order': 0, 'save_raw': False}} 2023-04-28 14:12:09,060 [ThreadPoolExecutor-0_0] INFO PlantSeg - Running the pipeline on: ['/home/yang/Documents/mesophyll project/mature leaf/tif/20230401 measophyll GFP-LTI6b P1 17DAS.tif'] 2023-04-28 14:12:09,060 [ThreadPoolExecutor-0_0] INFO PlantSeg - Executing pipeline, see terminal for verbose logs. 2023-04-28 14:12:09,173 [ThreadPoolExecutor-0_0] INFO PlantSeg - Executing pipeline step: 'preprocessing'. Parameters: '{'state': True, 'save_directory': 'PreProcessing', 'factor': [4.258360363041215, 2.565337379383448, 2.565337379383448], 'order': 2, 'crop_volume': '[:, :, :]', 'filter': {'state': True, 'type': 'gaussian', 'filter_param': 1.0}}'. Files ['/home/yang/Documents/mesophyll project/mature leaf/tif/20230401 measophyll GFP-LTI6b P1 17DAS.tif']. 2023-04-28 14:12:09,173 [ThreadPoolExecutor-0_0] INFO PlantSeg - Loading stack from /home/yang/Documents/mesophyll project/mature leaf/tif/20230401 measophyll GFP-LTI6b P1 17DAS.tif 2023-04-28 14:12:09,618 [ThreadPoolExecutor-0_0] INFO PlantSeg - Preprocessing files... 2023-04-28 14:12:09,618 [ThreadPoolExecutor-0_0] INFO PlantSeg - Cropping input image to: [:, :, :] 2023-04-28 14:16:53,044 [ThreadPoolExecutor-0_0] INFO PlantSeg - Saving results in /home/yang/Documents/mesophyll project/mature leaf/tif/PreProcessing/20230401 measophyll GFP-LTI6b P1 17DAS.h5 2023-04-28 14:17:51,090 [ThreadPoolExecutor-0_0] INFO PlantSeg - Executing pipeline step: 'cnn_prediction'. Parameters: '{'state': True, 'model_name': 'confocal_3D_unet_ovules_ds3x', 'device': 'cuda', 'patch': [80, 160, 160], 'stride_ratio': 0.75, 'patch_halo': [2, 4, 4], 'model_update': False, 'num_workers': 8}'. Files ['/home/yang/Documents/mesophyll project/mature leaf/tif/PreProcessing/20230401 measophyll GFP-LTI6b P1 17DAS.h5']. 2023-04-28 14:17:51,871 [ThreadPoolExecutor-0_0] INFO PlantSeg - Using batch size of 2 for prediction 2023-04-28 14:17:51,871 [ThreadPoolExecutor-0_0] INFO PlantSeg - Loading stack from /home/yang/Documents/mesophyll project/mature leaf/tif/PreProcessing/20230401 measophyll GFP-LTI6b P1 17DAS.h5 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2420/2420 [25:40<00:00, 1.57it/s] 2023-04-28 14:44:00,778 [ThreadPoolExecutor-0_0] INFO PlantSeg - Saving results in /home/yang/Documents/mesophyll project/mature leaf/tif/PreProcessing/confocal_3D_unet_ovules_ds3x/20230401 measophyll GFP-LTI6b P1 17DAS_predictions.h5 2023-04-28 14:50:33,453 [ThreadPoolExecutor-0_0] INFO PlantSeg - Executing pipeline step: 'cnn_postprocessing'. Parameters: '{'state': True, 'tiff': True, 'output_type': 'data_float32', 'factor': [0.23483216889747324, 0.389812275, 0.389812275], 'order': 2, 'save_raw': False, 'output_shapes': [(144, 1024, 1024)]}'. Files ['/home/yang/Documents/mesophyll project/mature leaf/tif/PreProcessing/confocal_3D_unet_ovules_ds3x/20230401 measophyll GFP-LTI6b P1 17DAS_predictions.h5']. 2023-04-28 14:50:33,453 [ThreadPoolExecutor-0_0] INFO PlantSeg - Loading stack from /home/yang/Documents/mesophyll project/mature leaf/tif/PreProcessing/confocal_3D_unet_ovules_ds3x/20230401 measophyll GFP-LTI6b P1 17DAS_predictions.h5 2023-04-28 14:52:00,335 [ThreadPoolExecutor-0_0] INFO PlantSeg - Postprocessing files... 2023-04-28 14:52:00,335 [ThreadPoolExecutor-0_0] INFO PlantSeg - Resizing image 0 from shape: (613, 2627, 2627) to shape: (144, 1024, 1024) 2023-04-28 14:55:04,110 [ThreadPoolExecutor-0_0] INFO PlantSeg - Saving results in /home/yang/Documents/mesophyll project/mature leaf/tif/PreProcessing/confocal_3D_unet_ovules_ds3x/PostProcessing/20230401 measophyll GFP-LTI6b P1 17DAS_predictions.tiff 2023-04-28 14:55:04,608 [ThreadPoolExecutor-0_0] INFO PlantSeg - Executing pipeline step: 'segmentation'. Parameters: '{'state': True, 'name': 'GASP', 'beta': 0.6, 'save_directory': 'GASP', 'run_ws': True, 'ws_2D': True, 'ws_threshold': 0.5, 'ws_minsize': 50, 'ws_sigma': 2.0, 'ws_w_sigma': 0.0, 'post_minsize': 50}'. Files ['/home/yang/Documents/mesophyll project/mature leaf/tif/PreProcessing/confocal_3D_unet_ovules_ds3x/20230401 measophyll GFP-LTI6b P1 17DAS_predictions.h5']. 2023-04-28 14:55:04,609 [ThreadPoolExecutor-0_0] INFO PlantSeg - Loading stack from /home/yang/Documents/mesophyll project/mature leaf/tif/PreProcessing/confocal_3D_unet_ovules_ds3x/20230401 measophyll GFP-LTI6b P1 17DAS_predictions.h5 2023-04-28 14:56:31,907 [ThreadPoolExecutor-0_0] INFO PlantSeg - Computing segmentation with dtWS... 2023-04-28 15:01:05,346 [ThreadPoolExecutor-0_0] INFO PlantSeg - Clustering with GASP... Killed

Could I get any suggestions on this? Many thanks!

Cheers, Yang

lorenzocerrone commented 1 year ago

The process does not terminate during the predictions stage, but it crashes during the segmentation, so your GPU size is not an issue.

From the error message, I am quite sure this is a problem with the RAM in your machine. Unfortunately, Plantseg segmentation in 3D requires quite a bit of ram. Maybe you could try the Multicut workflow instead of GASP, which should use a bit less RAM.

If this is also not working, have you tried to run the pipeline on a cropped image?

Best regards, Lorenzo

yw254 commented 1 year ago

Thanks Lorenzo, good to know it is not a GPU problem. I tried cropped image and it works now.

Cheers, Yang

lorenzocerrone commented 1 year ago

great! :)