learning-loop-node 0.18.0__py3-none-any.whl → 0.18.2__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.
@@ -21,6 +21,12 @@ class DetectorLogic():
21
21
  self.model_info = None
22
22
 
23
23
  def load_model_info_and_init_model(self):
24
+ """
25
+ Load model information from disk and initialize the model.
26
+
27
+ The detector node uses a lock to make sure that this is not called
28
+ concurrently with evaluate() or batch_evaluate().
29
+ """
24
30
  logging.info('Loading model from %s', GLOBALS.data_folder)
25
31
  self.model_info = ModelInformation.load_from_disk(f'{GLOBALS.data_folder}/model')
26
32
  if self.model_info is None:
@@ -42,21 +48,32 @@ class DetectorLogic():
42
48
 
43
49
  @abstractmethod
44
50
  def init(self):
45
- """Called when a (new) model was loaded. Initialize the model. Model information available via `self.model_info`"""
51
+ """
52
+ Initialize the model.
53
+
54
+ Called when a (new) model was loaded.
55
+ Model information available via `self.model_info`
56
+ The detector node uses a lock to make sure that this is not called
57
+ concurrently with evaluate() or batch_evaluate().
58
+ """
46
59
 
47
60
  @abstractmethod
48
61
  def evaluate(self, image: np.ndarray) -> ImageMetadata:
49
- """Evaluate the image and return the detections.
62
+ """
63
+ Evaluate the image and return the detections.
50
64
 
51
65
  Called by the detector node when an image should be evaluated (REST or SocketIO).
52
66
  The resulting detections should be stored in the ImageMetadata.
53
67
  Tags stored in the ImageMetadata will be uploaded to the learning loop.
54
- The function should return empty metadata if the detector is not initialized."""
68
+ The function should return empty metadata if the detector is not initialized.
69
+ """
55
70
 
56
71
  @abstractmethod
57
72
  def batch_evaluate(self, images: List[np.ndarray]) -> ImagesMetadata:
58
- """Evaluate a batch of images and return the detections.
73
+ """
74
+ Evaluate a batch of images and return the detections.
59
75
 
60
76
  The resulting detections per image should be stored in the ImagesMetadata.
61
77
  Tags stored in the ImagesMetadata will be uploaded to the learning loop.
62
- The function should return empty metadata if the detector is not initialized."""
78
+ The function should return empty metadata if the detector is not initialized.
79
+ """
@@ -190,13 +190,13 @@ class DetectorNode(Node):
190
190
 
191
191
  # simulate startup
192
192
  await self.detector_logic.soft_reload()
193
- self.detector_logic.load_model_info_and_init_model()
193
+ await self._load_model_info_and_init_model()
194
194
  self.operation_mode = OperationMode.Idle
195
195
 
196
196
  async def on_startup(self) -> None:
197
197
  try:
198
198
  self.outbox.ensure_continuous_upload()
199
- self.detector_logic.load_model_info_and_init_model()
199
+ await self._load_model_info_and_init_model()
200
200
  except Exception:
201
201
  self.log.exception("error during 'startup'")
202
202
  self.operation_mode = OperationMode.Idle
@@ -217,7 +217,7 @@ class DetectorNode(Node):
217
217
  # Initialize the Socket.IO server with 20MB buffer size
218
218
  self.sio = socketio.AsyncServer(
219
219
  async_mode='asgi',
220
- max_http_buffer_size=2e7, # 20MB
220
+ max_http_buffer_size=64 * 1024 * 1024, # 64 MiB
221
221
  )
222
222
  # Initialize and mount the ASGI app
223
223
  self.sio_app = socketio.ASGIApp(self.sio, socketio_path='/socket.io')
@@ -522,7 +522,7 @@ class DetectorNode(Node):
522
522
  self.log.info('Updated symlink for model to %s', os.readlink(model_symlink))
523
523
 
524
524
  try:
525
- self.detector_logic.load_model_info_and_init_model()
525
+ await self._load_model_info_and_init_model()
526
526
  except NodeNeedsRestartError:
527
527
  self.log.error('Node needs restart')
528
528
  sys.exit(0)
@@ -535,6 +535,10 @@ class DetectorNode(Node):
535
535
  await self._sync_status_with_loop()
536
536
  # self.reload(reason='new model installed')
537
537
 
538
+ async def _load_model_info_and_init_model(self) -> None:
539
+ async with self.detection_lock:
540
+ self.detector_logic.load_model_info_and_init_model()
541
+
538
542
  # ================================== API Implementations ==================================
539
543
 
540
544
  async def set_operation_mode(self, mode: OperationMode):
@@ -570,11 +574,8 @@ class DetectorNode(Node):
570
574
  cares about uploading to the loop and returns the detections as ImageMetadata object.
571
575
  """
572
576
 
573
- await self.detection_lock.acquire()
574
- try:
577
+ async with self.detection_lock:
575
578
  metadata = await run.io_bound(self.detector_logic.evaluate, image)
576
- finally:
577
- self.detection_lock.release()
578
579
 
579
580
  metadata.tags.extend(tags)
580
581
  metadata.source = source
@@ -606,14 +607,12 @@ class DetectorNode(Node):
606
607
  """
607
608
  Processing function for the detector node when a a batch inference is requested via SocketIO.
608
609
 
609
- This function infers the detections from all images, cares about uploading to the loop and returns the detections as a list of ImageMetadata.
610
+ This function infers the detections from all images,
611
+ cares about uploading to the loop and returns the detections as a list of ImageMetadata.
610
612
  """
611
613
 
612
- await self.detection_lock.acquire()
613
- try:
614
+ async with self.detection_lock:
614
615
  all_detections = await run.io_bound(self.detector_logic.batch_evaluate, images)
615
- finally:
616
- self.detection_lock.release()
617
616
 
618
617
  for metadata in all_detections.items:
619
618
  metadata.tags.extend(tags)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: learning-loop-node
3
- Version: 0.18.0
3
+ Version: 0.18.2
4
4
  Summary: Python Library for Nodes which connect to the Zauberzeug Learning Loop
5
5
  Home-page: https://github.com/zauberzeug/learning_loop_node
6
6
  License: MIT
@@ -12,8 +12,8 @@ learning_loop_node/data_classes/socket_response.py,sha256=tIdt-oYf6ULoJIDYQCecNM
12
12
  learning_loop_node/data_classes/training.py,sha256=TybwcCDf_NUaDUaOj30lPm-7Z3Qk9XFRibEX5qIv96Y,5737
13
13
  learning_loop_node/data_exchanger.py,sha256=nd9JNPLn9amIeTcSIyUPpbE97ORAcb5yNphvmpgWSUQ,9095
14
14
  learning_loop_node/detector/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- learning_loop_node/detector/detector_logic.py,sha256=wIOqguGedc0VUvUR812NLsG5ed5M1TLWnfQh1CIhW-g,2466
16
- learning_loop_node/detector/detector_node.py,sha256=8of6ku3Eu_t_yfgdFWqKDG06V14IVyvIJKca0vj5N80,31910
15
+ learning_loop_node/detector/detector_logic.py,sha256=8J70Fulrhex9IHFBAGYLR3a0-W-zsNj4h7mYLnrmUqM,2899
16
+ learning_loop_node/detector/detector_node.py,sha256=KtrlbB4sCwtP9cy6M-Qx0dHYKXYdt_6HagNUbVo6GG0,31925
17
17
  learning_loop_node/detector/exceptions.py,sha256=C6KbNPlSbtfgDrZx2Hbhm7Suk9jVoR3fMRCO0CkrMsQ,196
18
18
  learning_loop_node/detector/inbox_filter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  learning_loop_node/detector/inbox_filter/cam_observation_history.py,sha256=slPGm87TbBCfDUdpRTAM5yOz1An8Br5X_2HFJOGSrFg,3540
@@ -100,6 +100,6 @@ learning_loop_node/trainer/test_executor.py,sha256=6BVGDN_6f5GEMMEvDLSG1yzMybSvg
100
100
  learning_loop_node/trainer/trainer_logic.py,sha256=eK-01qZzi10UjLMCQX8vy5eW2FoghPj3rzzDC-s3Si4,8792
101
101
  learning_loop_node/trainer/trainer_logic_generic.py,sha256=KcHmXr-Hp8_Wuejzj8odY6sRPqi6aw1SEXv3YlbjM98,27057
102
102
  learning_loop_node/trainer/trainer_node.py,sha256=tsAMzJewdS7Bi_1b9FwG0d2lGlv2lY37pgOLWr0bP_I,4582
103
- learning_loop_node-0.18.0.dist-info/METADATA,sha256=LbLMgpf7nA5hBdsyPc-VUXvHcM-lfKPdBbQzEbuSb3U,15225
104
- learning_loop_node-0.18.0.dist-info/WHEEL,sha256=WGfLGfLX43Ei_YORXSnT54hxFygu34kMpcQdmgmEwCQ,88
105
- learning_loop_node-0.18.0.dist-info/RECORD,,
103
+ learning_loop_node-0.18.2.dist-info/METADATA,sha256=pDPv1j1iyt9KCziZNt3WHzAgqXykLeMPnO7Yb2lqf2A,15225
104
+ learning_loop_node-0.18.2.dist-info/WHEEL,sha256=WGfLGfLX43Ei_YORXSnT54hxFygu34kMpcQdmgmEwCQ,88
105
+ learning_loop_node-0.18.2.dist-info/RECORD,,