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

Add menu option for automatic segmentation modes #793

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion micro_sam/sam_annotator/_tooltips.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
21 changes: 14 additions & 7 deletions micro_sam/sam_annotator/_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,13 +976,14 @@ 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 = "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,
title="automatic segmentation mode", tooltip=get_tooltip("embedding", "automatic_segmentation_mode")
)
setting_values.layout().addWidget(widget)
setting_values.layout().addLayout(layout)

settings = _make_collapsible(setting_values, title="Embedding Settings")
return settings
Expand Down Expand Up @@ -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.prefer_decoder, 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()
Expand Down
Loading