computational-cell-analytics / micro-sam

Segment Anything for Microscopy
https://computational-cell-analytics.github.io/micro-sam/
MIT License
311 stars 35 forks source link

'AnnotatorState' object is not subscriptable #607

Closed Mobinapournemat closed 1 month ago

Mobinapournemat commented 1 month ago

Hello,

I finetuned the vit_h model on my dataset and I'd like to use it in the Automatic Segmentation Setting in napari. However, sometimes when I try to apply the automatic segmentation to the volume it returns this error:

TypeError Traceback (most recent call last) File ~/miniforge3/envs/last_sam/lib/python3.11/site-packages/superqt/utils/_qthreading.py:613, in create_worker.<locals>.reraise(e=TypeError("'AnnotatorState' object is not subscriptable")) 612 def reraise(e): --> 613 raise e e = TypeError("'AnnotatorState' object is not subscriptable")

I'd appreciate any guidance on how to solve this issue.

constantinpape commented 1 month ago

Hi @Mobinapournemat, can you provide the following information:

You can check the micro_sam version by running python -c "import micro_sam; print(micro_sam.__version__)" in a console with the correct environment activated.

Mobinapournemat commented 1 month ago

Thanks for your prompt response.

I've noticed that it returns this error when I pass -e argument (embedding path) in the CLI to save the computed embeddings.

I'm using the 1.0.0post0 version. and here's the complete traceback:

TypeError Traceback (most recent call last) File ~/miniforge3/envs/last_sam/lib/python3.11/site-packages/superqt/utils/_qthreading.py:613, in create_worker.<locals>.reraise(e=TypeError("'AnnotatorState' object is not subscriptable")) 612 def reraise(e): --> 613 raise e e = TypeError("'AnnotatorState' object is not subscriptable") File ~/miniforge3/envs/last_sam/lib/python3.11/site-packages/superqt/utils/_qthreading.py:175, in WorkerBase.run(self=<napari._qt.qthreading.FunctionWorker object>) 173 warnings.filterwarnings("always") 174 warnings.showwarning = lambda *w: self.warned.emit(w) --> 175 result = self.work() self = <napari._qt.qthreading.FunctionWorker object at 0x71989829fc70> 176 if isinstance(result, Exception): 177 if isinstance(result, RuntimeError): 178 # The Worker object has likely been deleted. 179 # A deleted wrapped C/C++ object may result in a runtime 180 # error that will cause segfault if we try to do much other 181 # than simply notify the user. File ~/miniforge3/envs/last_sam/lib/python3.11/site-packages/superqt/utils/_qthreading.py:354, in FunctionWorker.work(self=<napari._qt.qthreading.FunctionWorker object>) 353 def work(self) -> _R: --> 354 return self._func(*self._args, **self._kwargs) self._func = <function AutoSegmentWidget._run_segmentation_3d.<locals>.seg_impl at 0x719848b31260> self = <napari._qt.qthreading.FunctionWorker object at 0x71989829fc70> self._args = () self._kwargs = {} File ~/Documents/Last_v_msam/micro-sam/micro_sam/sam_annotator/_widgets.py:1590, in AutoSegmentWidget._run_segmentation_3d.<locals>.seg_impl() 1588 # Further optimization: parallelize if state is precomputed for all slices 1589 for i in range(segmentation.shape[0]): -> 1590 seg = _instance_segmentation_impl(self.with_background, self.min_object_size, i=i, **kwargs) i = 0 self.with_background = True self.min_object_size = 100 self = <micro_sam.sam_annotator._widgets.AutoSegmentWidget object at 0x7198486f9900> kwargs = {'center_distance_threshold': 0.5, 'boundary_distance_threshold': 0.5, 'min_size': 100} 1591 seg_max = seg.max() 1592 if seg_max == 0: File ~/Documents/Last_v_msam/micro-sam/micro_sam/sam_annotator/_widgets.py:1351, in _instance_segmentation_impl(with_background=True, min_object_size=100, i=0, pbar_init=None, pbar_update=None, **kwargs={'boundary_distance_threshold': 0.5, 'center_distance_threshold': 0.5, 'min_size': 100}) 1349 def _instance_segmentation_impl(with_background, min_object_size, i=None, pbar_init=None, pbar_update=None, **kwargs): 1350 state = AnnotatorState() -> 1351 _handle_amg_state(state, i, pbar_init, pbar_update) state = AnnotatorState(image_embeddings={'features': <zarr.core.Array '/features' (48, 1, 256, 64, 64) float32>, 'input_size': (1024, 1024), 'original_size': (1024, 1024)}, predictor=<mobile_sam.predictor.SamPredictor object at 0x71991f596250>, image_shape=(48, 1024, 1024), embedding_path='embedding_coCATS_T2_cropped_resized.zarr', data_signature='ca1eced1d69329bf069ef35f19209ef0f370ba91', amg=<micro_sam.instance_segmentation.InstanceSegmentationWithDecoder object at 0x7197f5756710>, amg_state={'cache_path': 'embedding_coCATS_T2_cropped_resized.zarr/is_state.h5', 23: {'foreground': <class 'numpy.ndarray'> (1024, 1024) float32, 'center_distances': <class 'numpy.ndarray'> (1024, 1024) float32, 'boundary_distances': <class 'numpy.ndarray'> (1024, 1024) float32}, 0: {'foreground': <class 'numpy.ndarray'> (1024, 1024) float32, 'center_distances': <class 'numpy.ndarray'> (1024, 1024) float32, 'boundary_distances': <class 'numpy.ndarray'> (1024, 1024) float32}}, decoder=DecoderAdapter( (base): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(512, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) (out_conv): Conv2d(64, 3, kernel_size=(1, 1), stride=(1, 1)) (deconv_out): SingleDeconv2DBlock( (block): ConvTranspose2d(64, 64, kernel_size=(2, 2), stride=(2, 2)) ) (decoder_head): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(128, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(64, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) (final_activation): Sigmoid() (decoder): Decoder( (blocks): ModuleList( (0): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(512, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(512, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) (1): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(256, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) (2): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(128, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(64, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) ) (samplers): ModuleList( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(512, 256, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleDeconv2DBlock( (block): ConvTranspose2d(256, 128, kernel_size=(2, 2), stride=(2, 2)) ) (2): SingleDeconv2DBlock( (block): ConvTranspose2d(128, 64, kernel_size=(2, 2), stride=(2, 2)) ) ) ) (deconv1): Deconv2DBlock( (block): Sequential( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(256, 512, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleConv2DBlock( (block): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) ) (2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (3): ReLU(inplace=True) ) ) (deconv2): Deconv2DBlock( (block): Sequential( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(512, 256, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleConv2DBlock( (block): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) ) (2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (3): ReLU(inplace=True) ) ) (deconv3): Deconv2DBlock( (block): Sequential( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(256, 128, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleConv2DBlock( (block): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) ) (2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (3): ReLU(inplace=True) ) ) (deconv4): Deconv2DBlock( (block): Sequential( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(128, 64, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleConv2DBlock( (block): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) ) (2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (3): ReLU(inplace=True) ) ) ), current_track_id=None, lineage=None, committed_lineages=None, widgets={'embeddings': <micro_sam.sam_annotator._widgets.EmbeddingWidget object at 0x719848b56440>, 'prompts': <Container ()>, 'segment': <FunctionGui segment_slice(viewer: napari.viewer.Viewer = Viewer(camera=Camera(center=(0.0, 511.5, 511.5), zoom=0.5372881426796636, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(23.0, 1408.5978266066681, 1208.5189599208982), scaled=True, size=10, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 48.0, 1.0), (0.0, 1024.0, 1.0), (0.0, 1024.0, 1.0)), current_step=(23, 511, 511), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'image' at 0x7198d843de50>, <Labels layer 'current_object' at 0x7198d8368c90>, <Labels layer 'auto_segmentation' at 0x7198d8253690>, <Labels layer 'committed_objects' at 0x7198d82de990>, <Points layer 'point_prompts' at 0x7198d81056d0>, <Shapes layer 'prompts' at 0x719848cc4390>], help='use <1> for activate the label eraser, use <2> for activate the paint brush, use <3> for activate the fill bucket, use <4> for pick mode', status={'layer_base': 'auto_segmentation', 'source_type': '', 'plugin': '', 'coordinates': ' [23 1409 1209]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x7199342d7880>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'S': <function _AnnotatorBase._create_keybindings.<locals>._segment at 0x71984872e3e0>, 'C': <function _AnnotatorBase._create_keybindings.<locals>._commit at 0x71984872e480>, 'T': <function _AnnotatorBase._create_keybindings.<locals>._toggle_label at 0x71984872e520>, 'Shift-C': <function _AnnotatorBase._create_keybindings.<locals>._clear_annotations at 0x71984872e5c0>, 'Shift-S': <function _AnnotatorBase._create_keybindings.<locals>._seg_nd at 0x71984872e660>})) -> None>, 'segment_nd': <micro_sam.sam_annotator._widgets.SegmentNDWidget object at 0x7198486fab00>, 'autosegment': <micro_sam.sam_annotator._widgets.AutoSegmentWidget object at 0x7198486f9900>, 'commit': <FunctionGui commit(viewer: napari.viewer.Viewer = Viewer(camera=Camera(center=(0.0, 511.5, 511.5), zoom=0.5372881426796636, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(23.0, 1408.5978266066681, 1208.5189599208982), scaled=True, size=10, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 48.0, 1.0), (0.0, 1024.0, 1.0), (0.0, 1024.0, 1.0)), current_step=(23, 511, 511), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'image' at 0x7198d843de50>, <Labels layer 'current_object' at 0x7198d8368c90>, <Labels layer 'auto_segmentation' at 0x7198d8253690>, <Labels layer 'committed_objects' at 0x7198d82de990>, <Points layer 'point_prompts' at 0x7198d81056d0>, <Shapes layer 'prompts' at 0x719848cc4390>], help='use <1> for activate the label eraser, use <2> for activate the paint brush, use <3> for activate the fill bucket, use <4> for pick mode', status={'layer_base': 'auto_segmentation', 'source_type': '', 'plugin': '', 'coordinates': ' [23 1409 1209]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x7199342d7880>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'S': <function _AnnotatorBase._create_keybindings.<locals>._segment at 0x71984872e3e0>, 'C': <function _AnnotatorBase._create_keybindings.<locals>._commit at 0x71984872e480>, 'T': <function _AnnotatorBase._create_keybindings.<locals>._toggle_label at 0x71984872e520>, 'Shift-C': <function _AnnotatorBase._create_keybindings.<locals>._clear_annotations at 0x71984872e5c0>, 'Shift-S': <function _AnnotatorBase._create_keybindings.<locals>._seg_nd at 0x71984872e660>}), layer: str = 'current_object', preserve_committed: bool = True, commit_path: Optional[pathlib.Path] = None) -> None>, 'clear': <FunctionGui clear_volume(viewer: napari.viewer.Viewer = Viewer(camera=Camera(center=(0.0, 511.5, 511.5), zoom=0.5372881426796636, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(23.0, 1408.5978266066681, 1208.5189599208982), scaled=True, size=10, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 48.0, 1.0), (0.0, 1024.0, 1.0), (0.0, 1024.0, 1.0)), current_step=(23, 511, 511), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'image' at 0x7198d843de50>, <Labels layer 'current_object' at 0x7198d8368c90>, <Labels layer 'auto_segmentation' at 0x7198d8253690>, <Labels layer 'committed_objects' at 0x7198d82de990>, <Points layer 'point_prompts' at 0x7198d81056d0>, <Shapes layer 'prompts' at 0x719848cc4390>], help='use <1> for activate the label eraser, use <2> for activate the paint brush, use <3> for activate the fill bucket, use <4> for pick mode', status={'layer_base': 'auto_segmentation', 'source_type': '', 'plugin': '', 'coordinates': ' [23 1409 1209]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x7199342d7880>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'S': <function _AnnotatorBase._create_keybindings.<locals>._segment at 0x71984872e3e0>, 'C': <function _AnnotatorBase._create_keybindings.<locals>._commit at 0x71984872e480>, 'T': <function _AnnotatorBase._create_keybindings.<locals>._toggle_label at 0x71984872e520>, 'Shift-C': <function _AnnotatorBase._create_keybindings.<locals>._clear_annotations at 0x71984872e5c0>, 'Shift-S': <function _AnnotatorBase._create_keybindings.<locals>._seg_nd at 0x71984872e660>}), all_slices: bool = True) -> None>}, z_range=None) i = 0 pbar_init = None pbar_update = None 1353 seg = state.amg.generate(**kwargs) 1354 if len(seg) == 0: File ~/Documents/Last_v_msam/micro-sam/micro_sam/sam_annotator/_widgets.py:1333, in _handle_amg_state(state=AnnotatorState(image_embeddings={'features': <za...all_slices: bool = True) -> None>}, z_range=None), i=0, pbar_init=None, pbar_update=None) 1331 with h5py.File(cache_path, "a") as f: 1332 g = f.create_group(save_key) -> 1333 g.create_dataset("foreground", data=state["foreground"], compression="gzip") state = AnnotatorState(image_embeddings={'features': <zarr.core.Array '/features' (48, 1, 256, 64, 64) float32>, 'input_size': (1024, 1024), 'original_size': (1024, 1024)}, predictor=<mobile_sam.predictor.SamPredictor object at 0x71991f596250>, image_shape=(48, 1024, 1024), embedding_path='embedding_coCATS_T2_cropped_resized.zarr', data_signature='ca1eced1d69329bf069ef35f19209ef0f370ba91', amg=<micro_sam.instance_segmentation.InstanceSegmentationWithDecoder object at 0x7197f5756710>, amg_state={'cache_path': 'embedding_coCATS_T2_cropped_resized.zarr/is_state.h5', 23: {'foreground': <class 'numpy.ndarray'> (1024, 1024) float32, 'center_distances': <class 'numpy.ndarray'> (1024, 1024) float32, 'boundary_distances': <class 'numpy.ndarray'> (1024, 1024) float32}, 0: {'foreground': <class 'numpy.ndarray'> (1024, 1024) float32, 'center_distances': <class 'numpy.ndarray'> (1024, 1024) float32, 'boundary_distances': <class 'numpy.ndarray'> (1024, 1024) float32}}, decoder=DecoderAdapter( (base): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(512, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) (out_conv): Conv2d(64, 3, kernel_size=(1, 1), stride=(1, 1)) (deconv_out): SingleDeconv2DBlock( (block): ConvTranspose2d(64, 64, kernel_size=(2, 2), stride=(2, 2)) ) (decoder_head): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(128, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(64, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) (final_activation): Sigmoid() (decoder): Decoder( (blocks): ModuleList( (0): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(512, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(512, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) (1): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(256, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) (2): ConvBlock2d( (block): Sequential( (0): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (1): Conv2d(128, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): ReLU(inplace=True) (3): InstanceNorm2d(64, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) (4): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (5): ReLU(inplace=True) ) ) ) (samplers): ModuleList( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(512, 256, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleDeconv2DBlock( (block): ConvTranspose2d(256, 128, kernel_size=(2, 2), stride=(2, 2)) ) (2): SingleDeconv2DBlock( (block): ConvTranspose2d(128, 64, kernel_size=(2, 2), stride=(2, 2)) ) ) ) (deconv1): Deconv2DBlock( (block): Sequential( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(256, 512, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleConv2DBlock( (block): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) ) (2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (3): ReLU(inplace=True) ) ) (deconv2): Deconv2DBlock( (block): Sequential( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(512, 256, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleConv2DBlock( (block): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) ) (2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (3): ReLU(inplace=True) ) ) (deconv3): Deconv2DBlock( (block): Sequential( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(256, 128, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleConv2DBlock( (block): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) ) (2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (3): ReLU(inplace=True) ) ) (deconv4): Deconv2DBlock( (block): Sequential( (0): SingleDeconv2DBlock( (block): ConvTranspose2d(128, 64, kernel_size=(2, 2), stride=(2, 2)) ) (1): SingleConv2DBlock( (block): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) ) (2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (3): ReLU(inplace=True) ) ) ), current_track_id=None, lineage=None, committed_lineages=None, widgets={'embeddings': <micro_sam.sam_annotator._widgets.EmbeddingWidget object at 0x719848b56440>, 'prompts': <Container ()>, 'segment': <FunctionGui segment_slice(viewer: napari.viewer.Viewer = Viewer(camera=Camera(center=(0.0, 511.5, 511.5), zoom=0.5372881426796636, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(23.0, 1408.5978266066681, 1208.5189599208982), scaled=True, size=10, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 48.0, 1.0), (0.0, 1024.0, 1.0), (0.0, 1024.0, 1.0)), current_step=(23, 511, 511), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'image' at 0x7198d843de50>, <Labels layer 'current_object' at 0x7198d8368c90>, <Labels layer 'auto_segmentation' at 0x7198d8253690>, <Labels layer 'committed_objects' at 0x7198d82de990>, <Points layer 'point_prompts' at 0x7198d81056d0>, <Shapes layer 'prompts' at 0x719848cc4390>], help='use <1> for activate the label eraser, use <2> for activate the paint brush, use <3> for activate the fill bucket, use <4> for pick mode', status={'layer_base': 'auto_segmentation', 'source_type': '', 'plugin': '', 'coordinates': ' [23 1409 1209]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x7199342d7880>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'S': <function _AnnotatorBase._create_keybindings.<locals>._segment at 0x71984872e3e0>, 'C': <function _AnnotatorBase._create_keybindings.<locals>._commit at 0x71984872e480>, 'T': <function _AnnotatorBase._create_keybindings.<locals>._toggle_label at 0x71984872e520>, 'Shift-C': <function _AnnotatorBase._create_keybindings.<locals>._clear_annotations at 0x71984872e5c0>, 'Shift-S': <function _AnnotatorBase._create_keybindings.<locals>._seg_nd at 0x71984872e660>})) -> None>, 'segment_nd': <micro_sam.sam_annotator._widgets.SegmentNDWidget object at 0x7198486fab00>, 'autosegment': <micro_sam.sam_annotator._widgets.AutoSegmentWidget object at 0x7198486f9900>, 'commit': <FunctionGui commit(viewer: napari.viewer.Viewer = Viewer(camera=Camera(center=(0.0, 511.5, 511.5), zoom=0.5372881426796636, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(23.0, 1408.5978266066681, 1208.5189599208982), scaled=True, size=10, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 48.0, 1.0), (0.0, 1024.0, 1.0), (0.0, 1024.0, 1.0)), current_step=(23, 511, 511), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'image' at 0x7198d843de50>, <Labels layer 'current_object' at 0x7198d8368c90>, <Labels layer 'auto_segmentation' at 0x7198d8253690>, <Labels layer 'committed_objects' at 0x7198d82de990>, <Points layer 'point_prompts' at 0x7198d81056d0>, <Shapes layer 'prompts' at 0x719848cc4390>], help='use <1> for activate the label eraser, use <2> for activate the paint brush, use <3> for activate the fill bucket, use <4> for pick mode', status={'layer_base': 'auto_segmentation', 'source_type': '', 'plugin': '', 'coordinates': ' [23 1409 1209]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x7199342d7880>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'S': <function _AnnotatorBase._create_keybindings.<locals>._segment at 0x71984872e3e0>, 'C': <function _AnnotatorBase._create_keybindings.<locals>._commit at 0x71984872e480>, 'T': <function _AnnotatorBase._create_keybindings.<locals>._toggle_label at 0x71984872e520>, 'Shift-C': <function _AnnotatorBase._create_keybindings.<locals>._clear_annotations at 0x71984872e5c0>, 'Shift-S': <function _AnnotatorBase._create_keybindings.<locals>._seg_nd at 0x71984872e660>}), layer: str = 'current_object', preserve_committed: bool = True, commit_path: Optional[pathlib.Path] = None) -> None>, 'clear': <FunctionGui clear_volume(viewer: napari.viewer.Viewer = Viewer(camera=Camera(center=(0.0, 511.5, 511.5), zoom=0.5372881426796636, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(23.0, 1408.5978266066681, 1208.5189599208982), scaled=True, size=10, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 48.0, 1.0), (0.0, 1024.0, 1.0), (0.0, 1024.0, 1.0)), current_step=(23, 511, 511), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'image' at 0x7198d843de50>, <Labels layer 'current_object' at 0x7198d8368c90>, <Labels layer 'auto_segmentation' at 0x7198d8253690>, <Labels layer 'committed_objects' at 0x7198d82de990>, <Points layer 'point_prompts' at 0x7198d81056d0>, <Shapes layer 'prompts' at 0x719848cc4390>], help='use <1> for activate the label eraser, use <2> for activate the paint brush, use <3> for activate the fill bucket, use <4> for pick mode', status={'layer_base': 'auto_segmentation', 'source_type': '', 'plugin': '', 'coordinates': ' [23 1409 1209]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x7199342d7880>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'S': <function _AnnotatorBase._create_keybindings.<locals>._segment at 0x71984872e3e0>, 'C': <function _AnnotatorBase._create_keybindings.<locals>._commit at 0x71984872e480>, 'T': <function _AnnotatorBase._create_keybindings.<locals>._toggle_label at 0x71984872e520>, 'Shift-C': <function _AnnotatorBase._create_keybindings.<locals>._clear_annotations at 0x71984872e5c0>, 'Shift-S': <function _AnnotatorBase._create_keybindings.<locals>._seg_nd at 0x71984872e660>}), all_slices: bool = True) -> None>}, z_range=None) g = <Closed HDF5 group> 1334 g.create_dataset("boundary_distances", data=state["boundary_distances"], compression="gzip") 1335 g.create_dataset("center_distances", data=state["center_distances"], compression="gzip") TypeError: 'AnnotatorState' object is not subscriptable

constantinpape commented 1 month ago

Thank you for posing the trace! This was a bug in the code, which will be fixed by #608. We will make a release soon, so that this is fixed in the released version as well.

In the meantime: you can run the CLI command with the additional option --precompute_amg_state. This will also compute the state for automatic segmentation, and in this case the part of the code which contains the bug will not be called. Doing this will take a bit longer when you compute the embeddings for the first time, but then the automatic segmentation in the tool will be faster.