juglab / napari-n2v

A self-supervised denoising algorithm.
https://juglab.github.io/napari-n2v/
BSD 3-Clause "New" or "Revised" License
24 stars 3 forks source link

Error while attempting to use plugin #43

Closed pbl007 closed 1 year ago

pbl007 commented 1 year ago

Hello, I am facing the following issues while running the plugin (any option): [please notice that I have python3.10 with TF 2.8.0].


ImportError Traceback (most recent call last) File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/npe2/_command_registry.py:33, in CommandHandler.resolve(self=CommandHandler(id='napari-n2v.make_n2v_trainwidg...'napari_n2v._train_widget:TrainingWidgetWrapper')) 32 try: ---> 33 self.function = utils.import_python_name(self.python_name) self.function = None self.python_name = 'napari_n2v._train_widget:TrainingWidgetWrapper' self = CommandHandler(id='napari-n2v.make_n2v_trainwidget', function=None, python_name='napari_n2v._train_widget:TrainingWidgetWrapper') utils = <module 'npe2.manifest.utils' from '/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/npe2/manifest/utils.py'> 34 except Exception as e:

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/npe2/manifest/utils.py:255, in import_python_name(python_name='napari_n2v._train_widget:TrainingWidgetWrapper') 253 module_name, funcname = match.groups() # type: ignore [union-attr] --> 255 mod = import_module(module_name) module_name = 'napari_n2v._train_widget' 256 return getattr(mod, funcname)

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/importlib/init.py:126, in import_module(name='napari_n2v._train_widget', package=None) 125 level += 1 --> 126 return _bootstrap._gcd_import(name[level:], package, level) level = 0 name = 'napari_n2v._train_widget' name[level:] = 'napari_n2v._train_widget' package = None _bootstrap = <module '_frozen_importlib' (frozen)>

File :1050, in _gcd_import(name='napari_n2v._train_widget', package=None, level=0)

File :1027, in _find_and_load(name='napari_n2v._trainwidget', import=)

File :992, in _find_and_load_unlocked(name='napari_n2v._trainwidget', import=)

File :241, in _call_with_frames_removed(f=, *args=('napari_n2v',), **kwds={})

File :1050, in _gcd_import(name='napari_n2v', package=None, level=0)

File :1027, in _find_and_load(name='naparin2v', import=)

File :1006, in _find_and_load_unlocked(name='naparin2v', import=)

File :688, in _load_unlocked(spec=ModuleSpec(name='napari_n2v', loader=<_frozen_im...ri-n2v/lib/python3.10/site-packages/napari_n2v']))

File :883, in exec_module(self=<_frozen_importlib_external.SourceFileLoader object>, module=<module 'napari_n2v' from '/opt/miniconda3/envs/...python3.10/site-packages/napari_n2v/init.py'>)

File :241, in _call_with_frames_removed(f=, *args=(<code object at 0x7f2ffb627680, file "/...10/site-packages/napari_n2v/init.py", line 1>, {'builtins': {'ArithmeticError': <class 'ArithmeticError'>, 'AssertionError': <class 'AssertionError'>, 'AttributeError': <class 'AttributeError'>, 'BaseException': <class 'BaseException'>, 'BlockingIOError': <class 'BlockingIOError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'BufferError': <class 'BufferError'>, 'BytesWarning': <class 'BytesWarning'>, 'ChildProcessError': <class 'ChildProcessError'>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, ...}, 'cached': '/opt/miniconda3/envs/napari-n2v/lib/python3.10/s...s/napari_n2v/pycache/init.cpython-310.pyc', 'doc': None, 'file': '/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari_n2v/init.py', 'loader': <_frozen_importlib_external.SourceFileLoader object>, 'name': 'napari_n2v', 'package': 'napari_n2v', 'path': ['/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari_n2v'], 'spec': ModuleSpec(name='napari_n2v', loader=<_frozen_im...ri-n2v/lib/python3.10/site-packages/napari_n2v']), 'version': '0.0.1'}), **kwds={})

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari_n2v/init.py:3 1 version = "0.0.1" ----> 3 from ._sample_data import n2v_2D_data, n2v_3D_data, n2v_rgb_data, n2v_sem_data, demo_files 4 from ._train_widget import TrainingWidgetWrapper

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari_n2v/_sample_data.py:11 9 from napari.utils import notifications as ntf ---> 11 from napari_n2v.utils import cwd, get_default_path 13 # todo the logic is the same for all functions, possibility to refactor

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari_n2v/utils/init.py:2 ----> 2 from .n2v_utils import ( 3 create_model, 4 filter_dimensions, 5 are_axes_valid, 6 build_modelzoo, 7 reshape_data, 8 get_size_from_shape, 9 get_images_count, 10 reshape_napari, 11 create_config, 12 get_napari_shapes, 13 get_shape_order, 14 get_default_path 15 ) 16 from .load_images_utils import ( 17 load_and_reshape, 18 load_from_disk, 19 lazy_load_generator, 20 )

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari_n2v/utils/n2v_utils.py:15 13 from napari.utils import notifications as ntf ---> 15 from n2v.models import N2V, N2VConfig 17 from napari_n2v.resources import DOC_BIOIMAGE

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/n2v/models/init.py:4 3 # imports ----> 4 from .n2v_config import N2VConfig 5 from .n2v_standard import N2V

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/n2v/models/n2v_config.py:3 1 import argparse ----> 3 import tensorflow.keras.backend as K 5 from csbdeep.utils import _raise, axes_check_and_normalize, axes_dict, backend_channels_last

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/keras/api/_v2/keras/init.py:8 6 import sys as _sys ----> 8 from keras import version 9 from keras.api._v2.keras import internal

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/keras/init.py:25 24 # See b/110718070#comment18 for more details about this import. ---> 25 from keras import models 27 from keras.engine.input_layer import Input

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/keras/models.py:19 18 import tensorflow.compat.v2 as tf ---> 19 from keras import backend 20 from keras import metrics as metrics_module

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/keras/backend/init.py:1 ----> 1 from .load_backend import epsilon 2 from .load_backend import set_epsilon

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/keras/backend/load_backend.py:90 89 sys.stderr.write('Using TensorFlow backend.\n') ---> 90 from .tensorflow_backend import * 91 else: 92 # Try and load external backend.

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/keras/backend/tensorflow_backend.py:25 23 from distutils.version import StrictVersion ---> 25 from ..utils.generic_utils import transpose_shape 27 py_all = all

ImportError: cannot import name 'transpose_shape' from 'keras.utils.generic_utils' (/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/keras/utils/generic_utils.py)

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last) File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari/_qt/menus/plugins_menu.py:97, in PluginsMenu._add_plugin_actions.._add_toggle_widget(key=('napari-n2v', 'N2V Train'), hook_type='dock') 94 return 96 if hook_type == 'dock': ---> 97 dock_widget, _w = self._win.add_plugin_dock_widget(key) key = ('napari-n2v', 'N2V Train') self._win = <napari._qt.qt_main_window.Window object at 0x7f2babf17fa0> self = <napari._qt.menus.plugins_menu.PluginsMenu object at 0x7f294101b2e0> 98 else: 99 dock_widget = self._win._add_plugin_function_widget(key)

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari/_qt/qt_main_window.py:664, in Window.add_plugin_dock_widget(self=, plugin_name='napari-n2v', widget_name='N2V Train') 661 Widget = None 662 dock_kwargs = {} --> 664 result = _npe2.get_widget_contribution(plugin_name, widget_name) plugin_name = 'napari-n2v' widget_name = 'N2V Train' _npe2 = <module 'napari.plugins._npe2' from '/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari/plugins/_npe2.py'> 665 if result: 666 Widget, widget_name = result

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari/plugins/_npe2.py:108, in get_widget_contribution(plugin_name='napari-n2v', widget_name='N2V Train') 106 if contrib.plugin_name == plugin_name: 107 if not widget_name or contrib.display_name == widget_name: --> 108 return contrib.get_callable(), contrib.display_name contrib = WidgetContribution(command='napari-n2v.make_n2v_trainwidget', display_name='N2V Train', autogenerate=False) contrib.display_name = 'N2V Train' 109 widgets_seen.add(contrib.display_name) 110 if widget_name and widgets_seen:

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/npe2/manifest/contributions/_widgets.py:50, in WidgetContribution.get_callable(self=WidgetContribution(command='napari-n2v.maken2v...t', display_name='N2V Train', autogenerate=False), _registry=None) 47 def get_callable( 48 self, _registry: Optional[CommandRegistry] = None 49 ) -> Callable[..., Widget]: ---> 50 func = super().get_callable() 51 if self.autogenerate: 52 try:

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/npe2/manifest/utils.py:72, in Executable.get_callable(self=WidgetContribution(command='napari-n2v.maken2v...t', display_name='N2V Train', autogenerate=False), _registry=) 69 from .._plugin_manager import PluginManager 71 _registry = PluginManager.instance().commands ---> 72 return _registry.get(self.command) _registry = <npe2._command_registry.CommandRegistry object at 0x7f2bb2f7e830> self.command = 'napari-n2v.make_n2v_trainwidget' self = WidgetContribution(command='napari-n2v.make_n2v_trainwidget', display_name='N2V Train', autogenerate=False)

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/npe2/_command_registry.py:132, in CommandRegistry.get(self=, id='napari-n2v.make_n2v_trainwidget') 130 if id not in self._commands: # sourcery skip 131 raise KeyError(f"command {id!r} not registered") --> 132 return self._commands[id].resolve() id = 'napari-n2v.make_n2v_trainwidget' self._commands = {'napari-n2v.make_n2v_trainwidget': CommandHandler(id='napari-n2v.make_n2v_trainwidget', function=None, python_name='napari_n2v._train_widget:TrainingWidgetWrapper'), 'napari-n2v.make_n2v_predictwidget': CommandHandler(id='napari-n2v.make_n2v_predictwidget', function=None, python_name='napari_n2v._predict_widget:PredictWidgetWrapper'), 'napari-n2v.make_n2v_demo_prediction': CommandHandler(id='napari-n2v.make_n2v_demo_prediction', function=None, python_name='napari_n2v._predict_widget:DemoPrediction'), 'napari-n2v.data_2D': CommandHandler(id='napari-n2v.data_2D', function=None, python_name='napari_n2v._sample_data:n2v_2D_data'), 'napari-n2v.data_3D': CommandHandler(id='napari-n2v.data_3D', function=None, python_name='napari_n2v._sample_data:n2v_3D_data'), 'napari-n2v.data_RGB': CommandHandler(id='napari-n2v.data_RGB', function=None, python_name='napari_n2v._sample_data:n2v_rgb_data'), 'napari-n2v.data_SEM': CommandHandler(id='napari-n2v.data_SEM', function=None, python_name='napari_n2v._sample_data:n2v_sem_data')} self = <npe2._command_registry.CommandRegistry object at 0x7f2bb2f7e830> self._commands[id] = CommandHandler(id='napari-n2v.make_n2v_trainwidget', function=None, python_name='napari_n2v._train_widget:TrainingWidgetWrapper')

File /opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/npe2/_command_registry.py:35, in CommandHandler.resolve(self=CommandHandler(id='napari-n2v.make_n2v_trainwidg...'napari_n2v._train_widget:TrainingWidgetWrapper')) 33 self.function = utils.import_python_name(self.python_name) 34 except Exception as e: ---> 35 raise RuntimeError( self.python_name = 'napari_n2v._train_widget:TrainingWidgetWrapper' self = CommandHandler(id='napari-n2v.make_n2v_trainwidget', function=None, python_name='napari_n2v._train_widget:TrainingWidgetWrapper') 36 f"Failed to import command at {self.python_name!r}: {e}" 37 ) from e 39 return self.function

RuntimeError: Failed to import command at 'napari_n2v._train_widget:TrainingWidgetWrapper': cannot import name 'transpose_shape' from 'keras.utils.generic_utils' (/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/keras/utils/generic_utils.py) ^CTraceback (most recent call last): File "/opt/miniconda3/envs/napari-n2v/bin/napari", line 8, in sys.exit(main()) File "/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari/main.py", line 447, in main _run() File "/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari/main.py", line 336, in _run run(gui_exceptions=True) File "/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari/_qt/qt_event_loop.py", line 401, in run with notification_manager, _maybe_allow_interrupt(app): File "/opt/miniconda3/envs/napari-n2v/lib/python3.10/contextlib.py", line 142, in exit next(self.gen) File "/opt/miniconda3/envs/napari-n2v/lib/python3.10/site-packages/napari/_qt/utils.py", line 459, in _maybe_allow_interrupt old_sigint_handler(*handler_args) KeyboardInterrupt

jdeschamps commented 1 year ago

Hi,

Thank you for your feedback. Could you show the result of conda list, so that we can look at your environment?

I managed to reproduce the problem, which seems to be due to the fact that tensorflow==2.8 installs protobuf=4.21 or at least protobuf>=4. A way around it is to do:

pip install protobuf==3.20

We will issue a fix in the next days.

jdeschamps commented 1 year ago

https://github.com/juglab/napari-n2v/pull/44

I now added the correct protobof version range to the requirements, so the plugin can be used with TF2.8 to TF2.10.

pbl007 commented 1 year ago

Fantastic. I'll reinstall!! Thanks a lot!

jdeschamps commented 1 year ago

Note that the fix will only be available in the next version on pip. We plan for a release early next week.

Otherwise you will have to install it from source.