Skip to content

Commit d785ad7

Browse files
Refactor gui for wrong embedding files
1 parent 8fca8ef commit d785ad7

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

micro_sam/sam_annotator/annotator_2d.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .. import util
1010
from .. import instance_segmentation
1111
from ..visualization import project_embeddings_for_visualization
12+
from .gui_utils import show_wrong_file_warning
1213
from .util import (
1314
clear_all_prompts, commit_segmentation_widget, create_prompt_menu,
1415
prompt_layer_to_boxes, prompt_layer_to_points, prompt_segmentation, toggle_label, LABEL_COLOR_CYCLE,
@@ -215,7 +216,8 @@ def annotator_2d(
215216
else:
216217
PREDICTOR = predictor
217218
IMAGE_EMBEDDINGS = util.precompute_image_embeddings(
218-
PREDICTOR, raw, save_path=embedding_path, ndim=2, tile_shape=tile_shape, halo=halo
219+
PREDICTOR, raw, save_path=embedding_path, ndim=2, tile_shape=tile_shape, halo=halo,
220+
wrong_file_callback=show_wrong_file_warning
219221
)
220222

221223
# we set the pre-computed image embeddings if we don't use tiling

micro_sam/sam_annotator/annotator_3d.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .. import util
99
from ..prompt_based_segmentation import segment_from_mask
1010
from ..visualization import project_embeddings_for_visualization
11+
from .gui_utils import show_wrong_file_warning
1112
from .util import (
1213
clear_all_prompts, commit_segmentation_widget, create_prompt_menu,
1314
prompt_layer_to_boxes, prompt_layer_to_points, prompt_segmentation,
@@ -195,7 +196,8 @@ def annotator_3d(
195196
global PREDICTOR, IMAGE_EMBEDDINGS
196197
PREDICTOR = util.get_sam_model(model_type=model_type)
197198
IMAGE_EMBEDDINGS = util.precompute_image_embeddings(
198-
PREDICTOR, raw, save_path=embedding_path, tile_shape=tile_shape, halo=halo
199+
PREDICTOR, raw, save_path=embedding_path, tile_shape=tile_shape, halo=halo,
200+
wrong_file_callback=show_wrong_file_warning,
199201
)
200202

201203
#

micro_sam/sam_annotator/annotator_tracking.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from .. import util
1414
from ..prompt_based_segmentation import segment_from_mask
15+
from .gui_utils import show_wrong_file_warning
1516
from .util import (
1617
create_prompt_menu, clear_all_prompts,
1718
prompt_layer_to_boxes, prompt_layer_to_points,
@@ -358,7 +359,8 @@ def annotator_tracking(
358359

359360
PREDICTOR = util.get_sam_model(model_type=model_type)
360361
IMAGE_EMBEDDINGS = util.precompute_image_embeddings(
361-
PREDICTOR, raw, save_path=embedding_path, tile_shape=tile_shape, halo=halo
362+
PREDICTOR, raw, save_path=embedding_path, tile_shape=tile_shape, halo=halo,
363+
wrong_file_callback=show_wrong_file_warning,
362364
)
363365

364366
CURRENT_TRACK_ID = 1

micro_sam/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def precompute_image_embeddings(
354354

355355
# data signature does not match or is not in the file
356356
if "data_signature" not in f.attrs or f.attrs["data_signature"] != data_signature:
357-
warnings.warn("Embeddings file is invalid. Please recompute embeddings to new file.")
357+
warnings.warn("Embeddings file is invalid. Please recompute embeddings in a new file.")
358358
if wrong_file_callback is not None:
359359
save_path = wrong_file_callback(save_path)
360360
f = zarr.open(save_path, "a")

0 commit comments

Comments
 (0)