napari_pyclesperanto_assistant icon indicating copy to clipboard operation
napari_pyclesperanto_assistant copied to clipboard

Unable to use the assistant on 3d images

Open DirkRemmers opened this issue 3 years ago • 14 comments

Hello,

I recently started working with this amazing tool, and I have to say I like it a lot! It is really powerful to have all the pyclesperanto_prototype functionality in the napari viewer. All the 2d functions are working perfectly fine. However, the one thing that I can't get to work is 3d image processing (which is working fine for me with pyclesperanto_prototype).

Everytime I want to do any sort of operation on a 3d image, I get a big error that looks like this:

2022-02-24 13:23:40.414 | INFO     | napari_pyclesperanto_assistant._gui._category_widget:call_op:124 - cle.gaussian_blur (clesperanto)(..., 1.0, 1.0, 0.0)
2022-02-24 13:23:40.465 | DEBUG    | napari_pyclesperanto_assistant._gui._category_widget:_show_result:223 - creating new layer for id: 140441732163040
Traceback (most recent call last):
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari_pyclesperanto_assistant/_gui/_category_widget.py", line 216, in _show_result
    layer = next(x for x in viewer.layers if isinstance(x.metadata, dict) and x.metadata.get(OP_ID) == op_id)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari_pyclesperanto_assistant/_gui/_Assistant.py", line 171, in _on_item_clicked
    self._activate(CATEGORIES.get(item.text()))
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari_pyclesperanto_assistant/_gui/_Assistant.py", line 202, in _activate
    self._layers[gui()] = (dw, gui)
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/magicgui/widgets/_function_gui.py", line 306, in __call__
    value = self._function(*bound.args, **bound.kwargs)
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari_pyclesperanto_assistant/_gui/_category_widget.py", line 344, in gui_function
    result_layer = _show_result(
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari_pyclesperanto_assistant/_gui/_category_widget.py", line 230, in _show_result
    layer = add_layer(data, **kwargs)
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari/components/viewer_model.py", line 731, in add_image
    layer = Image(data, **kwargs)
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari/layers/image/image.py", line 348, in __init__
    self._update_dims()
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari/layers/base/base.py", line 675, in _update_dims
    self.refresh()
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari/layers/base/base.py", line 1172, in refresh
    self.set_view_slice()
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari/layers/base/base.py", line 922, in set_view_slice
    self._set_view_slice()
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/napari/layers/image/image.py", line 678, in _set_view_slice
    image = self.data[image_indices]
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/pyclesperanto_prototype/_tier0/_array_operators.py", line 305, in __getitem__
    result = range(self, start_x=x_range.start, stop_x=x_range.stop, step_x=x_range.step,
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/pyclesperanto_prototype/_tier0/_plugin_function.py", line 71, in worker_function
    return function(*bound.args, **bound.kwargs)
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/pyclesperanto_prototype/_tier1/_range.py", line 61, in range
    execute(__file__, 'range_x.cl', 'range', destination.shape, parameters)
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/pyclesperanto_prototype/_tier0/_execute.py", line 3, in execute
    return Backend.get_instance().get().execute(anchor, opencl_kernel_filename, kernel_name, global_size, parameters, prog, constants, image_size_independent_kernel_compilation, device)
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/pyclesperanto_prototype/_tier0/_opencl_backend.py", line 41, in execute
    return execute(anchor, opencl_kernel_filename, kernel_name, global_size, parameters, prog, constants, image_size_independent_kernel_compilation, device)
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/pyclesperanto_prototype/_tier0/_opencl_execute.py", line 322, in execute
    prog.run_kernel(kernel_name, tuple(global_size[::-1]), None, *arguments)
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/pyclesperanto_prototype/_tier0/_program.py", line 34, in run_kernel
    self._kernel_dict[name](
  File "/home/dirk/miniconda3/envs/pyclesperanto/lib/python3.9/site-packages/pyopencl/__init__.py", line 896, in kernel_call
    return self._enqueue(self, queue, global_size, local_size, *args, **kwargs)
  File "<pyopencl invoker for 'range'>", line 7, in enqueue_knl_range
pyopencl._cl.LogicError: clSetKernelArg failed: INVALID_ARG_SIZE - when processing arg#13 (1-based): 

Just to be sure I don't have anything wrong in my environment, I made a new environment based on the installation instructions in the readme. The version of napari, the assistant and numpy in this environment are: napari (version = 0.4.14, source = pypi) napari-pyclesperanto-assistant (version = 0.15.4, source = pypi) numpy (version = 1.22.2, source = conda-forge)

This is a MRE to mimic what is wrong:

# use the new environment to run the following:

import numpy as np
import napari

random_array = np.random.random((500,500,500))
test = napari.Viewer()
test.add_image(random_array)
test.dims.ndisplay = 3

# in the napari viewer:
# 1) open the assistant
# 2) select any operation (remove noise for example)
# 3) the error appears and no operation is performed

Hopefully I'm not doing anything wrong here. If you need more information about this issue, please let me know. Thank you in advance for the help, and also thank you for creating such a nice tool!

DirkRemmers avatar Feb 24 '22 13:02 DirkRemmers