Skip to content

Commit

Permalink
Add unittests for the state
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinpape committed Oct 30, 2023
1 parent e60ede2 commit 11f170d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions micro_sam/sam_annotator/_state.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""Implements a singleton class for the state of the annotation tools.
The singleton is implemented following the metaclass design described here:
https://itnext.io/deciding-the-best-singleton-approach-in-python-65c61e90cdc4
"""

from dataclasses import dataclass
from typing import Dict, Optional, Tuple

Expand Down
32 changes: 32 additions & 0 deletions test/test_sam_annotator/test_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest
import micro_sam.util as util

from skimage.data import binary_blobs


class TestState(unittest.TestCase):
model_type = "vit_t" if util.VIT_T_SUPPORT else "vit_b"

def test_state_for_interactive_segmentation(self):
from micro_sam.sam_annotator._state import AnnotatorState
image = binary_blobs(512)
predictor = util.get_sam_model(model_type=self.model_type)
image_embeddings = util.precompute_image_embeddings(predictor, image)

state = AnnotatorState()
state.image_embeddings = image_embeddings
state.predictor = predictor
state.image_shape = image.shape
self.assertTrue(state.initialized_for_interactive_segmentation())

def test_state_for_tracking(self):
from micro_sam.sam_annotator._state import AnnotatorState

state = AnnotatorState()
state.current_track_id = 1
state.lineage = {1: {}}
self.assertTrue(state.initialized_for_tracking())


if __name__ == "__main__":
unittest.main()

0 comments on commit 11f170d

Please sign in to comment.