Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_masks interface changed from cellpose 1.x to 2.x #41

Open
aeisenbarth opened this issue Oct 26, 2022 · 2 comments
Open

get_masks interface changed from cellpose 1.x to 2.x #41

aeisenbarth opened this issue Oct 26, 2022 · 2 comments

Comments

@aeisenbarth
Copy link

When clicking "recompute last masks with new cellprob + model match", I get the error:

File …/lib/python3.8/site-packages/cellpose_napari/_dock_widget.py:116, in widget_wrapper.<locals>.compute_masks(masks_orig=<class 'numpy.ndarray'> (1000, 1000) uint16, flows_orig=[<class 'numpy.ndarray'> (1560, 1560, 3) uint8, <class 'numpy.ndarray'> (2, 1560, 1560) float32, <class 'numpy.ndarray'> (1560, 1560) float32, <class 'numpy.ndarray'> (2, 1560, 1560) float32], cellprob_threshold=8.0, model_match_threshold=27.0)
    114     logger.debug('flow_threshold=0 => no masks thrown out due to model mismatch')
    115 logger.debug(f'computing masks with cellprob_threshold={cellprob_threshold}, flow_threshold={flow_threshold}')
--> 116 maski = get_masks(flows_orig[3].copy(), iscell=(flows_orig[2] > cellprob_threshold),
        flows_orig[3] = <class 'numpy.ndarray'> (2, 1560, 1560) float32
        flows_orig[2] = <class 'numpy.ndarray'> (1560, 1560) float32
        cellprob_threshold = 8.0
        flows_orig = [<class 'numpy.ndarray'> (1560, 1560, 3) uint8, <class 'numpy.ndarray'> (2, 1560, 1560) float32, <class 'numpy.ndarray'> (1560, 1560) float32, <class 'numpy.ndarray'> (2, 1560, 1560) float32]
        flow_threshold = 0.4
        flows_orig[1] = <class 'numpy.ndarray'> (2, 1560, 1560) float32
        masks_orig = <class 'numpy.ndarray'> (1000, 1000) uint16
    117                 flows=flows_orig[1], threshold=flow_threshold*(masks_orig.ndim<3))
    118 maski = fill_holes_and_remove_small_masks(maski)
    119 maski = resize_image(maski, masks_orig.shape[-2], masks_orig.shape[-1],
    120                                 interpolation=cv2.INTER_NEAREST)

TypeError: get_masks() got an unexpected keyword argument 'flows'

Environment:
cellpose 1.0.2
cellpose-napari 0.1.5
napari 0.4.16
napari-plugin-engine 0.2.0

This is caused by the removal of the flows argument in the get_masks function in the transition from cellpose 1.x to 2.0. However, the requirements cellpose>=0.6.2 currently pull the latest package version. The current code would need to specify an upper limit cellpose>=0.6.2,<2, or be updated to the new interface.

Workaround:
Install cellpose==1.0.2

@sebherbert
Copy link
Contributor

Hi,

I've encountered the same problem.
Thanks for your workaround, I've forced the install of cellpose==1.0.2 as you suggested and it removed the get_mask TypeError. Unfortunately it still failed with the following error:

error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
>  - src data type = 8 is not supported
>  - Expected Ptr<cv::UMat> for argument 'src'

If it can be of use, I'm copying the full report

Full report

(base) PS C:> conda activate cellpose_napari
(cellpose_napari) PS C:> napari -w cellpose-napari
100%|█████████████████████████████████████████████████████████████████████████████| 25.3M/25.3M [00:02<00:00, 11.2MB/s]
100%|█████████████████████████████████████████████████████████████████████████████| 25.3M/25.3M [00:01<00:00, 17.5MB/s]
100%|█████████████████████████████████████████████████████████████████████████████| 25.3M/25.3M [00:01<00:00, 14.3MB/s]
100%|█████████████████████████████████████████████████████████████████████████████| 25.3M/25.3M [00:02<00:00, 11.9MB/s]
11:49:07 WARNING cellprob_threshold and dist_threshold are being deprecated in a future release, use mask_threshold instead

error Traceback (most recent call last)
File C:\Program Files\Anaconda3\envs\cellpose_napari\lib\site-packages\superqt\utils_qthreading.py:617, in create_worker..reraise(e=error("OpenCV(4.7.0) 👎 error: (-5:Bad argumen... - Expected Ptrcv::UMat for argument 'src'\n"))
616 def reraise(e):
--> 617 raise e
e = error("OpenCV(4.7.0) 👎 error: (-5:Bad argument) in function 'resize'\n> Overload resolution failed:\n> - src data type = 8 is not supported\n> - Expected Ptrcv::UMat for argument 'src'\n")

File C:\Program Files\Anaconda3\envs\cellpose_napari\lib\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 0x000001702A5F2430>
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 C:\Program Files\Anaconda3\envs\cellpose_napari\lib\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..compute_masks at 0x0000016FE3CE2AF0>
self = <napari._qt.qthreading.FunctionWorker object at 0x000001702A5F2430>
self._args = (<class 'numpy.ndarray'> (151, 658, 818) uint16, [<class 'numpy.ndarray'> (151, 658, 818, 3) uint8, <class 'numpy.ndarray'> (3, 151, 658, 818) float32, <class 'numpy.ndarray'> (151, 658, 818) float32, <class 'numpy.ndarray'> (3, 151, 658, 818) float32, None, []], 0.0, 15.882353)
self._kwargs = {}

File C:\Program Files\Anaconda3\envs\cellpose_napari\lib\site-packages\cellpose_napari_dock_widget.py:119, in widget_wrapper..compute_masks(masks_orig=<class 'numpy.ndarray'> (151, 658, 818) uint16, flows_orig=[<class 'numpy.ndarray'> (151, 658, 818, 3) uint8, <class 'numpy.ndarray'> (3, 151, 658, 818) float32, <class 'numpy.ndarray'> (151, 658, 818) float32, <class 'numpy.ndarray'> (3, 151, 658, 818) float32, None, []], cellprob_threshold=0.0, model_match_threshold=15.882353)
116 maski = get_masks(flows_orig[3].copy(), iscell=(flows_orig[2] > cellprob_threshold),
117 flows=flows_orig[1], threshold=flow_threshold*(masks_orig.ndim<3))
118 maski = fill_holes_and_remove_small_masks(maski)
--> 119 maski = resize_image(maski, masks_orig.shape[-2], masks_orig.shape[-1],
maski = <class 'numpy.ndarray'> (151, 658, 818) uint32
masks_orig = <class 'numpy.ndarray'> (151, 658, 818) uint16
cv2.INTER_NEAREST = 0
120 interpolation=cv2.INTER_NEAREST)
121 return maski

File C:\Program Files\Anaconda3\envs\cellpose_napari\lib\site-packages\cellpose\transforms.py:561, in resize_image(img0=<class 'numpy.ndarray'> (151, 658, 818) uint32, Ly=658, Lx=818, rsz=None, interpolation=0, no_channels=False)
559 imgs[i] = cv2.resize(img, (Lx, Ly), interpolation=interpolation)
560 else:
--> 561 imgs = cv2.resize(img0, (Lx, Ly), interpolation=interpolation)
Ly = 658
Lx = 818
img0 = <class 'numpy.ndarray'> (151, 658, 818) uint32
(Lx, Ly) = (818, 658)
interpolation = 0
562 return imgs

error: OpenCV(4.7.0) 👎 error: (-5:Bad argument) in function 'resize'

Overload resolution failed:

  • src data type = 8 is not supported
  • Expected Ptrcv::UMat for argument 'src'

@psobolewskiPhD
Copy link
Contributor

I can confirm this on cellpose 2.2.3
Traceback:

TypeError                                 Traceback (most recent call last)
File ~/micromamba/envs/cellpose/lib/python3.10/site-packages/superqt/utils/_qthreading.py:617, in create_worker.<locals>.reraise(e=TypeError("get_masks() got an unexpected keyword argument 'flows'"))
    616 def reraise(e):
--> 617     raise e
        e = TypeError("get_masks() got an unexpected keyword argument 'flows'")

File ~/micromamba/envs/cellpose/lib/python3.10/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 0x2b3635a20>
    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 ~/micromamba/envs/cellpose/lib/python3.10/site-packages/superqt/utils/_qthreading.py:358, in FunctionWorker.work(self=<napari._qt.qthreading.FunctionWorker object>)
    357 def work(self) -> _R:
--> 358     return self._func(*self._args, **self._kwargs)
        self._func = <function widget_wrapper.<locals>.compute_masks at 0x2b2f93250>
        self = <napari._qt.qthreading.FunctionWorker object at 0x2b3635a20>
        self._args = (<class 'numpy.ndarray'> (383, 512) uint16, [<class 'numpy.ndarray'> (383, 512, 3) uint8, <class 'numpy.ndarray'> (2, 383, 512) float32, <class 'numpy.ndarray'> (383, 512) float32, <class 'numpy.ndarray'> (2, 383, 512) float32], 0.0, 23.625)
        self._kwargs = {}

File ~/micromamba/envs/cellpose/lib/python3.10/site-packages/cellpose_napari/_dock_widget.py:116, in widget_wrapper.<locals>.compute_masks(masks_orig=<class 'numpy.ndarray'> (383, 512) uint16, flows_orig=[<class 'numpy.ndarray'> (383, 512, 3) uint8, <class 'numpy.ndarray'> (2, 383, 512) float32, <class 'numpy.ndarray'> (383, 512) float32, <class 'numpy.ndarray'> (2, 383, 512) float32], cellprob_threshold=0.0, model_match_threshold=23.625)
    114     logger.debug('flow_threshold=0 => no masks thrown out due to model mismatch')
    115 logger.debug(f'computing masks with cellprob_threshold={cellprob_threshold}, flow_threshold={flow_threshold}')
--> 116 maski = get_masks(flows_orig[3].copy(), iscell=(flows_orig[2] > cellprob_threshold),
        cellprob_threshold = 0.0
        flows_orig[3] = <class 'numpy.ndarray'> (2, 383, 512) float32
        flows_orig[2] = <class 'numpy.ndarray'> (383, 512) float32
        flows_orig = [<class 'numpy.ndarray'> (383, 512, 3) uint8, <class 'numpy.ndarray'> (2, 383, 512) float32, <class 'numpy.ndarray'> (383, 512) float32, <class 'numpy.ndarray'> (2, 383, 512) float32]
        flow_threshold = 0.7375
        flows_orig[1] = <class 'numpy.ndarray'> (2, 383, 512) float32
        masks_orig = <class 'numpy.ndarray'> (383, 512) uint16
    117                 flows=flows_orig[1], threshold=flow_threshold*(masks_orig.ndim<3))
    118 maski = fill_holes_and_remove_small_masks(maski)
    119 maski = resize_image(maski, masks_orig.shape[-2], masks_orig.shape[-1],
    120                                 interpolation=cv2.INTER_NEAREST)

TypeError: get_masks() got an unexpected keyword argument 'flows'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~/micromamba/envs/cellpose/lib/python3.10/site-packages/superqt/utils/_qthreading.py:617, in create_worker.<locals>.reraise(e=TypeError("get_masks() got an unexpected keyword argument 'flows'"))
    616 def reraise(e):
--> 617     raise e
        e = TypeError("get_masks() got an unexpected keyword argument 'flows'")

File ~/micromamba/envs/cellpose/lib/python3.10/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 0x2e7ff0af0>
    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 ~/micromamba/envs/cellpose/lib/python3.10/site-packages/superqt/utils/_qthreading.py:358, in FunctionWorker.work(self=<napari._qt.qthreading.FunctionWorker object>)
    357 def work(self) -> _R:
--> 358     return self._func(*self._args, **self._kwargs)
        self._func = <function widget_wrapper.<locals>.compute_masks at 0x2b2f93250>
        self = <napari._qt.qthreading.FunctionWorker object at 0x2e7ff0af0>
        self._args = (<class 'numpy.ndarray'> (383, 512) uint16, [<class 'numpy.ndarray'> (383, 512, 3) uint8, <class 'numpy.ndarray'> (2, 383, 512) float32, <class 'numpy.ndarray'> (383, 512) float32, <class 'numpy.ndarray'> (2, 383, 512) float32], 0.0, 23.625)
        self._kwargs = {}

File ~/micromamba/envs/cellpose/lib/python3.10/site-packages/cellpose_napari/_dock_widget.py:116, in widget_wrapper.<locals>.compute_masks(masks_orig=<class 'numpy.ndarray'> (383, 512) uint16, flows_orig=[<class 'numpy.ndarray'> (383, 512, 3) uint8, <class 'numpy.ndarray'> (2, 383, 512) float32, <class 'numpy.ndarray'> (383, 512) float32, <class 'numpy.ndarray'> (2, 383, 512) float32], cellprob_threshold=0.0, model_match_threshold=23.625)
    114     logger.debug('flow_threshold=0 => no masks thrown out due to model mismatch')
    115 logger.debug(f'computing masks with cellprob_threshold={cellprob_threshold}, flow_threshold={flow_threshold}')
--> 116 maski = get_masks(flows_orig[3].copy(), iscell=(flows_orig[2] > cellprob_threshold),
        cellprob_threshold = 0.0
        flows_orig[3] = <class 'numpy.ndarray'> (2, 383, 512) float32
        flows_orig[2] = <class 'numpy.ndarray'> (383, 512) float32
        flows_orig = [<class 'numpy.ndarray'> (383, 512, 3) uint8, <class 'numpy.ndarray'> (2, 383, 512) float32, <class 'numpy.ndarray'> (383, 512) float32, <class 'numpy.ndarray'> (2, 383, 512) float32]
        flow_threshold = 0.7375
        flows_orig[1] = <class 'numpy.ndarray'> (2, 383, 512) float32
        masks_orig = <class 'numpy.ndarray'> (383, 512) uint16
    117                 flows=flows_orig[1], threshold=flow_threshold*(masks_orig.ndim<3))
    118 maski = fill_holes_and_remove_small_masks(maski)
    119 maski = resize_image(maski, masks_orig.shape[-2], masks_orig.shape[-1],
    120                                 interpolation=cv2.INTER_NEAREST)

TypeError: get_masks() got an unexpected keyword argument 'flows'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants