From 1c004a02bd4d866bfd0e70f94bb8367451baca16 Mon Sep 17 00:00:00 2001 From: Anwai Archit Date: Thu, 21 Nov 2024 16:36:09 +0100 Subject: [PATCH 1/2] Add menu option for automatic segmentation modes --- micro_sam/sam_annotator/_widgets.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/micro_sam/sam_annotator/_widgets.py b/micro_sam/sam_annotator/_widgets.py index 4a58a42a..1f873897 100644 --- a/micro_sam/sam_annotator/_widgets.py +++ b/micro_sam/sam_annotator/_widgets.py @@ -976,13 +976,13 @@ def _create_settings_widget(self): ) setting_values.layout().addLayout(layout) - # Create UI for prefering the decoder. - self.prefer_decoder = True - widget = self._add_boolean_param( - "prefer_decoder", self.prefer_decoder, title="Prefer Segmentation Decoder", - tooltip=get_tooltip("embedding", "prefer_decoder") + # Create UI for the choice of automatic segmentation mode. + self.automatic_segmentation_mode = "amg" + auto_seg_options = ["amg", "ais"] + self.automatic_segmentation_mode_dropdown, layout = self._add_choice_param( + "automatic_segmentation_mode", self.automatic_segmentation_mode, auto_seg_options ) - setting_values.layout().addWidget(widget) + setting_values.layout().addLayout(layout) settings = _make_collapsible(setting_values, title="Embedding Settings") return settings @@ -1101,7 +1101,7 @@ def pbar_init(total, description): state.initialize_predictor( image_data, model_type=self.model_type, save_path=save_path, ndim=ndim, device=self.device, checkpoint_path=self.custom_weights, tile_shape=tile_shape, halo=halo, - prefer_decoder=self.prefer_decoder, pbar_init=pbar_init, + prefer_decoder=(self.automatic_segmentation_mode == "ais"), pbar_init=pbar_init, pbar_update=lambda update: pbar_signals.pbar_update.emit(update), ) pbar_signals.pbar_stop.emit() From 1315c5aff97b07a64063fc470caf770d104e22d1 Mon Sep 17 00:00:00 2001 From: Anwai Archit Date: Fri, 22 Nov 2024 16:37:30 +0100 Subject: [PATCH 2/2] Add tooltip for the mode menu and set 'auto' as default --- micro_sam/sam_annotator/_tooltips.py | 2 +- micro_sam/sam_annotator/_widgets.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/micro_sam/sam_annotator/_tooltips.py b/micro_sam/sam_annotator/_tooltips.py index 8ddda0ce..7129dadd 100644 --- a/micro_sam/sam_annotator/_tooltips.py +++ b/micro_sam/sam_annotator/_tooltips.py @@ -9,7 +9,7 @@ "halo": "Enter overlap values for computing tiled embeddings. Enter only x-value for quadratic size.\n Only active when tiling is used.", # noqa "image": "Select the napari image layer.", "model": "Select the segment anything model.", - "prefer_decoder": "Choose if the segmentation decoder is used for automatic segmentation. Only if it is available for the selected model..", # noqa + "automatic_segmentation_mode": "Select the automatic segmentation mode.", "run_button": "Compute embeddings or load embeddings if embedding_save_path is specified.", "tiling": "Enter tile size for computing tiled embeddings. Enter only x-value for quadratic size or both for non-quadratic.", # noqa }, diff --git a/micro_sam/sam_annotator/_widgets.py b/micro_sam/sam_annotator/_widgets.py index 1f873897..8d2cddea 100644 --- a/micro_sam/sam_annotator/_widgets.py +++ b/micro_sam/sam_annotator/_widgets.py @@ -977,10 +977,11 @@ def _create_settings_widget(self): setting_values.layout().addLayout(layout) # Create UI for the choice of automatic segmentation mode. - self.automatic_segmentation_mode = "amg" - auto_seg_options = ["amg", "ais"] + self.automatic_segmentation_mode = "auto" + auto_seg_options = ["auto", "amg", "ais"] self.automatic_segmentation_mode_dropdown, layout = self._add_choice_param( - "automatic_segmentation_mode", self.automatic_segmentation_mode, auto_seg_options + "automatic_segmentation_mode", self.automatic_segmentation_mode, auto_seg_options, + title="automatic segmentation mode", tooltip=get_tooltip("embedding", "automatic_segmentation_mode") ) setting_values.layout().addLayout(layout) @@ -1098,10 +1099,16 @@ def pbar_init(total, description): pbar_signals.pbar_total.emit(total) pbar_signals.pbar_description.emit(description) + # Whether to prefer decoder. + # With 'amg', it is set to 'False', else it is 'True' for the default 'auto' and 'ais' mode. + prefer_decoder = True + if self.automatic_segmentation_mode in "amg": + prefer_decoder = False + state.initialize_predictor( image_data, model_type=self.model_type, save_path=save_path, ndim=ndim, device=self.device, checkpoint_path=self.custom_weights, tile_shape=tile_shape, halo=halo, - prefer_decoder=(self.automatic_segmentation_mode == "ais"), pbar_init=pbar_init, + prefer_decoder=prefer_decoder, pbar_init=pbar_init, pbar_update=lambda update: pbar_signals.pbar_update.emit(update), ) pbar_signals.pbar_stop.emit()