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

image series annotator not exiting on last image in series #754

Open
lufre1 opened this issue Oct 21, 2024 · 0 comments
Open

image series annotator not exiting on last image in series #754

lufre1 opened this issue Oct 21, 2024 · 0 comments

Comments

@lufre1
Copy link
Contributor

lufre1 commented Oct 21, 2024

when trying to click "next image" while on the last image nothing happens besides following error pops up:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/psygnal/_signal.py:1196, in SignalInstance._run_emit_loop(self=<SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>, args=(False,))
   1195     with Signal._emitting(self):
-> 1196         self._run_emit_loop_inner()
        self = <SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>
        self._run_emit_loop_inner = <bound method SignalInstance._run_emit_loop_immediate of <SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>>
   1197 except RecursionError as e:

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/psygnal/_signal.py:1225, in SignalInstance._run_emit_loop_immediate(self=<SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>)
   1224 for caller in self._slots:
-> 1225     caller.cb(args)
        args = (False,)
        caller = <StrongFunction on magicgui.widgets._function_gui.FunctionGui.__init__.<locals>._disable_button_and_call>

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/psygnal/_weak_callback.py:357, in StrongFunction.cb(self=<StrongFunction on magicgui.widgets._function_gu...onGui.__init__.<locals>._disable_button_and_call>, args=())
    356     args = args[: self._max_args]
--> 357 self._f(*self._args, *args, **self._kwargs)
        args = ()
        self._f = <function FunctionGui.__init__.<locals>._disable_button_and_call at 0x721eb63da980>
        self = <StrongFunction on magicgui.widgets._function_gui.FunctionGui.__init__.<locals>._disable_button_and_call>
        self._args = ()
        self._kwargs = {}

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py:228, in FunctionGui.__init__.<locals>._disable_button_and_call()
    227 try:
--> 228     self.__call__()
        self = <FunctionGui next_image(*args)>
    229 finally:

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py:346, in FunctionGui.__call__(self=<FunctionGui next_image(*args)>, *args=(), **kwargs={})
    345 with _function_name_pointing_to_widget(self):
--> 346     value = self._function(*bound.args, **bound.kwargs)
        self = <FunctionGui next_image(*args)>
        bound = <BoundArguments (args=())>
        self._function = <function image_series_annotator.<locals>.next_image at 0x721ec7f05440>
    348 self._call_count += 1

File ~/Documents/git-repositories/micro-sam/micro_sam/sam_annotator/image_series_annotator.py:233, in image_series_annotator.<locals>.next_image(*args=())
    232 # Save the current segmentation.
--> 233 _save_segmentation(images[next_image_id], next_image_id, segmentation)
        segmentation = array([[0, 0, ..., 0, 0],
       [0, 0, ..., 0, 0],
       ...,
       [0, 0, ..., 0, 0],
       [0, 0, ..., 0, 0]], dtype=uint32)
        next_image_id = 15
        images = ['data/cells/images/001_img.png', 'data/cells/images/008_img.png', 'data/cells/images/009_img.png', 'data/cells/images/011_img.png', 'data/cells/images/018_img.png', 'data/cells/images/019_img.png', 'data/cells/images/028_img.png', 'data/cells/images/034_img.png', 'data/cells/images/040_img.png', 'data/cells/images/042_img.png', 'data/cells/images/043_img.png', 'data/cells/images/045_img.png', 'data/cells/images/046_img.png', 'data/cells/images/048_img.png', 'data/cells/images/050_img.png']
    235 # Clear the segmentation already to avoid lagging removal.

IndexError: list index out of range

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

EmitLoopError                             Traceback (most recent call last)
File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/magicgui/widgets/bases/_value_widget.py:71, in ValueWidget._on_value_change(self=PushButton(value=False, annotation=None, name='call_button'), value=False)
     69 if value is self.null_value and not self._nullable:
     70     return
---> 71 self.changed.emit(value)
        value = False
        self.changed = <SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>
        self = PushButton(value=False, annotation=None, name='call_button')

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/psygnal/_signal.py:1176, in SignalInstance.emit(self=<SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>, check_nargs=False, check_types=False, *args=(False,))
   1172     from ._group import EmissionInfo
   1174     SignalInstance._debug_hook(EmissionInfo(self, args))
-> 1176 self._run_emit_loop(args)
        self = <SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>
        args = (False,)

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/psygnal/_signal.py:1213, in SignalInstance._run_emit_loop(self=<SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>, args=(False,))
   1205     loop_err = EmitLoopError(
   1206         exc=cb_err,
   1207         signal=self,
   (...)
   1210         emit_queue=self._emit_queue,
   1211     ).with_traceback(cb_err.__traceback__)
   1212     # this comment will show up in the traceback
-> 1213     raise loop_err from cb_err  # emit() call ABOVE || callback error BELOW
        loop_err = EmitLoopError("\n\nWhile emitting signal 'magicgui.widgets.PushButton.changed', a IndexError occurred in a callback:\n\n  Signal emitted at: /home/freckmann15/miniforge3/envs/samtest/lib/python3.11/site-packages/magicgui/widgets/bases/_value_widget.py:71, in _on_value_change\n    >  self.changed.emit(value)\n\n  Callback error at: /home/freckmann15/Documents/git-repositories/micro-sam/micro_sam/sam_annotator/image_series_annotator.py:233, in next_image\n    >  _save_segmentation(images[next_image_id], next_image_id, segmentation)\n\n    Local variables:\n       args = ()\n       segmentation = array([[0, 0, 0, ..., 0, 0, 0],\n       [0, 0, 0, ..., 0, 0, ...\n       abort = False\n       _get_save_path = <function image_series_annotator.<locals>._get_save_path at ...\n       _save_segmentation = <function image_series_annotator.<locals>._save_segmentation...\n       annotator = <micro_sam.sam_annotator.annotator_2d.Annotator2d object at ...\n       decoder = DecoderAdapter(\n  (base): ConvBlock2d(\n    (block): Sequenti...\n       device = None\n       embedding_paths = ['embeddings/cells/vit_b_lm/001_img.zarr', 'embeddings/cells...\n       end_msg = 'You have annotated the last image. Do you wish to close nap...\n       halo = None\n       have_inputs_as_arrays = False\n       images = ['data/cells/images/001_img.png', 'data/cells/images/008_img...\n       is_volumetric = False\n       model_type = 'vit_b_lm'\n       next_image_id = 15\n       precompute_amg_state = False\n       predictor = <mobile_sam.predictor.SamPredictor object at 0x721ef0bb8190>\n       skip_segmented = True\n       state = AnnotatorState(image_embeddings={'features': array([[[[-0.01...\n       tile_shape = None\n       viewer = Viewer(camera=Camera(center=(0.0, 215.8179510554866, 260.959...\n\nSee IndexError above for original traceback.")
   1214 finally:
   1215     self._recursion_depth -= 1

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/psygnal/_signal.py:1196, in SignalInstance._run_emit_loop(self=<SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>, args=(False,))
   1192     self._max_recursion_depth = max(
   1193         self._max_recursion_depth, self._recursion_depth
   1194     )
   1195     with Signal._emitting(self):
-> 1196         self._run_emit_loop_inner()
        self = <SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>
        self._run_emit_loop_inner = <bound method SignalInstance._run_emit_loop_immediate of <SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>>
   1197 except RecursionError as e:
   1198     raise RecursionError(
   1199         f"RecursionError when "
   1200         f"emitting signal {self.name!r} with args {args}"
   1201     ) from e

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/psygnal/_signal.py:1225, in SignalInstance._run_emit_loop_immediate(self=<SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>)
   1223 args = self._emit_queue.popleft()
   1224 for caller in self._slots:
-> 1225     caller.cb(args)
        args = (False,)
        caller = <StrongFunction on magicgui.widgets._function_gui.FunctionGui.__init__.<locals>._disable_button_and_call>

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/psygnal/_weak_callback.py:357, in StrongFunction.cb(self=<StrongFunction on magicgui.widgets._function_gu...onGui.__init__.<locals>._disable_button_and_call>, args=())
    355 if self._max_args is not None:
    356     args = args[: self._max_args]
--> 357 self._f(*self._args, *args, **self._kwargs)
        args = ()
        self._f = <function FunctionGui.__init__.<locals>._disable_button_and_call at 0x721eb63da980>
        self = <StrongFunction on magicgui.widgets._function_gui.FunctionGui.__init__.<locals>._disable_button_and_call>
        self._args = ()
        self._kwargs = {}

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py:228, in FunctionGui.__init__.<locals>._disable_button_and_call()
    226 self._call_button.enabled = False
    227 try:
--> 228     self.__call__()
        self = <FunctionGui next_image(*args)>
    229 finally:
    230     self._call_button.enabled = True

File ~/miniforge3/envs/samtest/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py:346, in FunctionGui.__call__(self=<FunctionGui next_image(*args)>, *args=(), **kwargs={})
    344 self._tqdm_depth = 0  # reset the tqdm stack count
    345 with _function_name_pointing_to_widget(self):
--> 346     value = self._function(*bound.args, **bound.kwargs)
        self = <FunctionGui next_image(*args)>
        bound = <BoundArguments (args=())>
        self._function = <function image_series_annotator.<locals>.next_image at 0x721ec7f05440>
    348 self._call_count += 1
    349 if self._result_widget is not None:

File ~/Documents/git-repositories/micro-sam/micro_sam/sam_annotator/image_series_annotator.py:233, in image_series_annotator.<locals>.next_image(*args=())
    230         return
    232 # Save the current segmentation.
--> 233 _save_segmentation(images[next_image_id], next_image_id, segmentation)
        segmentation = array([[0, 0, ..., 0, 0],
       [0, 0, ..., 0, 0],
       ...,
       [0, 0, ..., 0, 0],
       [0, 0, ..., 0, 0]], dtype=uint32)
        next_image_id = 15
        images = ['data/cells/images/001_img.png', 'data/cells/images/008_img.png', 'data/cells/images/009_img.png', 'data/cells/images/011_img.png', 'data/cells/images/018_img.png', 'data/cells/images/019_img.png', 'data/cells/images/028_img.png', 'data/cells/images/034_img.png', 'data/cells/images/040_img.png', 'data/cells/images/042_img.png', 'data/cells/images/043_img.png', 'data/cells/images/045_img.png', 'data/cells/images/046_img.png', 'data/cells/images/048_img.png', 'data/cells/images/050_img.png']
    235 # Clear the segmentation already to avoid lagging removal.
    236 viewer.layers["committed_objects"].data = np.zeros_like(viewer.layers["committed_objects"].data)

EmitLoopError: 

While emitting signal 'magicgui.widgets.PushButton.changed', a IndexError occurred in a callback:

  Signal emitted at: /home/freckmann15/miniforge3/envs/samtest/lib/python3.11/site-packages/magicgui/widgets/bases/_value_widget.py:71, in _on_value_change
    >  self.changed.emit(value)

  Callback error at: /home/freckmann15/Documents/git-repositories/micro-sam/micro_sam/sam_annotator/image_series_annotator.py:233, in next_image
    >  _save_segmentation(images[next_image_id], next_image_id, segmentation)

    Local variables:
       args = ()
       segmentation = array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, ...
       abort = False
       _get_save_path = <function image_series_annotator.<locals>._get_save_path at ...
       _save_segmentation = <function image_series_annotator.<locals>._save_segmentation...
       annotator = <micro_sam.sam_annotator.annotator_2d.Annotator2d object at ...
       decoder = DecoderAdapter(
  (base): ConvBlock2d(
    (block): Sequenti...
       device = None
       embedding_paths = ['embeddings/cells/vit_b_lm/001_img.zarr', 'embeddings/cells...
       end_msg = 'You have annotated the last image. Do you wish to close nap...
       halo = None
       have_inputs_as_arrays = False
       images = ['data/cells/images/001_img.png', 'data/cells/images/008_img...
       is_volumetric = False
       model_type = 'vit_b_lm'
       next_image_id = 15
       precompute_amg_state = False
       predictor = <mobile_sam.predictor.SamPredictor object at 0x721ef0bb8190>
       skip_segmented = True
       state = AnnotatorState(image_embeddings={'features': array([[[[-0.01...
       tile_shape = None
       viewer = Viewer(camera=Camera(center=(0.0, 215.8179510554866, 260.959...

See IndexError above for original traceback.
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

1 participant