-
Notifications
You must be signed in to change notification settings - Fork 0
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
WIP refactor state in singleton #3
base: embedding-widget
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import napari | ||
from skimage.data import astronaut | ||
from micro_sam.sam_annotator._state import SamState | ||
|
||
x = astronaut() | ||
|
||
v = napari.Viewer() | ||
v.add_image(x) | ||
|
||
|
||
@v.bind_key("p") | ||
def print_embed(v): | ||
state = SamState() | ||
print("Image Embeddings are None:", state.image_embeddings is None) | ||
|
||
|
||
napari.run() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
The interactive annotation tools. | ||
""" | ||
|
||
from .annotator import annotator | ||
from .annotator_2d import annotator_2d | ||
from .annotator_3d import annotator_3d | ||
from .annotator_tracking import annotator_tracking | ||
from .image_series_annotator import image_folder_annotator, image_series_annotator | ||
# from .annotator import annotator | ||
# from .annotator_2d import annotator_2d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these lines commented out? This is what caused There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to comment these out locally in order to fix the vigra import issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to undo these changes. I assume these import errors are specific to my installation and I will look into this more closely at some later point (and first see if this still persists with a new environment.) |
||
# from .annotator_3d import annotator_3d | ||
# from .annotator_tracking import annotator_tracking | ||
# from .image_series_annotator import image_folder_annotator, image_series_annotator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
|
||
# See | ||
# https://stackoverflow.com/questions/6760685/creating-a-singleton-in-python | ||
def singleton(class_): | ||
instances = {} | ||
|
||
def getinstance(*args, **kwargs): | ||
if class_ not in instances: | ||
instances[class_] = class_(*args, **kwargs) | ||
return instances[class_] | ||
return getinstance | ||
|
||
|
||
# we probably want this to be a data class | ||
# and I am not sure which singleton pattern to go with | ||
@singleton | ||
class SamState: | ||
def __init__(self): | ||
self.image_embeddings = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just fyi, I have called this
AnnotatorState
in computational-cell-analytics#240 now.