Skip to content

Commit

Permalink
error message added to ui
Browse files Browse the repository at this point in the history
  • Loading branch information
vorozhkog committed Aug 1, 2024
1 parent c8c13f9 commit 64d374d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
13 changes: 7 additions & 6 deletions annotation-tool/debug.env
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
PYTHONUNBUFFERED=1
LOG_LEVEL="trace"

TASK_ID=52548 # ⬅️ change value (run 'While True Script' app and copy task ID)
TASK_ID=63377 # ⬅️ 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=34944 # ⬅️ change value
# modal.state.slyDatasetId=75910 # ⬅️ change value (optional)
context.userId=328 # ⬅️ change value
context.teamId=570 # ⬅️ change value
context.workspaceId=1101 # ⬅️ change value
modal.state.slyProjectId=39748 # ⬅️ change value
context.projectId=39748
# modal.state.slyDatasetId=75910 # ⬅️ change value (optional)

DEBUG_APP_DIR="debug/app_debug_data"
DEBUG_CACHE_DIR="debug/app_debug_cache"
5 changes: 5 additions & 0 deletions annotation-tool/src/gui.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
</div>

</div>
<sly-notification
v-if="data.inferenceError.length > 0"
:options="{'name': 'Inference Error', 'type': 'error'}"
:content="data.inferenceError">
</sly-notification>

<div><b>SETTINGS:</b></div>
<el-tabs class="small" v-model="state.tabName">
Expand Down
1 change: 1 addition & 0 deletions annotation-tool/src/init_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def init_ui(data, state):
data["tags"] = []
data["connected"] = False
data["connectionError"] = ""
data["inferenceError"] = ""
data["rollbackIds"] = []
data["ssOptions"] = {
"sessionTags": [
Expand Down
11 changes: 7 additions & 4 deletions annotation-tool/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ def inference(api: sly.Api, task_id, context, state, app_logger):
ann = ann.delete_label(label)

try:
ann_pred_json = api.task.send_request(state["sessionId"], "inference_image_id", data=data)
ann_pred_json = api.task.send_request(
state["sessionId"], "inference_image_id", data=data, raise_error=True
)
except Exception as e:
image_info = api.image.get_info_by_id(image_id)
sly.logger.info(
Expand All @@ -340,9 +342,10 @@ def inference(api: sly.Api, task_id, context, state, app_logger):
"settings": str(data["settings"]),
},
)
sly.logger.warn(
f"Couldn't process annotation prediction for image: {image_info.name} (ID: {image_id}). Image remain unchanged. Error: {e}"
)
# sly.logger.warn(
# f"Couldn't process annotation prediction for image: {image_info.name} (ID: {image_id}). Image remain unchanged. Error: {e}"
# )
set_error(api, task_id, e, "inference", log_error=False)
empty_ann_json = sly.Annotation(img_size=(image_info.height, image_info.width)).to_json()
ann_pred_json = {"annotation": empty_ann_json}

Expand Down
5 changes: 4 additions & 1 deletion shared_utils/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ 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.")
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 Expand Up @@ -73,6 +75,7 @@ def set_model_info(api, task_id, model_meta, model_info, inf_settings):
{"field": "state.tags", "payload": [True] * len(model_meta.tag_metas)},
{"field": "data.connected", "payload": True},
{"field": "data.connectionError", "payload": ""},
{"field": "data.inferenceError", "payload": ""},
{"field": "state.settings", "payload": inf_settings["settings"]},
{"field": "state.disabledSW", "payload": disabledSW},
]
Expand Down
36 changes: 26 additions & 10 deletions shared_utils/ui2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Union, Literal
import supervisely as sly


def set_model_info(api: sly.Api, task_id, model_meta: sly.ProjectMeta, model_info: dict, inf_settings: dict):
def set_model_info(
api: sly.Api, task_id, model_meta: sly.ProjectMeta, model_info: dict, inf_settings: dict
):
disabledSW = True
if "sliding_window_support" in model_info.keys() and model_info["sliding_window_support"] is not None:
if (
"sliding_window_support" in model_info.keys()
and model_info["sliding_window_support"] is not None
):
if isinstance(model_info["sliding_window_support"], bool):
if model_info["sliding_window_support"]:
disabledSW = False
Expand All @@ -19,28 +24,37 @@ def set_model_info(api: sly.Api, task_id, model_meta: sly.ProjectMeta, model_inf
{"field": "state.tags", "payload": [True] * len(model_meta.tag_metas)},
{"field": "data.connected", "payload": True},
{"field": "data.connectionError", "payload": ""},
{"field": "data.inferenceError", "payload": ""},
{"field": "state.settings", "payload": inf_settings["settings"]},
{"field": "state.disabledSW", "payload": disabledSW}
{"field": "state.disabledSW", "payload": disabledSW},
]
api.task.set_fields(task_id, fields)


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


def clean_error(api: sly.Api, task_id):
fields = [
{"field": "data.connectionError", "payload": ""},
{"field": "data.inferenceError", "payload": ""},
]
api.task.set_fields(task_id, fields)

Expand Down Expand Up @@ -70,10 +84,12 @@ def format_info(info: Dict[str, Any], trigger_to_del: Optional[str] = None) -> D
for name, data in info.items():
if trigger_to_del is not None:
if trigger_to_del.lower() in name.lower():
sly.logger.debug(f"Field {name} excluded from session info: found `{trigger_to_del}` in name")
sly.logger.debug(
f"Field {name} excluded from session info: found `{trigger_to_del}` in name"
)
continue

new_name = name.replace("_", " ").capitalize()
formated_info[new_name] = data

return formated_info
return formated_info

0 comments on commit 64d374d

Please sign in to comment.