Skip to content

Commit

Permalink
check if model meta is none
Browse files Browse the repository at this point in the history
  • Loading branch information
almazgimaev committed Feb 8, 2024
1 parent a84a9f4 commit 873d8dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions annotation-tool/debug.env
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PYTHONUNBUFFERED=1
LOG_LEVEL="trace"

TASK_ID=52097 # ⬅️ change value (run 'While True Script' app and copy task ID)
TASK_ID=52548 # ⬅️ change value (run 'While True Script' app and copy task ID)

context.userId=330 # ⬅️ change value
context.teamId=506 # ⬅️ change value
context.workspaceId=942 # ⬅️ change value
modal.state.slyProjectId=28001 # ⬅️ change value
modal.state.slyProjectId=34944 # ⬅️ change value
# modal.state.slyDatasetId=75910 # ⬅️ change value (optional)

DEBUG_APP_DIR="debug/app_debug_data"
Expand Down
8 changes: 7 additions & 1 deletion annotation-tool/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from init_ui import init_ui
from shared_utils.connect import get_model_info
from shared_utils.inference import postprocess
from shared_utils.ui2 import set_error
from dotenv import load_dotenv
import ruamel.yaml
import io
Expand Down Expand Up @@ -103,6 +104,12 @@ def deselect_all_tags(api: sly.Api, task_id, context, state, app_logger):
@sly.timeit
def inference(api: sly.Api, task_id, context, state, app_logger):
global model_meta
if model_meta is None:
err = "Model meta is None. Make sure that the model is deployed, has meta, and try again."
set_error(api, task_id, err)
fields = [{"field": "state.processing", "payload": False}]
api.task.set_fields(task_id, fields)
return
project_id = context.get("projectId")
image_id = context.get("imageId")
figure_id = context.get("figureId")
Expand Down Expand Up @@ -330,7 +337,6 @@ def inference(api: sly.Api, task_id, context, state, app_logger):

if session_info.get("task type") == "prompt-based object detection":
# add tag to model meta if necessary
global model_meta
if not model_meta.get_tag_meta("confidence"):
model_meta = model_meta.add_tag_meta(sly.TagMeta("confidence", value_type="any_number"))
# add obj class to model meta if necessary
Expand Down
3 changes: 2 additions & 1 deletion shared_utils/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def get_model_info(api: sly.Api, task_id, context, state, app_logger) -> sly.Pro
)
sly.logger.info(f"Model meta: {str(meta_json)}")
model_meta = sly.ProjectMeta.from_json(meta_json)

if model_meta is None:
raise RuntimeError("Model meta is None. Make sure that the model is deployed, has meta, and try again.")
try:
inf_settings = api.task.send_request(
state["sessionId"], "get_custom_inference_settings", data={}
Expand Down
11 changes: 7 additions & 4 deletions shared_utils/ui2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union
import supervisely as sly


Expand All @@ -25,12 +25,15 @@ def set_model_info(api: sly.Api, task_id, model_meta: sly.ProjectMeta, model_inf
api.task.set_fields(task_id, fields)


def set_error(api: sly.Api, task_id, e: Exception, log_error: bool = True):
def set_error(api: sly.Api, task_id, e: Union[Exception, str], log_error: bool = True):
err = e if isinstance(e, str) else repr(e)
if log_error:
sly.logger.error(repr(e))
sly.logger.error(err)
else:
sly.logger.warn(err)
fields = [
{"field": "data.connected", "payload": False},
{"field": "data.connectionError", "payload": repr(e)},
{"field": "data.connectionError", "payload": err},
]
api.task.set_fields(task_id, fields)

Expand Down

0 comments on commit 873d8dd

Please sign in to comment.