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

Minor fix to caching embeddings in AIS evaluation #800

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
17 changes: 10 additions & 7 deletions micro_sam/evaluation/instance_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def run_instance_segmentation_grid_search(
def run_instance_segmentation_inference(
segmenter: Union[AMGBase, InstanceSegmentationWithDecoder],
image_paths: List[Union[str, os.PathLike]],
embedding_dir: Union[str, os.PathLike],
embedding_dir: Optional[Union[str, os.PathLike]],
prediction_dir: Union[str, os.PathLike],
generate_kwargs: Optional[Dict[str, Any]] = None,
) -> None:
Expand Down Expand Up @@ -279,13 +279,16 @@ def run_instance_segmentation_inference(
image = imageio.imread(image_path)

if embedding_dir is None:
segmenter.initialize(image)
embedding_path = None
else:
assert predictor is not None
embedding_path = os.path.join(embedding_dir, f"{os.path.splitext(image_name)[0]}.zarr")
image_embeddings = util.precompute_image_embeddings(
predictor, image, embedding_path, ndim=2, verbose=verbose_embeddings
)
segmenter.initialize(image, image_embeddings)

image_embeddings = util.precompute_image_embeddings(
predictor, image, embedding_path, ndim=2, verbose=verbose_embeddings
)

segmenter.initialize(image, image_embeddings)

masks = segmenter.generate(**generate_kwargs)

Expand Down Expand Up @@ -365,7 +368,7 @@ def run_instance_segmentation_grid_search_and_inference(
val_image_paths: List[Union[str, os.PathLike]],
val_gt_paths: List[Union[str, os.PathLike]],
test_image_paths: List[Union[str, os.PathLike]],
embedding_dir: Union[str, os.PathLike],
embedding_dir: Optional[Union[str, os.PathLike]],
prediction_dir: Union[str, os.PathLike],
experiment_folder: Union[str, os.PathLike],
result_dir: Union[str, os.PathLike],
Expand Down
Loading