Skip to content

Run Cellpose issue with imports #263

Open
@MikeLippincott

Description

After clicking the "Test GPU" button in the RunCellpose module, this error shows up in my stdout:

Traceback (most recent call last):
  File "/path/to/conda/env/lib/python3.8/site-packages/cellprofiler/gui/module_view/_module_view.py", line 1206, in callback
    self.__on_do_something(event, setting)
  File "/path/to/conda/env/lib/python3.8/site-packages/cellprofiler/gui/module_view/_module_view.py", line 2247, in __on_do_something
    setting.on_event_fired()
  File "/path/to/conda/env/lib/python3.8/site-packages/cellprofiler_core/setting/do_something/_do_something.py", line 27, in on_event_fired
    self.__callback(*self.__args)
  File "/path/to/CP.plugins/CellProfiler-plugins/active_plugins/runcellpose.py", line 724, in do_check_gpu
    if self.save_probabilities.value:
NameError: name 'core' is not defined`

I can open a PR to patch this with the proposed change below:

Starting on current line 799 of runcellpose.py - add the import core statement

def do_check_gpu(self):
        import importlib.util

        from cellpose import core

        torch_installed = importlib.util.find_spec("torch") is not None
        self.cellpose_ver = importlib.metadata.version("cellpose")
        # if the old version of cellpose <2.0, then use istorch kwarg
        if float(self.cellpose_ver[0:3]) >= 0.7 and int(self.cellpose_ver[0]) < 2:
            GPU_works = core.use_gpu(istorch=torch_installed)
        else:  # if new version of cellpose, use use_torch kwarg
            GPU_works = core.use_gpu(use_torch=torch_installed)
        if GPU_works:
            message = "GPU appears to be working correctly!"
        else:
            message = (
                "GPU test failed. There may be something wrong with your configuration."
            )
        import wx

        wx.MessageBox(message, caption="GPU Test")

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