Run automatic segmentation with SAM. This can take a few minutes ...
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File .../lib/python3.10/site-packages/napari/utils/events/containers/_typed.py:140, in TypedMutableSequence.__getitem__(self=[<Image layer 'DAPI' at 0x1696a8eb0>, <Labels la...9d4610>, <Points layer 'prompts' at 0x33da3bd90>], key='raw')
139 try:
--> 140 return self.__getitem__(self.index(key))
key = 'raw'
self = [<Image layer 'DAPI' at 0x1696a8eb0>, <Labels layer 'auto_segmentation' at 0x330020100>, <Labels layer 'committed_objects' at 0x33bb89570>, <Labels layer 'current_object' at 0x33d9d4610>, <Points layer 'prompts' at 0x33da3bd90>]
141 except ValueError as e:
File .../lib/python3.10/site-packages/napari/utils/events/containers/_typed.py:228, in TypedMutableSequence.index(self=[<Image layer 'DAPI' at 0x1696a8eb0>, <Labels la...9d4610>, <Points layer 'prompts' at 0x33da3bd90>], value='raw', start=0, stop=None)
226 return i
--> 228 raise ValueError(
trans = <napari.utils.translations.TranslationBundle object at 0x13124af50>
value = 'raw'
229 trans._(
230 "{value!r} is not in list",
231 deferred=True,
232 value=value,
233 )
234 )
ValueError: 'raw' is not in list
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
File .../lib/python3.10/site-packages/psygnal/_signal.py:972, in SignalInstance._run_emit_loop(self=<SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>, args=(False,))
971 try:
--> 972 caller.cb(args)
caller = <psygnal._weak_callback._StrongFunction object at 0x169631c00>
args = (False,)
973 except Exception as e:
File .../lib/python3.10/site-packages/psygnal/_weak_callback.py:268, in _StrongFunction.cb(self=<psygnal._weak_callback._StrongFunction object>, args=())
267 args = args[: self._max_args]
--> 268 self._f(*self._args, *args, **self._kwargs)
args = ()
self._f = <function FunctionGui.__init__.<locals>._disable_button_and_call at 0x16962c550>
self = <psygnal._weak_callback._StrongFunction object at 0x169631c00>
self._args = ()
self._kwargs = {}
File .../lib/python3.10/site-packages/magicgui/widgets/_function_gui.py:218, in FunctionGui.__init__.<locals>._disable_button_and_call()
217 try:
--> 218 self.__call__()
self = <FunctionGui autosegment_widget(v: napari.viewer.Viewer = Viewer(axes=Axes(visible=False, labels=True, colored=True, dashed=False, arrows=True), camera=Camera(center=(0.0, 1070.4865548651428, 525.4334832457411), zoom=1.2841762427452341, angles=(0.0, 0.0, 90.0), perspective=0.0, interactive=True), cursor=Cursor(position=(1527.1995960807803, 1304.1428168946877), scaled=True, size=1, style=<CursorStyle.CROSSHAIR: 'crosshair'>), dims=Dims(ndim=2, ndisplay=2, last_used=0, range=((0.0, 2160.0, 1.0), (0.0, 2160.0, 1.0)), current_step=(1080, 1080), order=(0, 1), axis_labels=('0', '1')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'DAPI' at 0x1696a8eb0>, <Labels layer 'auto_segmentation' at 0x330020100>, <Labels layer 'committed_objects' at 0x33bb89570>, <Labels layer 'current_object' at 0x33d9d4610>, <Points layer 'prompts' at 0x33da3bd90>], scale_bar=ScaleBar(visible=False, colored=False, color=<class 'numpy.ndarray'> (4,) float32, ticks=True, position=<Position.BOTTOM_RIGHT: 'bottom_right'>, font_size=10.0, box=False, box_color=<class 'numpy.ndarray'> (4,) float32, unit=None), text_overlay=TextOverlay(visible=False, color=<class 'numpy.ndarray'> (4,) float32, font_size=10.0, position=<TextOverlayPosition.TOP_LEFT: 'top_left'>, text=''), overlays=Overlays(interaction_box=InteractionBox(points=None, show=False, show_handle=False, show_vertices=False, selection_box_drag=None, selection_box_final=None, transform_start=<napari.utils.transforms.transforms.Affine object at 0x16cb0af80>, transform_drag=<napari.utils.transforms.transforms.Affine object at 0x16cb0aec0>, transform_final=<napari.utils.transforms.transforms.Affine object at 0x16cb0ae60>, transform=<napari.utils.transforms.transforms.Affine object at 0x3307c9f90>, allow_new_selection=True, selected_vertex=None)), help='use <3> for select points, use <4> for pan/zoom', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_move at 0x3307c1630>], mouse_drag_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_drag at 0x3307c1900>], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x14fbd1900>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Shift': <function InteractionBoxMouseBindings.initialize_key_events.<locals>.hold_to_lock_aspect_ratio at 0x3307c2440>, 'Control-Shift-R': <function InteractionBoxMouseBindings._reset_active_layer_affine at 0x33185c9d0>, 'Control-Shift-A': <function InteractionBoxMouseBindings._transform_active_layer at 0x33185c8b0>, 'S': <function annotator_2d.<locals>._segmet at 0x33dd7b400>, 'C': <function annotator_2d.<locals>._commit at 0x33dd7b520>, 'T': <function annotator_2d.<locals>._toggle_label at 0x33dd7b370>, 'Shift-C': <function annotator_2d.<locals>.clear_prompts at 0x33dd7b0a0>}), method: str = 'default')>
219 finally:
File .../lib/python3.10/site-packages/magicgui/widgets/_function_gui.py:331, in FunctionGui.__call__(self=<FunctionGui autosegment_widget(v: napari.viewer...mpts at 0x33dd7b0a0>}), method: str = 'default')>, update_widget=False, *args=(), **kwargs={})
330 with _function_name_pointing_to_widget(self):
--> 331 value = self._function(*bound.args, **bound.kwargs)
self = <FunctionGui autosegment_widget(v: napari.viewer.Viewer = Viewer(axes=Axes(visible=False, labels=True, colored=True, dashed=False, arrows=True), camera=Camera(center=(0.0, 1070.4865548651428, 525.4334832457411), zoom=1.2841762427452341, angles=(0.0, 0.0, 90.0), perspective=0.0, interactive=True), cursor=Cursor(position=(1527.1995960807803, 1304.1428168946877), scaled=True, size=1, style=<CursorStyle.CROSSHAIR: 'crosshair'>), dims=Dims(ndim=2, ndisplay=2, last_used=0, range=((0.0, 2160.0, 1.0), (0.0, 2160.0, 1.0)), current_step=(1080, 1080), order=(0, 1), axis_labels=('0', '1')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'DAPI' at 0x1696a8eb0>, <Labels layer 'auto_segmentation' at 0x330020100>, <Labels layer 'committed_objects' at 0x33bb89570>, <Labels layer 'current_object' at 0x33d9d4610>, <Points layer 'prompts' at 0x33da3bd90>], scale_bar=ScaleBar(visible=False, colored=False, color=<class 'numpy.ndarray'> (4,) float32, ticks=True, position=<Position.BOTTOM_RIGHT: 'bottom_right'>, font_size=10.0, box=False, box_color=<class 'numpy.ndarray'> (4,) float32, unit=None), text_overlay=TextOverlay(visible=False, color=<class 'numpy.ndarray'> (4,) float32, font_size=10.0, position=<TextOverlayPosition.TOP_LEFT: 'top_left'>, text=''), overlays=Overlays(interaction_box=InteractionBox(points=None, show=False, show_handle=False, show_vertices=False, selection_box_drag=None, selection_box_final=None, transform_start=<napari.utils.transforms.transforms.Affine object at 0x16cb0af80>, transform_drag=<napari.utils.transforms.transforms.Affine object at 0x16cb0aec0>, transform_final=<napari.utils.transforms.transforms.Affine object at 0x16cb0ae60>, transform=<napari.utils.transforms.transforms.Affine object at 0x3307c9f90>, allow_new_selection=True, selected_vertex=None)), help='use <3> for select points, use <4> for pan/zoom', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_move at 0x3307c1630>], mouse_drag_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_drag at 0x3307c1900>], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x14fbd1900>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Shift': <function InteractionBoxMouseBindings.initialize_key_events.<locals>.hold_to_lock_aspect_ratio at 0x3307c2440>, 'Control-Shift-R': <function InteractionBoxMouseBindings._reset_active_layer_affine at 0x33185c9d0>, 'Control-Shift-A': <function InteractionBoxMouseBindings._transform_active_layer at 0x33185c8b0>, 'S': <function annotator_2d.<locals>._segmet at 0x33dd7b400>, 'C': <function annotator_2d.<locals>._commit at 0x33dd7b520>, 'T': <function annotator_2d.<locals>._toggle_label at 0x33dd7b370>, 'Shift-C': <function annotator_2d.<locals>.clear_prompts at 0x33dd7b0a0>}), method: str = 'default')>
bound = <BoundArguments (v=Viewer(axes=Axes(visible=False, labels=True, colored=True, dashed=False, arrows=True), camera=Camera(center=(0.0, 1070.4865548651428, 525.4334832457411), zoom=1.2841762427452341, angles=(0.0, 0.0, 90.0), perspective=0.0, interactive=True), cursor=Cursor(position=(1527.1995960807803, 1304.1428168946877), scaled=True, size=1, style=<CursorStyle.CROSSHAIR: 'crosshair'>), dims=Dims(ndim=2, ndisplay=2, last_used=0, range=((0.0, 2160.0, 1.0), (0.0, 2160.0, 1.0)), current_step=(1080, 1080), order=(0, 1), axis_labels=('0', '1')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'DAPI' at 0x1696a8eb0>, <Labels layer 'auto_segmentation' at 0x330020100>, <Labels layer 'committed_objects' at 0x33bb89570>, <Labels layer 'current_object' at 0x33d9d4610>, <Points layer 'prompts' at 0x33da3bd90>], scale_bar=ScaleBar(visible=False, colored=False, color=<class 'numpy.ndarray'> (4,) float32, ticks=True, position=<Position.BOTTOM_RIGHT: 'bottom_right'>, font_size=10.0, box=False, box_color=<class 'numpy.ndarray'> (4,) float32, unit=None), text_overlay=TextOverlay(visible=False, color=<class 'numpy.ndarray'> (4,) float32, font_size=10.0, position=<TextOverlayPosition.TOP_LEFT: 'top_left'>, text=''), overlays=Overlays(interaction_box=InteractionBox(points=None, show=False, show_handle=False, show_vertices=False, selection_box_drag=None, selection_box_final=None, transform_start=<napari.utils.transforms.transforms.Affine object at 0x16cb0af80>, transform_drag=<napari.utils.transforms.transforms.Affine object at 0x16cb0aec0>, transform_final=<napari.utils.transforms.transforms.Affine object at 0x16cb0ae60>, transform=<napari.utils.transforms.transforms.Affine object at 0x3307c9f90>, allow_new_selection=True, selected_vertex=None)), help='use <3> for select points, use <4> for pan/zoom', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_move at 0x3307c1630>], mouse_drag_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_drag at 0x3307c1900>], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x14fbd1900>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Shift': <function InteractionBoxMouseBindings.initialize_key_events.<locals>.hold_to_lock_aspect_ratio at 0x3307c2440>, 'Control-Shift-R': <function InteractionBoxMouseBindings._reset_active_layer_affine at 0x33185c9d0>, 'Control-Shift-A': <function InteractionBoxMouseBindings._transform_active_layer at 0x33185c8b0>, 'S': <function annotator_2d.<locals>._segmet at 0x33dd7b400>, 'C': <function annotator_2d.<locals>._commit at 0x33dd7b520>, 'T': <function annotator_2d.<locals>._toggle_label at 0x33dd7b370>, 'Shift-C': <function annotator_2d.<locals>.clear_prompts at 0x33dd7b0a0>}), method='default')>
self._function = <function autosegment_widget at 0x169612e60>
333 self._call_count += 1
File ~/projects/micro-sam/micro_sam/sam_annotator/annotator_2d.py:29, in autosegment_widget(v=Viewer(axes=Axes(visible=False, labels=True, col...tator_2d.<locals>.clear_prompts at 0x33dd7b0a0>}), method='default')
28 print("Run automatic segmentation with SAM. This can take a few minutes ...")
---> 29 image = v.layers["raw"].data
v = Viewer(axes=Axes(visible=False, labels=True, colored=True, dashed=False, arrows=True), camera=Camera(center=(0.0, 1070.4865548651428, 525.4334832457411), zoom=1.2841762427452341, angles=(0.0, 0.0, 90.0), perspective=0.0, interactive=True), cursor=Cursor(position=(1527.1995960807803, 1304.1428168946877), scaled=True, size=1, style=<CursorStyle.CROSSHAIR: 'crosshair'>), dims=Dims(ndim=2, ndisplay=2, last_used=0, range=((0.0, 2160.0, 1.0), (0.0, 2160.0, 1.0)), current_step=(1080, 1080), order=(0, 1), axis_labels=('0', '1')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'DAPI' at 0x1696a8eb0>, <Labels layer 'auto_segmentation' at 0x330020100>, <Labels layer 'committed_objects' at 0x33bb89570>, <Labels layer 'current_object' at 0x33d9d4610>, <Points layer 'prompts' at 0x33da3bd90>], scale_bar=ScaleBar(visible=False, colored=False, color=<class 'numpy.ndarray'> (4,) float32, ticks=True, position=<Position.BOTTOM_RIGHT: 'bottom_right'>, font_size=10.0, box=False, box_color=<class 'numpy.ndarray'> (4,) float32, unit=None), text_overlay=TextOverlay(visible=False, color=<class 'numpy.ndarray'> (4,) float32, font_size=10.0, position=<TextOverlayPosition.TOP_LEFT: 'top_left'>, text=''), overlays=Overlays(interaction_box=InteractionBox(points=None, show=False, show_handle=False, show_vertices=False, selection_box_drag=None, selection_box_final=None, transform_start=<napari.utils.transforms.transforms.Affine object at 0x16cb0af80>, transform_drag=<napari.utils.transforms.transforms.Affine object at 0x16cb0aec0>, transform_final=<napari.utils.transforms.transforms.Affine object at 0x16cb0ae60>, transform=<napari.utils.transforms.transforms.Affine object at 0x3307c9f90>, allow_new_selection=True, selected_vertex=None)), help='use <3> for select points, use <4> for pan/zoom', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_move at 0x3307c1630>], mouse_drag_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_drag at 0x3307c1900>], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x14fbd1900>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Shift': <function InteractionBoxMouseBindings.initialize_key_events.<locals>.hold_to_lock_aspect_ratio at 0x3307c2440>, 'Control-Shift-R': <function InteractionBoxMouseBindings._reset_active_layer_affine at 0x33185c9d0>, 'Control-Shift-A': <function InteractionBoxMouseBindings._transform_active_layer at 0x33185c8b0>, 'S': <function annotator_2d.<locals>._segmet at 0x33dd7b400>, 'C': <function annotator_2d.<locals>._commit at 0x33dd7b520>, 'T': <function annotator_2d.<locals>._toggle_label at 0x33dd7b370>, 'Shift-C': <function annotator_2d.<locals>.clear_prompts at 0x33dd7b0a0>})
30 seg = segment_instances.segment_instances_sam(SAM, image)
File .../lib/python3.10/site-packages/napari/utils/_proxies.py:77, in PublicOnlyProxy.__getitem__(self=[<Image layer 'DAPI' at 0x1696a8eb0>, <Labels la...9d4610>, <Points layer 'prompts' at 0x33da3bd90>], key='raw')
76 def __getitem__(self, key):
---> 77 return self.create(super().__getitem__(key))
self = [<Image layer 'DAPI' at 0x1696a8eb0>, <Labels layer 'auto_segmentation' at 0x330020100>, <Labels layer 'committed_objects' at 0x33bb89570>, <Labels layer 'current_object' at 0x33d9d4610>, <Points layer 'prompts' at 0x33da3bd90>]
key = 'raw'
File .../lib/python3.10/site-packages/napari/utils/events/containers/_typed.py:142, in TypedMutableSequence.__getitem__(self=[<Image layer 'DAPI' at 0x1696a8eb0>, <Labels la...9d4610>, <Points layer 'prompts' at 0x33da3bd90>], key='raw')
141 except ValueError as e:
--> 142 raise KeyError(str(e)) from e
144 result = self._list[key]
KeyError: "'raw' is not in list"
The above exception was the direct cause of the following exception:
EmitLoopError Traceback (most recent call last)
File .../lib/python3.10/site-packages/magicgui/widgets/bases/_value_widget.py:65, in ValueWidget._on_value_change(self=PushButton(value=False, annotation=None, name='call_button'), value=False)
63 if value is self.null_value and not self._nullable:
64 return
---> 65 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 .../lib/python3.10/site-packages/psygnal/_signal.py:927, in SignalInstance.emit(self=<SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>, check_nargs=False, check_types=False, asynchronous=False, *args=(False,))
924 sd.start()
925 return sd
--> 927 self._run_emit_loop(args)
self = <SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>
args = (False,)
928 return None
File .../lib/python3.10/site-packages/psygnal/_signal.py:974, in SignalInstance._run_emit_loop(self=<SignalInstance 'changed' on PushButton(value=False, annotation=None, name='call_button')>, args=(False,))
972 caller.cb(args)
973 except Exception as e:
--> 974 raise EmitLoopError(
caller = <psygnal._weak_callback._StrongFunction object at 0x169631c00>
args = (False,)
975 slot_repr=repr(caller), args=args, exc=e
976 ) from e
978 return None
EmitLoopError: calling <psygnal._weak_callback._StrongFunction object at 0x169631c00> with args=(False,) caused KeyError: "'raw' is not in list".