Skip to content

Commit

Permalink
✨ start fleshing out model running function
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahker committed Jul 26, 2023
1 parent 2367f64 commit 37c8cbe
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
34 changes: 33 additions & 1 deletion callbacks/segmentation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
from dash import callback, Input, Output, State, no_update
from utils.annotations import Annotations
from utils.data_utils import data
import numpy as np


# NEXT STEPS:
# - this function returns a job ID, which would be associated with the workflow run on vaughan
# - then we need another callback to pick up this ID and start polling for successful output
@callback(
Output("output-placeholder", "children"),
Input("run-model", "n_clicks"),
State("annotation-store", "data"),
State("project-name-src", "value"),
)
def run_model(n_clicks, annotation_store):
def run_job(n_clicks, annotation_store, project_name):
# TODO: Check if someone needs annotations as inputs
if n_clicks:

annotations = Annotations(annotation_store)
annotations.create_annotation_metadata()
annotations.create_annotation_mask(sparse=False) # TODO: Would sparse need to be true?

# Get metadata and annotation data
metadata = annotations.get_annotations()
mask = annotations.get_annotation_mask()

# Get raw images associated with each annotated slice
# Actually we can just pass the indices and have the job point to Tiled directly
img_idx = list(metadata.keys())
img = data[project_name]
raw = []
for idx in img_idx:
ar = img[int(idx)]
raw.append(ar)
raw = np.stack(raw)
mask = np.stack(mask)

# Some checks to validate that things are in the format we'd expect
print(metadata)
print(mask.shape)
print(raw.shape)

return "Running the model..."
return no_update
22 changes: 11 additions & 11 deletions components/control_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,13 @@ def layout():
],
),
dmc.Space(h=20),
dmc.Center(
# dmc.Button(
# "Save annotation",
# variant="light",
# style={"width": "160px", "margin": "5px"},
# )
),
# dmc.Center(
# # dmc.Button(
# # "Save annotation",
# # variant="light",
# # style={"width": "160px", "margin": "5px"},
# # )
# ),
dmc.Center(
dmc.Button(
"Export annotation",
Expand All @@ -359,13 +359,13 @@ def layout():
],
),
_accordion_item(
"Model configuration",
"carbon:ibm-watson-machine-learning",
"run-model",
title="Model configuration",
icon="carbon:ibm-watson-machine-learning",
value="run-model",
children=[
dmc.Center(
dmc.Button(
"Run model",
children="Run model",
id="run-model",
variant="light",
style={"width": "160px", "margin": "5px"},
Expand Down
3 changes: 3 additions & 0 deletions utils/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def __init__(self, annotation_store):
def get_annotations(self):
return self.annotations

def get_annotation_mask(self):
return self.annotation_mask

def get_annotation_mask_as_bytes(self):
buffer = io.BytesIO()
np.save(buffer, self.annotation_mask)
Expand Down

0 comments on commit 37c8cbe

Please sign in to comment.