From 64d374df826a1ed5c76de99fffec8a92d5ccfc16 Mon Sep 17 00:00:00 2001 From: vorozhkog Date: Thu, 1 Aug 2024 03:23:41 +0100 Subject: [PATCH] error message added to ui --- annotation-tool/debug.env | 13 ++++++------ annotation-tool/src/gui.html | 5 +++++ annotation-tool/src/init_ui.py | 1 + annotation-tool/src/main.py | 11 +++++++---- shared_utils/connect.py | 5 ++++- shared_utils/ui2.py | 36 ++++++++++++++++++++++++---------- 6 files changed, 50 insertions(+), 21 deletions(-) diff --git a/annotation-tool/debug.env b/annotation-tool/debug.env index cb7b4ed..c1945c1 100644 --- a/annotation-tool/debug.env +++ b/annotation-tool/debug.env @@ -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" diff --git a/annotation-tool/src/gui.html b/annotation-tool/src/gui.html index 0842cba..489152d 100644 --- a/annotation-tool/src/gui.html +++ b/annotation-tool/src/gui.html @@ -81,6 +81,11 @@ + +
SETTINGS:
diff --git a/annotation-tool/src/init_ui.py b/annotation-tool/src/init_ui.py index a313419..99759cd 100644 --- a/annotation-tool/src/init_ui.py +++ b/annotation-tool/src/init_ui.py @@ -4,6 +4,7 @@ def init_ui(data, state): data["tags"] = [] data["connected"] = False data["connectionError"] = "" + data["inferenceError"] = "" data["rollbackIds"] = [] data["ssOptions"] = { "sessionTags": [ diff --git a/annotation-tool/src/main.py b/annotation-tool/src/main.py index b52a9fb..c72577c 100644 --- a/annotation-tool/src/main.py +++ b/annotation-tool/src/main.py @@ -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( @@ -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} diff --git a/shared_utils/connect.py b/shared_utils/connect.py index e2a81b1..96c9d88 100644 --- a/shared_utils/connect.py +++ b/shared_utils/connect.py @@ -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={} @@ -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}, ] diff --git a/shared_utils/ui2.py b/shared_utils/ui2.py index e0d1bbd..ff8194b 100644 --- a/shared_utils/ui2.py +++ b/shared_utils/ui2.py @@ -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 @@ -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) @@ -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 \ No newline at end of file + return formated_info