Skip to content

Cellprofiler 4.0.7 and CellPose 3.0.7 - RunCellpose is out of date #252

@kmshort

Description

@kmshort

Firstly, my versioning information:

CellProfiler version:   4.2.7
cellpose version:       3.0.7
platform:               win32
python version:         3.8.19
torch version:          2.4.0
conda version:          24.7.1

I am using the Cuda SDK v12.4, and torch version 2.4.0

I am using a conda environment with both CellProfiler and Cellpose running in it. I have installed the GUI version of CellPose, and it runs well with CUDA/GPU processing enabled.

However, there are issues with the RunCellpose plugin in CellProfiler. runcellpose.py was pulled via git clone today, 8th August 2024.

Issues:

  1. In the CellProfiler project pipeline, the RunCellpose items are crossed ❌ with the "Value not in decimal format" notification. With the workaround I have, that issue doesn't affect the processing.

  2. The models in the Cellpose 2.x are now mostly removed, but are referenced by the current runcellpose.py.

  3. net_avg used by the plugin is no longer used by CellPose 3.0.7, so the plugin throws an error and exits.

(cellpose) C:\Users\user\anaconda3\envs\cellpose\Scripts\CellProfiler_Plugins>cellprofiler
Progress Counter({'Unprocessed': 1})
Starting workers on address tcp://127.0.0.1:62355
Worker 0: C:\Users\usert\anaconda3\envs\cellpose\lib\site-packages\cellprofiler_core\worker\__init__.py:25: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
Worker 0:   import pkg_resources
Worker 0: Starting job
Progress Counter({'InProcess': 1})
Worker 0: Doing job: 1
Worker 0: Running module Images 1
Worker 0: Thu Aug  8 11:31:18 2024: Image # 1, module Images # 1: CPU_time = 0.00 secs, Wall_time = 0.00 secs
Worker 0: Running module Metadata 2
Worker 0: Thu Aug  8 11:31:18 2024: Image # 1, module Metadata # 2: CPU_time = 0.00 secs, Wall_time = 0.00 secs
Worker 0: Running module NamesAndTypes 3
Worker 0: Thu Aug  8 11:31:18 2024: Image # 1, module NamesAndTypes # 3: CPU_time = 0.25 secs, Wall_time = 0.50 secs
Worker 0: Running module Groups 4
Worker 0: Thu Aug  8 11:31:19 2024: Image # 1, module Groups # 4: CPU_time = 0.00 secs, Wall_time = 0.00 secs
Worker 0: Running module RunCellpose 5
Worker 0: >>>> loading model c:\users\user\Desktop\CellPose Models\StellarisDapi_20240807_131156
Worker 0: >>>> using CPU
Worker 0: C:\Users\user\anaconda3\envs\cellpose\lib\site-packages\cellpose\resnet_torch.py:298: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
Worker 0:   state_dict = torch.load(filename, map_location=torch.device("cpu"))
Worker 0: >>>> model diam_mean =  30.000 (ROIs rescaled to this size during training)
Worker 0: >>>> model diam_labels =  31.044 (mean diameter of training ROIs)
Worker 0: Unable to create masks. Check your module settings. eval() got an unexpected keyword argument 'net_avg'
Worker 0: run_image_set_exception, get_always_continue False
Worker 0: Error detected during run of module RunCellpose#5
Worker 0: Traceback (most recent call last):
Worker 0:   File "C:\Users\user\anaconda3\envs\cellpose\lib\site-packages\cellprofiler_core\pipeline\_pipeline.py", line 1208, in run_image_set
Worker 0:     self.run_module(module, workspace)
Worker 0:   File "C:\Users\user\anaconda3\envs\cellpose\lib\site-packages\cellprofiler_core\pipeline\_pipeline.py", line 1349, in run_module
Worker 0:     module.run(workspace)
Worker 0:   File "C:\Users\user\anaconda3\envs\cellpose\Scripts\CellProfiler_Plugins\CellProfiler-plugins\active_plugins\runcellpose.py", line 638, in run
Worker 0:     y.segmented = y_data
Worker 0: UnboundLocalError: local variable 'y_data' referenced before assignment
Progress Counter({'FinishedWaitingMeasurements': 1})
Progress Counter({'Done': 1})
Finished!
Worker 0: Cancelling worker

If I comment out net_avg lines 536, 551, and 610. The plugin works, but with CPU only (see next).

  1. The Test GPU button does not work. The GPU detection fails (the reference to core.use_gpu on line 717 in the script fails, because there's no reference to core:
File "C:\Users\user\anaconda3\envs\cellpose\Scripts\CellProfiler_Plugins\CellProfiler-plugins\active_plugins\runcellpose.py", line 722, in do_check_gpu
    GPU_works = core.use_gpu(use_torch=torch_installed)
NameError: name 'core' is not defined
  1. When using the GPU anyway, the process fails even though that there is a line that says: ****Worker 0: TORCH CUDA version installed and working. ****:
Progress Counter({'Unprocessed': 1})
Starting workers on address tcp://127.0.0.1:64668
Worker 0: C:\Users\user\anaconda3\envs\cellpose\lib\site-packages\cellprofiler_core\worker\__init__.py:25: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
Worker 0:   import pkg_resources
Worker 0: Starting job
Progress Counter({'InProcess': 1})
Worker 0: Doing job: 1
Worker 0: Running module Images 1
Worker 0: Thu Aug  8 11:44:16 2024: Image # 1, module Images # 1: CPU_time = 0.00 secs, Wall_time = 0.00 secs
Worker 0: Running module Metadata 2
Worker 0: Thu Aug  8 11:44:16 2024: Image # 1, module Metadata # 2: CPU_time = 0.00 secs, Wall_time = 0.00 secs
Worker 0: Running module NamesAndTypes 3
Worker 0: Thu Aug  8 11:44:16 2024: Image # 1, module NamesAndTypes # 3: CPU_time = 0.38 secs, Wall_time = 0.49 secs
Worker 0: Running module Groups 4
Worker 0: Thu Aug  8 11:44:16 2024: Image # 1, module Groups # 4: CPU_time = 0.00 secs, Wall_time = 0.00 secs
Worker 0: Running module RunCellpose 5
Worker 0: >>>> loading model c:\users\userDesktop\CellPose Models\StellarisDapi_20240807_131156
Worker 0: ** TORCH CUDA version installed and working. **
Worker 0: >>>> using GPU
Worker 0: C:\Users\user\anaconda3\envs\cellpose\lib\site-packages\cellpose\resnet_torch.py:294: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
Worker 0:   state_dict = torch.load(filename, map_location=device)
Worker 0: >>>> model diam_mean =  30.000 (ROIs rescaled to this size during training)
Worker 0: >>>> model diam_labels =  31.044 (mean diameter of training ROIs)
Worker 0: run_image_set_exception, get_always_continue False
Worker 0: Error detected during run of module RunCellpose#5
Worker 0: Traceback (most recent call last):
Worker 0:   File "C:\Users\user\anaconda3\envs\cellpose\lib\site-packages\cellprofiler_core\pipeline\_pipeline.py", line 1208, in run_image_set
Worker 0:     self.run_module(module, workspace)
Worker 0:   File "C:\Users\user\anaconda3\envs\cellpose\lib\site-packages\cellprofiler_core\pipeline\_pipeline.py", line 1349, in run_module
Worker 0:     module.run(workspace)
Worker 0:   File "C:\Users\user\anaconda3\envs\cellpose\Scripts\CellProfiler_Plugins\CellProfiler-plugins\active_plugins\runcellpose.py", line 526, in run
Worker 0:     if self.use_gpu.value and model.torch:
Worker 0: AttributeError: 'CellposeModel' object has no attribute 'torch'
Worker 0: Cancelling worker
Worker 0: Aborting job after cancellation
Cancelled!

So in summary, there are a few major issues with runcellpose.py and CellPose 3.0.7. My current edits to remove net_avg, make it work, but only via CPU. I am using custom trained models generated in CellPose 3.0.7.

I hope these issues can be resolved. It would be good to get GPU processing working. I'll continue to look at the python script to see what I can do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions