cellpose-napari icon indicating copy to clipboard operation
cellpose-napari copied to clipboard

TypeError: eval() got an unexpected keyword argument 'net_avg'

Open LeungKamdayjat opened this issue 1 year ago • 6 comments

Hi, I installed cellpose-napari plugin in naparim, when I tried to run segment, this happened. I don't think there's a way for me to change net_ave since I only have the true/false options in the GUI interface.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File /opt/homebrew/anaconda3/envs/napari/lib/python3.9/site-packages/superqt/utils/_qthreading.py:617, in create_worker.<locals>.reraise(e=TypeError("eval() got an unexpected keyword argument 'net_avg'"))
    616 def reraise(e):
--> 617     raise e
        e = TypeError("eval() got an unexpected keyword argument 'net_avg'")

File /opt/homebrew/anaconda3/envs/napari/lib/python3.9/site-packages/superqt/utils/_qthreading.py:178, in WorkerBase.run(self=<napari._qt.qthreading.FunctionWorker object>)
    176     warnings.filterwarnings("always")
    177     warnings.showwarning = lambda *w: self.warned.emit(w)
--> 178     result = self.work()
        self = <napari._qt.qthreading.FunctionWorker object at 0x16ba32af0>
    179 if isinstance(result, Exception):
    180     if isinstance(result, RuntimeError):
    181         # The Worker object has likely been deleted.
    182         # A deleted wrapped C/C++ object may result in a runtime
    183         # error that will cause segfault if we try to do much other
    184         # than simply notify the user.

File /opt/homebrew/anaconda3/envs/napari/lib/python3.9/site-packages/superqt/utils/_qthreading.py:357, in FunctionWorker.work(self=<napari._qt.qthreading.FunctionWorker object>)
    356 def work(self) -> _R:
--> 357     return self._func(*self._args, **self._kwargs)
        self._func = <function widget_wrapper.<locals>.run_cellpose at 0x291a02d30>
        self = <napari._qt.qthreading.FunctionWorker object at 0x16ba32af0>
        self._args = ()
        self._kwargs = {'image': <class 'numpy.ndarray'> (934, 934) uint16, 'model_type': 'cyto', 'custom_model': '/Users/jeffrey.liang', 'channels': [1, 0], 'channel_axis': None, 'diameter': 5.64, 'net_avg': False, 'resample': False, 'cellprob_threshold': 1.747126, 'model_match_threshold': 25.0, 'do_3D': False, 'stitch_threshold': 0.0}

File /opt/homebrew/anaconda3/envs/napari/lib/python3.9/site-packages/torch/utils/_contextlib.py:115, in context_decorator.<locals>.decorate_context(*args=(), **kwargs={'cellprob_threshold': 1.747126, 'channel_axis': None, 'channels': [1, 0], 'custom_model': '/Users/jeffrey.liang', 'diameter': 5.64, 'do_3D': False, 'image': <class 'numpy.ndarray'> (934, 934) uint16, 'model_match_threshold': 25.0, 'model_type': 'cyto', 'net_avg': False, ...})
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)
        func = <function widget_wrapper.<locals>.run_cellpose at 0x1687939d0>
        args = ()
        kwargs = {'image': <class 'numpy.ndarray'> (934, 934) uint16, 'model_type': 'cyto', 'custom_model': '/Users/jeffrey.liang', 'channels': [1, 0], 'channel_axis': None, 'diameter': 5.64, 'net_avg': False, 'resample': False, 'cellprob_threshold': 1.747126, 'model_match_threshold': 25.0, 'do_3D': False, 'stitch_threshold': 0.0}

File /opt/homebrew/anaconda3/envs/napari/lib/python3.9/site-packages/cellpose_napari/_dock_widget.py:73, in widget_wrapper.<locals>.run_cellpose(image=<class 'numpy.ndarray'> (934, 934) uint16, model_type='cyto', custom_model='/Users/jeffrey.liang', channels=[1, 0], channel_axis=None, diameter=5.64, net_avg=False, resample=False, cellprob_threshold=1.747126, model_match_threshold=25.0, do_3D=False, stitch_threshold=0.0)
     71 else:
     72     CP = models.CellposeModel(model_type=model_type, gpu=True)
---> 73 masks, flows_orig, _ = CP.eval(image, 
        CP = <cellpose.models.CellposeModel object at 0x2bcf3c250>
        image = <class 'numpy.ndarray'> (934, 934) uint16
        channels = [1, 0]
        channel_axis = None
        diameter = 5.64
        net_avg = False
        resample = False
        cellprob_threshold = 1.747126
        flow_threshold = 0.6
        do_3D = False
        stitch_threshold = 0.0
     74                             channels=channels, 
     75                             channel_axis=channel_axis,
     76                             diameter=diameter,
     77                             net_avg=net_avg,
     78                             resample=resample,
     79                             cellprob_threshold=cellprob_threshold,
     80                             flow_threshold=flow_threshold,
     81                             do_3D=do_3D,
     82                             stitch_threshold=stitch_threshold)
     83 del CP
     84 if not do_3D and stitch_threshold==0 and masks.ndim > 2:

TypeError: eval() got an unexpected keyword argument 'net_avg'

LeungKamdayjat avatar Mar 14 '24 15:03 LeungKamdayjat

I had the same issue, which I was able to solve by making a new environment using cellpose v2.3.2 instead of v3.0.7, which I had been using. Hope this helps!

kelk16 avatar Mar 29 '24 21:03 kelk16

I can confirm both the error and the workaround -- looks like the plugin needs to be updated for the latest cellpose release

psobolewskiPhD avatar Apr 04 '24 14:04 psobolewskiPhD

Hi @psobolewskiPhD ,

do you know who is maintaining the plugin? I sent a PR (#51 ) to fix the problem but it looks like nobody is taking a look :/

Best, Johannes

jo-mueller avatar Apr 24 '24 06:04 jo-mueller

Sorry I don't -- for a bit Talley was merging some PR... Maybe we try ping to @carsen-stringer and see what the plan is for this repo.

psobolewskiPhD avatar Apr 24 '24 22:04 psobolewskiPhD

@psobolewskiPhD I already tried that above and didn't get a reply. Maybe @tlambert03 knows who else has maintainer access to this repository and may be inclined to merge fixes?

jo-mueller avatar May 07 '24 08:05 jo-mueller

Yes, I had to downgrade CellPose via pip install cellpose==2.2.3. The old default was net_avg=False, so maybe I can update my code to be future proof? model.eval(gray, diameter=average_diameter_pixs, channels=channels, net_avg=False, augment=True)

keesh0 avatar Jun 13 '24 14:06 keesh0

sorry for the delay this is fixed now

carsen-stringer avatar Sep 13 '24 05:09 carsen-stringer