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

microsam crashes when commit path is set #868

Open
Jintram opened this issue Feb 18, 2025 · 3 comments
Open

microsam crashes when commit path is set #868

Jintram opened this issue Feb 18, 2025 · 3 comments

Comments

@Jintram
Copy link

Jintram commented Feb 18, 2025

Hi microsam team,

Great work, many thanks for this!

Just wanted to report a crash I experience:

When trying microsam with a simple example image of some fluorescently labeled cells, I can use everything with relative ease. (I'm now working through the tutorial & documentation.)
However, when I set a "commit path", and press "commit [c]", the program crashses.

Workflow:

  • I use the conda installation as in the documentation. I run python from terminal, and execute the following lines to get started:
# Libs
import napari
import numpy as np
from skimage import io

# Load example image
img_toseg = io.imread('/Users/m.wehrens/Data_UVA/example-datasets/HeLa-Cells-MW/example_cell_image.tif')
# Downsize image for ease of working
img_toseg_tile = img_toseg[:3000:2, :3000:2]
# Create the viewer and add the image
viewer = napari.view_image(np.log(img_toseg_tile), name='toseg_log', opacity=1)
  • Using plugins > microsam, I open the annotator 2D.
  • I compute embeddings using the "vit_t" model.
  • I add some rectangular prompts.
  • Press segment
  • When I commit without "commit path" set, it works fine.
  • When I commit with "commit path" set, the program crashes.

My system is the following:

System: Apple M4 Max (36 GB), MacOS: 15.1 (24B2082)

I get the following error report:

>>> 2025-02-18 12:10:48.758 python[5897:144028] The class 'NSOpenPanel' overrides the method identifier.  This method is implemented by class 'NSWindow'
Using apple MPS device.
Computed embeddings for vit_t
WARNING: Traceback (most recent call last):
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1279, in _run_emit_loop
    self._run_emit_loop_inner()
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1308, in _run_emit_loop_immediate
    caller.cb(args)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_weak_callback.py", line 358, in cb
    self._f(*self._args, *args, **self._kwargs)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py", line 235, in _disable_button_and_call
    self.__call__()  # type: ignore [call-arg]
    ^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py", line 351, in __call__
    value = self._function(*bound.args, **bound.kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 502, in commit
    _commit_to_file(commit_path, viewer, layer, seg, mask, bb)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 471, in _commit_to_file
    write_prompts(
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 442, in write_prompts
    g = f.create_group(f"prompts/{object_id}")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/z5py/group.py", line 133, in create_group
    raise KeyError("An object with name %s already exists" % name)
KeyError: 'An object with name prompts/4 already exists'

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

Traceback (most recent call last):
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/bases/_value_widget.py", line 69, in _on_value_change
    self.changed.emit(value)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1201, in emit
    self._run_emit_loop(args)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1296, in _run_emit_loop
    raise loop_err from cb_err  # emit() call ABOVE || callback error BELOW
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1279, in _run_emit_loop
    self._run_emit_loop_inner()
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1308, in _run_emit_loop_immediate
    caller.cb(args)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_weak_callback.py", line 358, in cb
    self._f(*self._args, *args, **self._kwargs)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py", line 235, in _disable_button_and_call
    self.__call__()  # type: ignore [call-arg]
    ^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py", line 351, in __call__
    value = self._function(*bound.args, **bound.kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 502, in commit
    _commit_to_file(commit_path, viewer, layer, seg, mask, bb)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 471, in _commit_to_file
    write_prompts(
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 442, in write_prompts
    g = f.create_group(f"prompts/{object_id}")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/z5py/group.py", line 133, in create_group
    raise KeyError("An object with name %s already exists" % name)
psygnal.EmitLoopError: 

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

  KeyError: 'An object with name prompts/4 already exists'
  --------------------------------------------------------

  SIGNAL EMISSION: 
    /Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/bases/_value_widget.py:69 in _on_value_change
      self.changed.emit(value)  # <-- SIGNAL WAS EMITTED HERE

  CALLBACK CHAIN:
    /Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py:235 in _disable_button_and_call
    ... 4 more frames ...
    /Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/z5py/group.py:133 in create_group
      raise KeyError("An object with name %s already exists" % name)  # <-- ERROR OCCURRED HERE 

      Local variables:
                name = 'prompts/4'
WARNING:vispy:Traceback (most recent call last):
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1279, in _run_emit_loop
    self._run_emit_loop_inner()
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1308, in _run_emit_loop_immediate
    caller.cb(args)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_weak_callback.py", line 358, in cb
    self._f(*self._args, *args, **self._kwargs)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py", line 235, in _disable_button_and_call
    self.__call__()  # type: ignore [call-arg]
    ^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py", line 351, in __call__
    value = self._function(*bound.args, **bound.kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 502, in commit
    _commit_to_file(commit_path, viewer, layer, seg, mask, bb)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 471, in _commit_to_file
    write_prompts(
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 442, in write_prompts
    g = f.create_group(f"prompts/{object_id}")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/z5py/group.py", line 133, in create_group
    raise KeyError("An object with name %s already exists" % name)
KeyError: 'An object with name prompts/4 already exists'

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

Traceback (most recent call last):
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/bases/_value_widget.py", line 69, in _on_value_change
    self.changed.emit(value)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1201, in emit
    self._run_emit_loop(args)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1296, in _run_emit_loop
    raise loop_err from cb_err  # emit() call ABOVE || callback error BELOW
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1279, in _run_emit_loop
    self._run_emit_loop_inner()
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_signal.py", line 1308, in _run_emit_loop_immediate
    caller.cb(args)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/psygnal/_weak_callback.py", line 358, in cb
    self._f(*self._args, *args, **self._kwargs)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py", line 235, in _disable_button_and_call
    self.__call__()  # type: ignore [call-arg]
    ^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py", line 351, in __call__
    value = self._function(*bound.args, **bound.kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 502, in commit
    _commit_to_file(commit_path, viewer, layer, seg, mask, bb)
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 471, in _commit_to_file
    write_prompts(
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/micro_sam/sam_annotator/_widgets.py", line 442, in write_prompts
    g = f.create_group(f"prompts/{object_id}")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/z5py/group.py", line 133, in create_group
    raise KeyError("An object with name %s already exists" % name)
psygnal.EmitLoopError: 

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

  KeyError: 'An object with name prompts/4 already exists'
  --------------------------------------------------------

  SIGNAL EMISSION: 
    /Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/bases/_value_widget.py:69 in _on_value_change
      self.changed.emit(value)  # <-- SIGNAL WAS EMITTED HERE

  CALLBACK CHAIN:
    /Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/magicgui/widgets/_function_gui.py:235 in _disable_button_and_call
    ... 4 more frames ...
    /Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/site-packages/z5py/group.py:133 in create_group
      raise KeyError("An object with name %s already exists" % name)  # <-- ERROR OCCURRED HERE 

      Local variables:
                name = 'prompts/4'
zsh: abort      python
/Users/m.wehrens/miniconda3/envs/2025_microsam/lib/python3.11/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
@anwai98
Copy link
Contributor

anwai98 commented Feb 18, 2025

Hi @Jintram,

Thanks for your interest in micro-sam. The feature to store the committed prompts is still a WIP (see #408). It's good that you reported the issue, we will investigate this and come back to you!

In general, is this a feature you are interest in for some specific reason? (if not, I suggest to avoid committing the prompts for now and continue with your segmentation workflow).

Let me know if you come across any other issues!

@Jintram
Copy link
Author

Jintram commented Feb 18, 2025

Hi Anwai,

Thanks for your very fast reply!

In general, is this a feature you are interest in for some specific reason?

I am still in the stage were I'm trying to figure out how your software works (going through the tutorials right now), and I thought that the "commit path" would allow me to save the segmentation, similar to the "embeddings save path" (which is a really convenient feature if I want to quickly show microsam features to other people, or continue working on a segmentation later).

However, I now realize I can save my segmentation in a better way, via the menu and "file > save selected layers".

In general, I was using the "commit" feature as this was suggested in the Youtube tutorial video:

Some context: In the future, I was also hoping to potentially apply some transfer learning to tune the model further for my own dataset. But I really have to delve into this subject matter further. That's the reason I was diligently following the tutorial for now. I see there's also notes about this in the documentation (https://computational-cell-analytics.github.io/micro-sam/micro_sam.html#fine-tuning-questions). But I think this is probably unrelated to this current issue.

Anyways, many thanks for your quick answer!

Best, Martijn

@constantinpape
Copy link
Contributor

Thank you for the report and context @Jintram ! We will look into fixing the commit path in one of the next releases.

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