supervisely 6.73.331__py3-none-any.whl → 6.73.333__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -786,7 +786,7 @@ class TaskApi(ModuleApiBase, ModuleWithStatus):
786
786
  resp = self._api.post("tasks.data.get", data)
787
787
  return resp.json()["result"]
788
788
 
789
- def get_field(self, task_id: int, field: Dict):
789
+ def get_field(self, task_id: int, field: str):
790
790
  """get_field"""
791
791
  result = self.get_fields(task_id, [field])
792
792
  return result[field]
@@ -11,7 +11,7 @@ import time
11
11
  import uuid
12
12
  from collections import OrderedDict, defaultdict
13
13
  from concurrent.futures import ThreadPoolExecutor
14
- from dataclasses import asdict
14
+ from dataclasses import asdict, dataclass
15
15
  from functools import partial, wraps
16
16
  from pathlib import Path
17
17
  from queue import Queue
@@ -46,7 +46,7 @@ from supervisely.annotation.label import Label
46
46
  from supervisely.annotation.obj_class import ObjClass
47
47
  from supervisely.annotation.tag_collection import TagCollection
48
48
  from supervisely.annotation.tag_meta import TagMeta, TagValueType
49
- from supervisely.api.api import Api
49
+ from supervisely.api.api import Api, ApiField
50
50
  from supervisely.api.app_api import WorkflowMeta, WorkflowSettings
51
51
  from supervisely.api.image_api import ImageInfo
52
52
  from supervisely.app.content import StateJson, get_data_dir
@@ -91,6 +91,33 @@ except ImportError:
91
91
  from typing_extensions import Literal
92
92
 
93
93
 
94
+ @dataclass
95
+ class AutoRestartInfo:
96
+ deploy_params: dict
97
+
98
+ class Fields:
99
+ AUTO_RESTART_INFO = "autoRestartInfo"
100
+ DEPLOY_PARAMS = "deployParams"
101
+
102
+ def generate_fields(self) -> List[dict]:
103
+ return [
104
+ {
105
+ ApiField.FIELD: self.Fields.AUTO_RESTART_INFO,
106
+ ApiField.PAYLOAD: {self.Fields.DEPLOY_PARAMS: self.deploy_params},
107
+ }
108
+ ]
109
+
110
+ @classmethod
111
+ def from_response(cls, data: dict):
112
+ autorestart_info = data.get(cls.Fields.AUTO_RESTART_INFO, None)
113
+ if autorestart_info is None:
114
+ return None
115
+ return cls(deploy_params=autorestart_info.get(cls.Fields.DEPLOY_PARAMS, None))
116
+
117
+ def is_changed(self, deploy_params: dict) -> bool:
118
+ return self.deploy_params != deploy_params
119
+
120
+
94
121
  class Inference:
95
122
  FRAMEWORK_NAME: str = None
96
123
  """Name of framework to register models in Supervisely"""
@@ -127,6 +154,7 @@ class Inference:
127
154
  model_dir = os.path.join(get_data_dir(), "models")
128
155
  sly_fs.mkdir(model_dir)
129
156
 
157
+ self.autorestart = None
130
158
  self.device: str = None
131
159
  self.runtime: str = None
132
160
  self.model_precision: str = None
@@ -327,6 +355,9 @@ class Inference:
327
355
  self._user_layout_card.unlock()
328
356
 
329
357
  def set_params_to_gui(self, deploy_params: dict) -> None:
358
+ """
359
+ Set params for load_model method to GUI.
360
+ """
330
361
  if isinstance(self.gui, GUI.ServingGUI):
331
362
  self._user_layout_card.hide()
332
363
  self._api_request_model_info.set_text(json.dumps(deploy_params), "json")
@@ -677,6 +708,16 @@ class Inference:
677
708
  self.load_model(**deploy_params)
678
709
  self._model_served = True
679
710
  self._deploy_params = deploy_params
711
+ try:
712
+ if self.autorestart is None:
713
+ logger.debug("Autorestart info is not set. Creating new one.")
714
+ self.autorestart = AutoRestartInfo(self._deploy_params)
715
+ self.api.task.set_fields(self._task_id, self.autorestart.generate_fields())
716
+ elif self.autorestart.is_changed(self._deploy_params):
717
+ logger.debug("Autorestart info is changed. Updating.")
718
+ self.autorestart.deploy_params.update(self._deploy_params)
719
+ except Exception as e:
720
+ logger.warning(f"Failed to update autorestart info: {repr(e)}")
680
721
  if self.gui is not None:
681
722
  self.update_gui(self._model_served)
682
723
  self.gui.show_deployed_model_info(self)
@@ -2420,6 +2461,29 @@ class Inference:
2420
2461
  future.add_done_callback(end_callback)
2421
2462
  logger.debug("Scheduled task.", extra={"inference_request_uuid": inference_request_uuid})
2422
2463
 
2464
+ def _deploy_on_autorestart(self):
2465
+ try:
2466
+ self._api_request_model_layout._title = (
2467
+ "Model was deployed during auto restart with the following settings"
2468
+ )
2469
+ self._api_request_model_layout.update_data()
2470
+ deploy_params = self.autorestart.deploy_params
2471
+ if isinstance(self.gui, GUI.ServingGUITemplate):
2472
+ model_files = self._download_model_files(deploy_params)
2473
+ deploy_params["model_files"] = model_files
2474
+ self._load_model_headless(**deploy_params)
2475
+ elif isinstance(self.gui, GUI.ServingGUI):
2476
+ self._load_model(deploy_params)
2477
+
2478
+ self.set_params_to_gui(deploy_params)
2479
+ # update to set correct device
2480
+ device = deploy_params.get("device", "cpu")
2481
+ self.gui.set_deployed(device)
2482
+ return {"result": "model was successfully deployed"}
2483
+ except Exception as e:
2484
+ self.gui._success_label.hide()
2485
+ raise e
2486
+
2423
2487
  def serve(self):
2424
2488
  if not self._use_gui and not self._is_local_deploy:
2425
2489
  Progress("Deploying model ...", 1)
@@ -2463,6 +2527,21 @@ class Inference:
2463
2527
  else:
2464
2528
  self._app = Application(layout=self.get_ui())
2465
2529
 
2530
+ try:
2531
+ if self._task_id is not None:
2532
+ logger.debug("Checking autorestart info...")
2533
+ response = self.api.task.get_fields(
2534
+ self._task_id, [AutoRestartInfo.Fields.AUTO_RESTART_INFO]
2535
+ )
2536
+ self.autorestart = AutoRestartInfo.from_response(response)
2537
+ if self.autorestart is not None:
2538
+ logger.debug("Autorestart info:", extra=self.autorestart.deploy_params)
2539
+ self._deploy_on_autorestart()
2540
+ else:
2541
+ logger.debug("Autorestart info is not set.")
2542
+ except Exception:
2543
+ logger.error("Autorestart failed.", exc_info=True)
2544
+
2466
2545
  server = self._app.get_server()
2467
2546
  self._app.set_ready_check_function(self.is_model_deployed)
2468
2547
 
@@ -368,6 +368,9 @@ class VideoFigure:
368
368
  if self._priority is not None:
369
369
  data_json[ApiField.PRIORITY] = self._priority
370
370
 
371
+ if self.track_id is not None:
372
+ data_json[ApiField.TRACK_ID] = self.track_id
373
+
371
374
  self._add_creation_info(data_json)
372
375
  return data_json
373
376
 
@@ -441,9 +444,7 @@ class VideoFigure:
441
444
  raise RuntimeError("Figure can not be deserialized: key_id_map is None")
442
445
  object_key = key_id_map.get_object_key(object_id)
443
446
  if object_key is None:
444
- raise RuntimeError(
445
- "Object with id={!r} not found in key_id_map".format(object_id)
446
- )
447
+ raise RuntimeError("Object with id={!r} not found in key_id_map".format(object_id))
447
448
 
448
449
  object = objects.get(object_key)
449
450
  if object is None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supervisely
3
- Version: 6.73.331
3
+ Version: 6.73.333
4
4
  Summary: Supervisely Python SDK.
5
5
  Home-page: https://github.com/supervisely/supervisely
6
6
  Author: Supervisely
@@ -42,7 +42,7 @@ supervisely/api/remote_storage_api.py,sha256=qTuPhPsstgEjRm1g-ZInddik8BNC_38YvBB
42
42
  supervisely/api/report_api.py,sha256=Om7CGulUbQ4BuJ16eDtz7luLe0JQNqab-LoLpUXu7YE,7123
43
43
  supervisely/api/role_api.py,sha256=aBL4mxtn08LDPXQuS153-lQFN6N2kcwiz8MbescZ8Gk,3044
44
44
  supervisely/api/storage_api.py,sha256=FPGYf3Rn3LBoe38RBNdoiURs306oshzvKOEOQ56XAbs,13030
45
- supervisely/api/task_api.py,sha256=WUyovA322egcfjG6Iv_vX8RdfU_3Bw7qxcniYeLpqwA,53874
45
+ supervisely/api/task_api.py,sha256=ZuPXAfHO5WwWRfR0f93iprkcGlqRMK0q2UXF55dGneo,53873
46
46
  supervisely/api/team_api.py,sha256=bEoz3mrykvliLhKnzEy52vzdd_H8VBJCpxF-Bnek9Q8,19467
47
47
  supervisely/api/user_api.py,sha256=4S97yIc6AMTZCa0N57lzETnpIE8CeqClvCb6kjUkgfc,24940
48
48
  supervisely/api/video_annotation_tool_api.py,sha256=3A9-U8WJzrTShP_n9T8U01M9FzGYdeS51CCBTzUnooo,6686
@@ -883,7 +883,7 @@ supervisely/nn/benchmark/visualization/widgets/table/__init__.py,sha256=47DEQpj8
883
883
  supervisely/nn/benchmark/visualization/widgets/table/table.py,sha256=atmDnF1Af6qLQBUjLhK18RMDKAYlxnsuVHMSEa5a-e8,4319
884
884
  supervisely/nn/inference/__init__.py,sha256=QFukX2ip-U7263aEPCF_UCFwj6EujbMnsgrXp5Bbt8I,1623
885
885
  supervisely/nn/inference/cache.py,sha256=LAirR5mFHCtK59EO1lefQ2qhpp0vBvRTH26EVrs13Y0,32073
886
- supervisely/nn/inference/inference.py,sha256=O0GR2o0t9hDh-bMdiKrxk-hxdmQU1M-44aIcZM89Qo8,166222
886
+ supervisely/nn/inference/inference.py,sha256=pIylesTNxmhnJqd3sd5cs9QjAew2wPuqH63KOlimOqA,169495
887
887
  supervisely/nn/inference/session.py,sha256=jmkkxbe2kH-lEgUU6Afh62jP68dxfhF5v6OGDfLU62E,35757
888
888
  supervisely/nn/inference/video_inference.py,sha256=8Bshjr6rDyLay5Za8IB8Dr6FURMO2R_v7aELasO8pR4,5746
889
889
  supervisely/nn/inference/gui/__init__.py,sha256=wCxd-lF5Zhcwsis-wScDA8n1Gk_1O00PKgDviUZ3F1U,221
@@ -1051,7 +1051,7 @@ supervisely/video_annotation/frame.py,sha256=H1G7Wl4LEEmQE-E0B2QWD8kyzZ4-w-GJSUd
1051
1051
  supervisely/video_annotation/frame_collection.py,sha256=RZrnw7lURgvzRrskwvnEIQQfJkp9htMhircU3hLiHVY,15031
1052
1052
  supervisely/video_annotation/key_id_map.py,sha256=KayYOhTtAe3ITq1-NQ82T6YIiBjmu4aJm8t4UxdvI8U,37712
1053
1053
  supervisely/video_annotation/video_annotation.py,sha256=syqfhIerzhMWNh8scM_kWskBl8R2E-pfOSW_jN2Lb1Y,28867
1054
- supervisely/video_annotation/video_figure.py,sha256=j1ZoDnMLO_bFRUI19GDK3A2CzTWGr5pGYbd3NjC7ztE,23766
1054
+ supervisely/video_annotation/video_figure.py,sha256=9oWtcixcbJ8Ue89-dnaU1Re2Zhjzwro5M-tdUN5BP80,23824
1055
1055
  supervisely/video_annotation/video_object.py,sha256=i-oiliNpDr2X4Wcy9DJ7sBbuVUT3QYiSrtklCCJGVsY,16736
1056
1056
  supervisely/video_annotation/video_object_collection.py,sha256=Epu9MAC9uZiThfBn4NxKbQ7JRbW4eFZHglTzaJJ9WUQ,9047
1057
1057
  supervisely/video_annotation/video_tag.py,sha256=a1mdzRoq1GLJl7GxyHNGkX1PEGvudlVoqCDn0MxxAEQ,18306
@@ -1082,9 +1082,9 @@ supervisely/worker_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
1082
1082
  supervisely/worker_proto/worker_api_pb2.py,sha256=VQfi5JRBHs2pFCK1snec3JECgGnua3Xjqw_-b3aFxuM,59142
1083
1083
  supervisely/worker_proto/worker_api_pb2_grpc.py,sha256=3BwQXOaP9qpdi0Dt9EKG--Lm8KGN0C5AgmUfRv77_Jk,28940
1084
1084
  supervisely_lib/__init__.py,sha256=7-3QnN8Zf0wj8NCr2oJmqoQWMKKPKTECvjH9pd2S5vY,159
1085
- supervisely-6.73.331.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1086
- supervisely-6.73.331.dist-info/METADATA,sha256=Jl2Q2-aQqYnnh1EDKOY95wpocUZnttqC5StXwKTOO8I,33596
1087
- supervisely-6.73.331.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1088
- supervisely-6.73.331.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1089
- supervisely-6.73.331.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1090
- supervisely-6.73.331.dist-info/RECORD,,
1085
+ supervisely-6.73.333.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1086
+ supervisely-6.73.333.dist-info/METADATA,sha256=dYUKmQZXH6UwwNCIKAYsS0ycDRlPKEpcUlBM7q6djPU,33596
1087
+ supervisely-6.73.333.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1088
+ supervisely-6.73.333.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1089
+ supervisely-6.73.333.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1090
+ supervisely-6.73.333.dist-info/RECORD,,