learning-loop-node 0.12.0__tar.gz → 0.13.0__tar.gz

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.

Potentially problematic release.


This version of learning-loop-node might be problematic. Click here for more details.

Files changed (104) hide show
  1. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/PKG-INFO +22 -3
  2. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/README.md +21 -2
  3. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/annotation/annotator_node.py +2 -1
  4. learning_loop_node-0.13.0/learning_loop_node/data_classes/__init__.py +19 -0
  5. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/data_classes/annotations.py +1 -11
  6. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/data_classes/general.py +25 -7
  7. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/data_classes/training.py +1 -21
  8. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/data_exchanger.py +0 -3
  9. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/detector_node.py +110 -13
  10. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/outbox.py +1 -6
  11. learning_loop_node-0.13.0/learning_loop_node/detector/rest/about.py +26 -0
  12. learning_loop_node-0.13.0/learning_loop_node/detector/rest/model_version_control.py +46 -0
  13. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/rest/operation_mode.py +2 -9
  14. learning_loop_node-0.13.0/learning_loop_node/enums/__init__.py +6 -0
  15. learning_loop_node-0.13.0/learning_loop_node/enums/annotator.py +11 -0
  16. learning_loop_node-0.13.0/learning_loop_node/enums/detector.py +18 -0
  17. learning_loop_node-0.13.0/learning_loop_node/enums/general.py +9 -0
  18. learning_loop_node-0.13.0/learning_loop_node/enums/trainer.py +22 -0
  19. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/loop_communication.py +21 -0
  20. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/node.py +9 -0
  21. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/annotator/test_annotator_node.py +2 -2
  22. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/general/test_data_classes.py +2 -1
  23. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/states/test_state_detecting.py +1 -1
  24. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/states/test_state_download_train_model.py +1 -1
  25. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/states/test_state_prepare.py +2 -1
  26. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/states/test_state_sync_confusion_matrix.py +1 -1
  27. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/states/test_state_train.py +1 -1
  28. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/states/test_state_upload_detections.py +2 -1
  29. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/states/test_state_upload_model.py +2 -1
  30. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/test_errors.py +1 -1
  31. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/test_trainer_states.py +2 -1
  32. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/trainer_logic.py +2 -1
  33. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/trainer_logic_generic.py +3 -2
  34. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/trainer_node.py +2 -1
  35. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/pyproject.toml +1 -1
  36. learning_loop_node-0.12.0/learning_loop_node/data_classes/__init__.py +0 -20
  37. learning_loop_node-0.12.0/learning_loop_node/detector/rest/about.py +0 -50
  38. learning_loop_node-0.12.0/learning_loop_node/detector/rest/model_version_control.py +0 -118
  39. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/__init__.py +0 -0
  40. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/annotation/__init__.py +0 -0
  41. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/annotation/annotator_logic.py +0 -0
  42. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/data_classes/detections.py +0 -0
  43. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/data_classes/image_metadata.py +0 -0
  44. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/data_classes/socket_response.py +0 -0
  45. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/__init__.py +0 -0
  46. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/detector_logic.py +0 -0
  47. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/inbox_filter/__init__.py +0 -0
  48. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/inbox_filter/cam_observation_history.py +0 -0
  49. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/inbox_filter/relevance_filter.py +0 -0
  50. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/rest/__init__.py +0 -0
  51. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/rest/backdoor_controls.py +0 -0
  52. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/rest/detect.py +0 -0
  53. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/rest/outbox_mode.py +0 -0
  54. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/detector/rest/upload.py +0 -0
  55. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/examples/novelty_score_updater.py +0 -0
  56. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/globals.py +0 -0
  57. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/helpers/__init__.py +0 -0
  58. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/helpers/environment_reader.py +0 -0
  59. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/helpers/gdrive_downloader.py +0 -0
  60. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/helpers/log_conf.py +0 -0
  61. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/helpers/misc.py +0 -0
  62. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/py.typed +0 -0
  63. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/rest.py +0 -0
  64. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/__init__.py +0 -0
  65. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/annotator/__init__.py +0 -0
  66. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/annotator/conftest.py +0 -0
  67. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/annotator/pytest.ini +0 -0
  68. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/__init__.py +0 -0
  69. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/conftest.py +0 -0
  70. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/inbox_filter/__init__.py +0 -0
  71. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/inbox_filter/test_observation.py +0 -0
  72. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/inbox_filter/test_relevance_group.py +0 -0
  73. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/inbox_filter/test_unexpected_observations_count.py +0 -0
  74. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/pytest.ini +0 -0
  75. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/test.jpg +0 -0
  76. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/test_client_communication.py +0 -0
  77. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/test_detector_node.py +0 -0
  78. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/test_outbox.py +0 -0
  79. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/test_relevance_filter.py +0 -0
  80. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/detector/testing_detector.py +0 -0
  81. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/general/__init__.py +0 -0
  82. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/general/conftest.py +0 -0
  83. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/general/pytest.ini +0 -0
  84. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/general/test_data/file_1.txt +0 -0
  85. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/general/test_data/file_2.txt +0 -0
  86. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/general/test_data/model.json +0 -0
  87. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/general/test_downloader.py +0 -0
  88. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/general/test_learning_loop_node.py +0 -0
  89. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/test_helper.py +0 -0
  90. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/__init__.py +0 -0
  91. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/conftest.py +0 -0
  92. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/pytest.ini +0 -0
  93. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/state_helper.py +0 -0
  94. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/states/__init__.py +0 -0
  95. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/states/test_state_cleanup.py +0 -0
  96. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/tests/trainer/testing_trainer_logic.py +0 -0
  97. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/__init__.py +0 -0
  98. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/downloader.py +0 -0
  99. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/exceptions.py +0 -0
  100. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/executor.py +0 -0
  101. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/io_helpers.py +0 -0
  102. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/rest/__init__.py +0 -0
  103. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/rest/backdoor_controls.py +0 -0
  104. {learning_loop_node-0.12.0 → learning_loop_node-0.13.0}/learning_loop_node/trainer/test_executor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: learning-loop-node
3
- Version: 0.12.0
3
+ Version: 0.13.0
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
@@ -106,11 +106,11 @@ The detector also has a sio **upload endpoint** that can be used to upload image
106
106
 
107
107
  The endpoint returns None if the upload was successful and an error message otherwise.
108
108
 
109
- ### Changing the model version
109
+ ### Changing the model versioning mode
110
110
 
111
111
  The detector can be configured to one of the following behaviors:
112
112
 
113
- - download use a specific model version
113
+ - use a specific model version
114
114
  - automatically update the model version according to the learning loop deployment target
115
115
  - pause the model updates and use the version that was last loaded
116
116
 
@@ -124,6 +124,15 @@ The model versioning configuration can be accessed/changed via a REST endpoint.
124
124
  Note that the configuration is not persistent, however, the default behavior on startup can be configured via the environment variable `VERSION_CONTROL_DEFAULT`.
125
125
  If the environment variable is set to `VERSION_CONTROL_DEFAULT=PAUSE`, the detector will pause the model updates on startup. Otherwise, the detector will automatically follow the loop deployment target.
126
126
 
127
+ The model versioning configuration can also be changed via a socketio event:
128
+
129
+ - Configure the detector to use a specific model version: `sio.emit('set_model_version_mode', '1.0')`
130
+ - Configure the detector to automatically update the model version: `sio.emit('set_model_version_mode', 'follow_loop')`
131
+ - Pause the model updates: `sio.emit('set_model_version_mode', 'pause')`
132
+
133
+ There is also a GET endpoint to fetch the current model versioning configuration:
134
+ `sio.emit('get_model_version')` or `curl http://localhost/model_version`
135
+
127
136
  ### Changing the outbox mode
128
137
 
129
138
  If the autoupload is set to `all` or `filtered` (selected) images and the corresponding detections are saved on HDD (the outbox). A background thread will upload the images and detections to the Learning Loop. The outbox is located in the `outbox` folder in the root directory of the node. The outbox can be cleared by deleting the files in the folder.
@@ -138,6 +147,16 @@ Example Usage:
138
147
  The current state can be queried via a GET request:
139
148
  `curl http://localhost/outbox_mode`
140
149
 
150
+ Alternatively, the outbox mode can be changed via a socketio event:
151
+
152
+ - Enable upload: `sio.emit('set_outbox_mode', 'continuous_upload')`
153
+ - Disable upload: `sio.emit('set_outbox_mode', 'stopped')`
154
+
155
+ The outbox mode can also be queried via:
156
+
157
+ - HTTP: `curl http://localhost/outbox_mode`
158
+ - SocketIO: `sio.emit('get_outbox_mode')`
159
+
141
160
  ### Explicit upload
142
161
 
143
162
  The detector has a REST endpoint to upload images (and detections) to the Learning Loop. The endpoint takes a POST request with the image and optionally the detections. The image is expected to be in jpg format. The detections are expected to be a json dictionary. Example:
@@ -66,11 +66,11 @@ The detector also has a sio **upload endpoint** that can be used to upload image
66
66
 
67
67
  The endpoint returns None if the upload was successful and an error message otherwise.
68
68
 
69
- ### Changing the model version
69
+ ### Changing the model versioning mode
70
70
 
71
71
  The detector can be configured to one of the following behaviors:
72
72
 
73
- - download use a specific model version
73
+ - use a specific model version
74
74
  - automatically update the model version according to the learning loop deployment target
75
75
  - pause the model updates and use the version that was last loaded
76
76
 
@@ -84,6 +84,15 @@ The model versioning configuration can be accessed/changed via a REST endpoint.
84
84
  Note that the configuration is not persistent, however, the default behavior on startup can be configured via the environment variable `VERSION_CONTROL_DEFAULT`.
85
85
  If the environment variable is set to `VERSION_CONTROL_DEFAULT=PAUSE`, the detector will pause the model updates on startup. Otherwise, the detector will automatically follow the loop deployment target.
86
86
 
87
+ The model versioning configuration can also be changed via a socketio event:
88
+
89
+ - Configure the detector to use a specific model version: `sio.emit('set_model_version_mode', '1.0')`
90
+ - Configure the detector to automatically update the model version: `sio.emit('set_model_version_mode', 'follow_loop')`
91
+ - Pause the model updates: `sio.emit('set_model_version_mode', 'pause')`
92
+
93
+ There is also a GET endpoint to fetch the current model versioning configuration:
94
+ `sio.emit('get_model_version')` or `curl http://localhost/model_version`
95
+
87
96
  ### Changing the outbox mode
88
97
 
89
98
  If the autoupload is set to `all` or `filtered` (selected) images and the corresponding detections are saved on HDD (the outbox). A background thread will upload the images and detections to the Learning Loop. The outbox is located in the `outbox` folder in the root directory of the node. The outbox can be cleared by deleting the files in the folder.
@@ -98,6 +107,16 @@ Example Usage:
98
107
  The current state can be queried via a GET request:
99
108
  `curl http://localhost/outbox_mode`
100
109
 
110
+ Alternatively, the outbox mode can be changed via a socketio event:
111
+
112
+ - Enable upload: `sio.emit('set_outbox_mode', 'continuous_upload')`
113
+ - Disable upload: `sio.emit('set_outbox_mode', 'stopped')`
114
+
115
+ The outbox mode can also be queried via:
116
+
117
+ - HTTP: `curl http://localhost/outbox_mode`
118
+ - SocketIO: `sio.emit('get_outbox_mode')`
119
+
101
120
  ### Explicit upload
102
121
 
103
122
  The detector has a REST endpoint to upload images (and detections) to the Learning Loop. The endpoint takes a POST request with the image and optionally the detections. The image is expected to be in jpg format. The detections are expected to be a json dictionary. Example:
@@ -73,7 +73,8 @@ class AnnotatorNode(Node):
73
73
  capabilities=['segmentation']
74
74
  )
75
75
 
76
- self.log.debug('Sending status %s', status)
76
+ self.log_status_on_change(status.state.value if status.state else 'None', status)
77
+
77
78
  try:
78
79
  result = await self.sio_client.call('update_annotation_node', jsonable_encoder(asdict(status)), timeout=10)
79
80
  except Exception:
@@ -0,0 +1,19 @@
1
+ from .annotations import AnnotationData, SegmentationAnnotation, ToolOutput, UserInput
2
+ from .detections import (BoxDetection, ClassificationDetection, Detections, Observation, Point, PointDetection,
3
+ SegmentationDetection, Shape)
4
+ from .general import (AboutResponse, AnnotationNodeStatus, Category, Context, DetectionStatus, ErrorConfiguration,
5
+ ModelInformation, ModelVersionResponse, NodeState, NodeStatus)
6
+ from .image_metadata import ImageMetadata
7
+ from .socket_response import SocketResponse
8
+ from .training import Errors, PretrainedModel, Training, TrainingError, TrainingOut, TrainingStateData, TrainingStatus
9
+
10
+ __all__ = [
11
+ 'AboutResponse', 'AnnotationData', 'SegmentationAnnotation', 'ToolOutput', 'UserInput',
12
+ 'BoxDetection', 'ClassificationDetection', 'ImageMetadata', 'Observation', 'Point', 'PointDetection',
13
+ 'SegmentationDetection', 'Shape', 'Detections',
14
+ 'AnnotationNodeStatus', 'Category', 'Context', 'DetectionStatus', 'ErrorConfiguration',
15
+ 'ModelInformation', 'NodeState', 'NodeStatus', 'ModelVersionResponse',
16
+ 'SocketResponse',
17
+ 'Errors', 'PretrainedModel', 'Training',
18
+ 'TrainingError', 'TrainingOut', 'TrainingStateData', 'TrainingStatus',
19
+ ]
@@ -1,24 +1,14 @@
1
1
  import sys
2
2
  from dataclasses import dataclass
3
- from enum import Enum
4
3
  from typing import Optional, Union
5
4
 
5
+ from ..enums import AnnotationEventType
6
6
  from .detections import Point, Shape
7
7
  from .general import Category, Context
8
8
 
9
9
  KWONLY_SLOTS = {'kw_only': True, 'slots': True} if sys.version_info >= (3, 10) else {}
10
10
 
11
11
 
12
- class AnnotationEventType(str, Enum):
13
- LeftMouseDown = 'left_mouse_down'
14
- RightMouseDown = 'right_mouse_down'
15
- MouseMove = 'mouse_move'
16
- LeftMouseUp = 'left_mouse_up'
17
- RightMouseUp = 'right_mouse_up'
18
- KeyUp = 'key_up'
19
- KeyDown = 'key_down'
20
-
21
-
22
12
  @dataclass(**KWONLY_SLOTS)
23
13
  class AnnotationData():
24
14
  coordinate: Point
@@ -8,14 +8,9 @@ from typing import Dict, List, Optional, Union
8
8
 
9
9
  from dacite import from_dict
10
10
 
11
- KWONLY_SLOTS = {'kw_only': True, 'slots': True} if sys.version_info >= (3, 10) else {}
12
-
11
+ from ..enums import CategoryType
13
12
 
14
- class CategoryType(str, Enum):
15
- Box = 'box'
16
- Point = 'point'
17
- Segmentation = 'segmentation'
18
- Classification = 'classification'
13
+ KWONLY_SLOTS = {'kw_only': True, 'slots': True} if sys.version_info >= (3, 10) else {}
19
14
 
20
15
 
21
16
  @dataclass(**KWONLY_SLOTS)
@@ -104,6 +99,29 @@ class ModelInformation():
104
99
  return from_dict(ModelInformation, data=data)
105
100
 
106
101
 
102
+ @dataclass(**KWONLY_SLOTS)
103
+ class AboutResponse:
104
+ operation_mode: str = field(metadata={"description": "The operation mode of the detector node"})
105
+ state: Optional[str] = field(metadata={
106
+ "description": "The state of the detector node",
107
+ "example": "idle, online, detecting"})
108
+ model_info: Optional[ModelInformation] = field(metadata={
109
+ "description": "Information about the model of the detector node"})
110
+ target_model: Optional[str] = field(metadata={"description": "The target model of the detector node"})
111
+ version_control: str = field(metadata={
112
+ "description": "The version control mode of the detector node",
113
+ "example": "follow_loop, specific_version, pause"})
114
+
115
+
116
+ @dataclass(**KWONLY_SLOTS)
117
+ class ModelVersionResponse:
118
+ current_version: str = field(metadata={"description": "The version of the model currently used by the detector."})
119
+ target_version: str = field(metadata={"description": "The target model version set in the detector."})
120
+ loop_version: str = field(metadata={"description": "The target model version specified by the loop."})
121
+ local_versions: List[str] = field(metadata={"description": "The locally available versions of the model."})
122
+ version_control: str = field(metadata={"description": "The version control mode."})
123
+
124
+
107
125
  @dataclass(**KWONLY_SLOTS)
108
126
  class ErrorConfiguration():
109
127
  begin_training: Optional[bool] = False
@@ -2,11 +2,11 @@
2
2
  import sys
3
3
  import time
4
4
  from dataclasses import dataclass, field
5
- from enum import Enum
6
5
  from pathlib import Path
7
6
  from typing import Any, Dict, List, Optional
8
7
  from uuid import uuid4
9
8
 
9
+ from ..enums import TrainerState
10
10
  from ..helpers.misc import create_image_folder, create_training_folder
11
11
  # pylint: disable=no-name-in-module
12
12
  from .general import Category, Context
@@ -21,26 +21,6 @@ class PretrainedModel():
21
21
  description: str
22
22
 
23
23
 
24
- class TrainerState(str, Enum):
25
- Idle = 'idle'
26
- Initialized = 'initialized'
27
- Preparing = 'preparing'
28
- DataDownloading = 'data_downloading'
29
- DataDownloaded = 'data_downloaded'
30
- TrainModelDownloading = 'train_model_downloading'
31
- TrainModelDownloaded = 'train_model_downloaded'
32
- TrainingRunning = 'running'
33
- TrainingFinished = 'training_finished'
34
- ConfusionMatrixSyncing = 'confusion_matrix_syncing'
35
- ConfusionMatrixSynced = 'confusion_matrix_synced'
36
- TrainModelUploading = 'train_model_uploading'
37
- TrainModelUploaded = 'train_model_uploaded'
38
- Detecting = 'detecting'
39
- Detected = 'detected'
40
- DetectionUploading = 'detection_uploading'
41
- ReadyForCleanup = 'ready_for_cleanup'
42
-
43
-
44
24
  @dataclass(**KWONLY_SLOTS)
45
25
  class TrainingStatus():
46
26
  id: str # NOTE this must not be changed, but tests wont detect a change -> update tests!
@@ -124,9 +124,6 @@ class DataExchanger():
124
124
 
125
125
  async def _download_one_image(self, path: str, image_id: str, image_folder: str) -> None:
126
126
  response = await self.loop_communicator.get(path)
127
- if response.status_code == 429:
128
- await asyncio.sleep(1)
129
- response = await self.loop_communicator.get(path)
130
127
  if response.status_code != HTTPStatus.OK:
131
128
  logging.error('bad status code %s for %s. Details: %s', response.status_code, path, response.text)
132
129
  return
@@ -6,7 +6,7 @@ import subprocess
6
6
  from dataclasses import asdict
7
7
  from datetime import datetime
8
8
  from threading import Thread
9
- from typing import Dict, List, Optional, Union
9
+ from typing import Dict, List, Optional
10
10
 
11
11
  import numpy as np
12
12
  import socketio
@@ -14,9 +14,11 @@ from dacite import from_dict
14
14
  from fastapi.encoders import jsonable_encoder
15
15
  from socketio import AsyncClient
16
16
 
17
- from ..data_classes import Category, Context, DetectionStatus, ImageMetadata, ModelInformation, Shape
17
+ from ..data_classes import (AboutResponse, Category, Context, DetectionStatus, ImageMetadata, ModelInformation,
18
+ ModelVersionResponse, Shape)
18
19
  from ..data_classes.socket_response import SocketResponse
19
20
  from ..data_exchanger import DataExchanger, DownloadError
21
+ from ..enums import OperationMode, VersionMode
20
22
  from ..globals import GLOBALS
21
23
  from ..helpers import environment_reader
22
24
  from ..node import Node
@@ -30,7 +32,6 @@ from .rest import model_version_control as rest_version_control
30
32
  from .rest import operation_mode as rest_mode
31
33
  from .rest import outbox_mode as rest_outbox_mode
32
34
  from .rest import upload as rest_upload
33
- from .rest.operation_mode import OperationMode
34
35
 
35
36
 
36
37
  class DetectorNode(Node):
@@ -58,8 +59,8 @@ class DetectorNode(Node):
58
59
  # FollowLoop: the detector node will follow the loop and update the model if necessary
59
60
  # SpecificVersion: the detector node will update to a specific version, set via the /model_version endpoint
60
61
  # Pause: the detector node will not update the model
61
- self.version_control: rest_version_control.VersionMode = rest_version_control.VersionMode.Pause if os.environ.get(
62
- 'VERSION_CONTROL_DEFAULT', 'follow_loop').lower() == 'pause' else rest_version_control.VersionMode.FollowLoop
62
+ self.version_control: VersionMode = VersionMode.Pause if os.environ.get(
63
+ 'VERSION_CONTROL_DEFAULT', 'follow_loop').lower() == 'pause' else VersionMode.FollowLoop
63
64
  self.target_model: Optional[ModelInformation] = None
64
65
  self.loop_deployment_target: Optional[ModelInformation] = None
65
66
 
@@ -75,6 +76,74 @@ class DetectorNode(Node):
75
76
 
76
77
  self.setup_sio_server()
77
78
 
79
+ def get_about_response(self) -> AboutResponse:
80
+ return AboutResponse(
81
+ operation_mode=self.operation_mode.value,
82
+ state=self.status.state,
83
+ model_info=self.detector_logic._model_info, # pylint: disable=protected-access
84
+ target_model=self.target_model.version if self.target_model else None,
85
+ version_control=self.version_control.value
86
+ )
87
+
88
+ def get_model_version_response(self) -> ModelVersionResponse:
89
+ current_version = self.detector_logic._model_info.version if self.detector_logic._model_info is not None else 'None' # pylint: disable=protected-access
90
+ target_version = self.target_model.version if self.target_model is not None else 'None'
91
+ loop_version = self.loop_deployment_target.version if self.loop_deployment_target is not None else 'None'
92
+
93
+ local_versions: list[str] = []
94
+ models_path = os.path.join(GLOBALS.data_folder, 'models')
95
+ local_models = os.listdir(models_path) if os.path.exists(models_path) else []
96
+ for model in local_models:
97
+ if model.replace('.', '').isdigit():
98
+ local_versions.append(model)
99
+
100
+ return ModelVersionResponse(
101
+ current_version=current_version,
102
+ target_version=target_version,
103
+ loop_version=loop_version,
104
+ local_versions=local_versions,
105
+ version_control=self.version_control.value,
106
+ )
107
+
108
+ async def set_model_version_mode(self, version_control_mode: str) -> None:
109
+
110
+ if version_control_mode == 'follow_loop':
111
+ self.version_control = VersionMode.FollowLoop
112
+ elif version_control_mode == 'pause':
113
+ self.version_control = VersionMode.Pause
114
+ else:
115
+ self.version_control = VersionMode.SpecificVersion
116
+ if not version_control_mode or not version_control_mode.replace('.', '').isdigit():
117
+ raise Exception('Invalid version number')
118
+ target_version = version_control_mode
119
+
120
+ if self.target_model is not None and self.target_model.version == target_version:
121
+ return
122
+
123
+ # Fetch the model uuid by version from the loop
124
+ uri = f'/{self.organization}/projects/{self.project}/models'
125
+ response = await self.loop_communicator.get(uri)
126
+ if response.status_code != 200:
127
+ self.version_control = VersionMode.Pause
128
+ raise Exception('Failed to load models from learning loop')
129
+
130
+ models = response.json()['models']
131
+ models_with_target_version = [m for m in models if m['version'] == target_version]
132
+ if len(models_with_target_version) == 0:
133
+ self.version_control = VersionMode.Pause
134
+ raise Exception(f'No Model with version {target_version}')
135
+ if len(models_with_target_version) > 1:
136
+ self.version_control = VersionMode.Pause
137
+ raise Exception(f'Multiple models with version {target_version}')
138
+
139
+ model_id = models_with_target_version[0]['id']
140
+ model_host = models_with_target_version[0].get('host', 'unknown')
141
+
142
+ self.target_model = ModelInformation(organization=self.organization, project=self.project,
143
+ host=model_host, categories=[],
144
+ id=model_id,
145
+ version=target_version)
146
+
78
147
  async def soft_reload(self) -> None:
79
148
  # simulate init
80
149
  self.organization = environment_reader.organization()
@@ -85,8 +154,8 @@ class DetectorNode(Node):
85
154
  Context(organization=self.organization, project=self.project),
86
155
  self.loop_communicator)
87
156
  self.relevance_filter = RelevanceFilter(self.outbox)
88
- self.version_control = rest_version_control.VersionMode.Pause if os.environ.get(
89
- 'VERSION_CONTROL_DEFAULT', 'follow_loop').lower() == 'pause' else rest_version_control.VersionMode.FollowLoop
157
+ self.version_control = VersionMode.Pause if os.environ.get(
158
+ 'VERSION_CONTROL_DEFAULT', 'follow_loop').lower() == 'pause' else VersionMode.FollowLoop
90
159
  self.target_model = None
91
160
  # self.setup_sio_server()
92
161
 
@@ -141,9 +210,8 @@ class DetectorNode(Node):
141
210
  @self.sio.event
142
211
  async def detect(sid, data: Dict) -> Dict:
143
212
  try:
144
- np_image = np.frombuffer(data['image'], np.uint8)
145
213
  det = await self.get_detections(
146
- raw_image=np_image,
214
+ raw_image=np.frombuffer(data['image'], np.uint8),
147
215
  camera_id=data.get('camera-id', None) or data.get('mac', None),
148
216
  tags=data.get('tags', []),
149
217
  source=data.get('source', None),
@@ -160,10 +228,38 @@ class DetectorNode(Node):
160
228
  return {'error': str(e)}
161
229
 
162
230
  @self.sio.event
163
- async def info(sid) -> Union[str, Dict]:
231
+ async def info(sid) -> Dict:
164
232
  if self.detector_logic.is_initialized:
165
233
  return asdict(self.detector_logic.model_info)
166
- return 'No model loaded'
234
+ return {"status": "No model loaded"}
235
+
236
+ @self.sio.event
237
+ async def about(sid) -> Dict:
238
+ return asdict(self.get_about_response())
239
+
240
+ @self.sio.event
241
+ async def get_model_version(sid) -> Dict:
242
+ return asdict(self.get_model_version_response())
243
+
244
+ @self.sio.event
245
+ async def set_model_version_mode(sid, data: str) -> Dict:
246
+ try:
247
+ await self.set_model_version_mode(data)
248
+ return {"status": "OK"}
249
+ except Exception as e:
250
+ return {'error': str(e)}
251
+
252
+ @self.sio.event
253
+ async def get_outbox_mode(sid) -> Dict:
254
+ return {'outbox_mode': self.outbox.get_mode().value}
255
+
256
+ @self.sio.event
257
+ async def set_outbox_mode(sid, data: str) -> Dict:
258
+ try:
259
+ await self.outbox.set_mode(data)
260
+ return {"status": "OK"}
261
+ except Exception as e:
262
+ return {'error': str(e)}
167
263
 
168
264
  @self.sio.event
169
265
  async def upload(sid, data: Dict) -> Optional[Dict]:
@@ -292,7 +388,8 @@ class DetectorNode(Node):
292
388
  model_format=self.detector_logic.model_format,
293
389
  )
294
390
 
295
- self.log.debug('sending status %s', status)
391
+ self.log_status_on_change(status.state or 'None', status)
392
+
296
393
  response = await self.sio_client.call('update_detector', (self.organization, self.project, jsonable_encoder(asdict(status))))
297
394
  if not response:
298
395
  self.socket_connection_broken = True
@@ -313,7 +410,7 @@ class DetectorNode(Node):
313
410
  id=deployment_target_model_id,
314
411
  version=deployment_target_model_version)
315
412
 
316
- if (self.version_control == rest_version_control.VersionMode.FollowLoop and
413
+ if (self.version_control == VersionMode.FollowLoop and
317
414
  self.target_model != self.loop_deployment_target):
318
415
  old_target_model_version = self.target_model.version if self.target_model else None
319
416
  self.target_model = self.loop_deployment_target
@@ -7,7 +7,6 @@ import shutil
7
7
  from asyncio import Task
8
8
  from dataclasses import asdict
9
9
  from datetime import datetime
10
- from enum import Enum
11
10
  from glob import glob
12
11
  from io import BufferedReader, TextIOWrapper
13
12
  from multiprocessing import Event
@@ -20,15 +19,11 @@ import PIL.Image # type: ignore
20
19
  from fastapi.encoders import jsonable_encoder
21
20
 
22
21
  from ..data_classes import ImageMetadata
22
+ from ..enums import OutboxMode
23
23
  from ..globals import GLOBALS
24
24
  from ..helpers import environment_reader
25
25
 
26
26
 
27
- class OutboxMode(Enum):
28
- CONTINUOUS_UPLOAD = 'continuous_upload'
29
- STOPPED = 'stopped'
30
-
31
-
32
27
  class Outbox():
33
28
  def __init__(self) -> None:
34
29
  self.log = logging.getLogger()
@@ -0,0 +1,26 @@
1
+
2
+ import sys
3
+ from typing import TYPE_CHECKING
4
+
5
+ from fastapi import APIRouter, Request
6
+
7
+ from ...data_classes import AboutResponse
8
+
9
+ if TYPE_CHECKING:
10
+ from ..detector_node import DetectorNode
11
+ KWONLY_SLOTS = {'kw_only': True, 'slots': True} if sys.version_info >= (3, 10) else {}
12
+
13
+ router = APIRouter()
14
+
15
+
16
+ @router.get("/about", response_model=AboutResponse)
17
+ async def get_about(request: Request):
18
+ '''
19
+ Get information about the detector node.
20
+
21
+ Example Usage
22
+
23
+ curl http://hosturl/about
24
+ '''
25
+ app: 'DetectorNode' = request.app
26
+ return app.get_about_response()
@@ -0,0 +1,46 @@
1
+
2
+ import sys
3
+ from typing import TYPE_CHECKING
4
+
5
+ from fastapi import APIRouter, HTTPException, Request
6
+
7
+ from ...data_classes import ModelVersionResponse
8
+
9
+ if TYPE_CHECKING:
10
+ from ..detector_node import DetectorNode
11
+ KWONLY_SLOTS = {'kw_only': True, 'slots': True} if sys.version_info >= (3, 10) else {}
12
+
13
+ router = APIRouter()
14
+
15
+
16
+ @router.get("/model_version", name='Get model version information', response_model=ModelVersionResponse)
17
+ async def get_version(request: Request):
18
+ '''
19
+ Get information about the model version control and the current model version.
20
+
21
+ Example Usage
22
+ curl http://localhost/model_version
23
+ '''
24
+ # pylint: disable=protected-access
25
+ app: 'DetectorNode' = request.app
26
+ return app.get_model_version_response()
27
+
28
+
29
+ @router.put("/model_version", name='Set model version control mode')
30
+ async def put_version(request: Request):
31
+ '''
32
+ Set the model version control mode.
33
+
34
+ Example Usage
35
+ curl -X PUT -d "follow_loop" http://hosturl/model_version
36
+ curl -X PUT -d "pause" http://hosturl/model_version
37
+ curl -X PUT -d "13.6" http://hosturl/model_version
38
+ '''
39
+ app: 'DetectorNode' = request.app
40
+ content = str(await request.body(), 'utf-8')
41
+ try:
42
+ await app.set_model_version_mode(content)
43
+ except Exception as exc:
44
+ raise HTTPException(400, str(exc)) from exc
45
+
46
+ return "OK"
@@ -1,24 +1,17 @@
1
1
  import logging
2
- from enum import Enum
3
2
  from typing import TYPE_CHECKING
4
3
 
5
4
  from fastapi import APIRouter, HTTPException, Request
6
5
  from fastapi.responses import PlainTextResponse
7
6
 
7
+ from ...enums import OperationMode
8
+
8
9
  if TYPE_CHECKING:
9
10
  from learning_loop_node.detector.detector_node import DetectorNode
10
11
 
11
12
  router = APIRouter()
12
13
 
13
14
 
14
- class OperationMode(str, Enum):
15
- Startup = 'startup' # used until model is loaded
16
- Idle = 'idle' # will check and perform updates
17
- Detecting = 'detecting' # Blocks updates
18
-
19
- # NOTE: This is only ment to be used by a detector node
20
-
21
-
22
15
  @router.put("/operation_mode")
23
16
  async def put_operation_mode(request: Request):
24
17
  '''
@@ -0,0 +1,6 @@
1
+ from .annotator import AnnotationEventType
2
+ from .detector import OperationMode, OutboxMode, VersionMode
3
+ from .general import CategoryType
4
+ from .trainer import TrainerState
5
+
6
+ __all__ = ['VersionMode', 'OperationMode', 'OutboxMode', 'AnnotationEventType', 'CategoryType', 'TrainerState']
@@ -0,0 +1,11 @@
1
+ from enum import Enum
2
+
3
+
4
+ class AnnotationEventType(str, Enum):
5
+ LeftMouseDown = 'left_mouse_down'
6
+ RightMouseDown = 'right_mouse_down'
7
+ MouseMove = 'mouse_move'
8
+ LeftMouseUp = 'left_mouse_up'
9
+ RightMouseUp = 'right_mouse_up'
10
+ KeyUp = 'key_up'
11
+ KeyDown = 'key_down'
@@ -0,0 +1,18 @@
1
+ from enum import Enum
2
+
3
+
4
+ class VersionMode(str, Enum):
5
+ FollowLoop = 'follow_loop' # will follow the loop
6
+ SpecificVersion = 'specific_version' # will follow the specific version
7
+ Pause = 'pause' # will pause the updates
8
+
9
+
10
+ class OperationMode(str, Enum):
11
+ Startup = 'startup' # used until model is loaded
12
+ Idle = 'idle' # will check and perform updates
13
+ Detecting = 'detecting' # Blocks updates
14
+
15
+
16
+ class OutboxMode(Enum):
17
+ CONTINUOUS_UPLOAD = 'continuous_upload'
18
+ STOPPED = 'stopped'
@@ -0,0 +1,9 @@
1
+
2
+ from enum import Enum
3
+
4
+
5
+ class CategoryType(str, Enum):
6
+ Box = 'box'
7
+ Point = 'point'
8
+ Segmentation = 'segmentation'
9
+ Classification = 'classification'
@@ -0,0 +1,22 @@
1
+
2
+ from enum import Enum
3
+
4
+
5
+ class TrainerState(str, Enum):
6
+ Idle = 'idle'
7
+ Initialized = 'initialized'
8
+ Preparing = 'preparing'
9
+ DataDownloading = 'data_downloading'
10
+ DataDownloaded = 'data_downloaded'
11
+ TrainModelDownloading = 'train_model_downloading'
12
+ TrainModelDownloaded = 'train_model_downloaded'
13
+ TrainingRunning = 'running'
14
+ TrainingFinished = 'training_finished'
15
+ ConfusionMatrixSyncing = 'confusion_matrix_syncing'
16
+ ConfusionMatrixSynced = 'confusion_matrix_synced'
17
+ TrainModelUploading = 'train_model_uploading'
18
+ TrainModelUploaded = 'train_model_uploaded'
19
+ Detecting = 'detecting'
20
+ Detected = 'detected'
21
+ DetectionUploading = 'detection_uploading'
22
+ ReadyForCleanup = 'ready_for_cleanup'