learning-loop-node 0.18.2__tar.gz → 0.18.3__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.
Files changed (113) hide show
  1. {learning_loop_node-0.18.2 → learning_loop_node-0.18.3}/PKG-INFO +33 -36
  2. learning_loop_node-0.18.3/learning_loop_node.egg-info/PKG-INFO +280 -0
  3. learning_loop_node-0.18.3/learning_loop_node.egg-info/SOURCES.txt +15 -0
  4. learning_loop_node-0.18.3/learning_loop_node.egg-info/dependency_links.txt +1 -0
  5. learning_loop_node-0.18.3/learning_loop_node.egg-info/requires.txt +27 -0
  6. learning_loop_node-0.18.3/learning_loop_node.egg-info/top_level.txt +1 -0
  7. learning_loop_node-0.18.3/pyproject.toml +49 -0
  8. learning_loop_node-0.18.3/setup.cfg +4 -0
  9. learning_loop_node-0.18.3/setup.py +10 -0
  10. learning_loop_node-0.18.2/learning_loop_node/annotation/__init__.py +0 -0
  11. learning_loop_node-0.18.2/learning_loop_node/annotation/annotator_logic.py +0 -29
  12. learning_loop_node-0.18.2/learning_loop_node/annotation/annotator_node.py +0 -116
  13. learning_loop_node-0.18.2/learning_loop_node/data_classes/__init__.py +0 -50
  14. learning_loop_node-0.18.2/learning_loop_node/data_classes/annotation_data.py +0 -43
  15. learning_loop_node-0.18.2/learning_loop_node/data_classes/annotations.py +0 -44
  16. learning_loop_node-0.18.2/learning_loop_node/data_classes/detections.py +0 -136
  17. learning_loop_node-0.18.2/learning_loop_node/data_classes/general.py +0 -187
  18. learning_loop_node-0.18.2/learning_loop_node/data_classes/image_metadata.py +0 -56
  19. learning_loop_node-0.18.2/learning_loop_node/data_classes/socket_response.py +0 -24
  20. learning_loop_node-0.18.2/learning_loop_node/data_classes/training.py +0 -168
  21. learning_loop_node-0.18.2/learning_loop_node/detector/__init__.py +0 -0
  22. learning_loop_node-0.18.2/learning_loop_node/detector/detector_logic.py +0 -79
  23. learning_loop_node-0.18.2/learning_loop_node/detector/detector_node.py +0 -704
  24. learning_loop_node-0.18.2/learning_loop_node/detector/exceptions.py +0 -7
  25. learning_loop_node-0.18.2/learning_loop_node/detector/inbox_filter/__init__.py +0 -0
  26. learning_loop_node-0.18.2/learning_loop_node/detector/inbox_filter/cam_observation_history.py +0 -82
  27. learning_loop_node-0.18.2/learning_loop_node/detector/inbox_filter/relevance_filter.py +0 -40
  28. learning_loop_node-0.18.2/learning_loop_node/detector/outbox.py +0 -323
  29. learning_loop_node-0.18.2/learning_loop_node/detector/rest/__init__.py +0 -0
  30. learning_loop_node-0.18.2/learning_loop_node/detector/rest/about.py +0 -26
  31. learning_loop_node-0.18.2/learning_loop_node/detector/rest/backdoor_controls.py +0 -37
  32. learning_loop_node-0.18.2/learning_loop_node/detector/rest/detect.py +0 -59
  33. learning_loop_node-0.18.2/learning_loop_node/detector/rest/model_version_control.py +0 -46
  34. learning_loop_node-0.18.2/learning_loop_node/detector/rest/operation_mode.py +0 -54
  35. learning_loop_node-0.18.2/learning_loop_node/detector/rest/outbox_mode.py +0 -41
  36. learning_loop_node-0.18.2/learning_loop_node/detector/rest/upload.py +0 -44
  37. learning_loop_node-0.18.2/learning_loop_node/enums/__init__.py +0 -6
  38. learning_loop_node-0.18.2/learning_loop_node/enums/annotator.py +0 -11
  39. learning_loop_node-0.18.2/learning_loop_node/enums/detector.py +0 -18
  40. learning_loop_node-0.18.2/learning_loop_node/enums/general.py +0 -9
  41. learning_loop_node-0.18.2/learning_loop_node/enums/trainer.py +0 -22
  42. learning_loop_node-0.18.2/learning_loop_node/examples/novelty_score_updater.py +0 -70
  43. learning_loop_node-0.18.2/learning_loop_node/helpers/__init__.py +0 -0
  44. learning_loop_node-0.18.2/learning_loop_node/helpers/background_tasks.py +0 -77
  45. learning_loop_node-0.18.2/learning_loop_node/helpers/environment_reader.py +0 -49
  46. learning_loop_node-0.18.2/learning_loop_node/helpers/gdrive_downloader.py +0 -43
  47. learning_loop_node-0.18.2/learning_loop_node/helpers/log_conf.py +0 -39
  48. learning_loop_node-0.18.2/learning_loop_node/helpers/misc.py +0 -239
  49. learning_loop_node-0.18.2/learning_loop_node/helpers/run.py +0 -21
  50. learning_loop_node-0.18.2/learning_loop_node/tests/__init__.py +0 -0
  51. learning_loop_node-0.18.2/learning_loop_node/tests/annotator/__init__.py +0 -0
  52. learning_loop_node-0.18.2/learning_loop_node/tests/annotator/conftest.py +0 -55
  53. learning_loop_node-0.18.2/learning_loop_node/tests/annotator/pytest.ini +0 -10
  54. learning_loop_node-0.18.2/learning_loop_node/tests/annotator/test_annotator_node.py +0 -60
  55. learning_loop_node-0.18.2/learning_loop_node/tests/detector/__init__.py +0 -0
  56. learning_loop_node-0.18.2/learning_loop_node/tests/detector/conftest.py +0 -174
  57. learning_loop_node-0.18.2/learning_loop_node/tests/detector/inbox_filter/__init__.py +0 -0
  58. learning_loop_node-0.18.2/learning_loop_node/tests/detector/inbox_filter/test_observation.py +0 -31
  59. learning_loop_node-0.18.2/learning_loop_node/tests/detector/inbox_filter/test_relevance_group.py +0 -162
  60. learning_loop_node-0.18.2/learning_loop_node/tests/detector/inbox_filter/test_unexpected_observations_count.py +0 -35
  61. learning_loop_node-0.18.2/learning_loop_node/tests/detector/pytest.ini +0 -10
  62. learning_loop_node-0.18.2/learning_loop_node/tests/detector/test.jpg +0 -0
  63. learning_loop_node-0.18.2/learning_loop_node/tests/detector/test_client_communication.py +0 -177
  64. learning_loop_node-0.18.2/learning_loop_node/tests/detector/test_detector_node.py +0 -98
  65. learning_loop_node-0.18.2/learning_loop_node/tests/detector/test_outbox.py +0 -77
  66. learning_loop_node-0.18.2/learning_loop_node/tests/detector/test_relevance_filter.py +0 -43
  67. learning_loop_node-0.18.2/learning_loop_node/tests/detector/testing_detector.py +0 -28
  68. learning_loop_node-0.18.2/learning_loop_node/tests/general/__init__.py +0 -0
  69. learning_loop_node-0.18.2/learning_loop_node/tests/general/conftest.py +0 -68
  70. learning_loop_node-0.18.2/learning_loop_node/tests/general/pytest.ini +0 -10
  71. learning_loop_node-0.18.2/learning_loop_node/tests/general/test_data/file_1.txt +0 -1
  72. learning_loop_node-0.18.2/learning_loop_node/tests/general/test_data/file_2.txt +0 -1
  73. learning_loop_node-0.18.2/learning_loop_node/tests/general/test_data/model.json +0 -6
  74. learning_loop_node-0.18.2/learning_loop_node/tests/general/test_data_classes.py +0 -22
  75. learning_loop_node-0.18.2/learning_loop_node/tests/general/test_downloader.py +0 -84
  76. learning_loop_node-0.18.2/learning_loop_node/tests/general/test_learning_loop_node.py +0 -20
  77. learning_loop_node-0.18.2/learning_loop_node/tests/test_helper.py +0 -96
  78. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/__init__.py +0 -0
  79. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/conftest.py +0 -101
  80. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/pytest.ini +0 -10
  81. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/state_helper.py +0 -22
  82. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/states/__init__.py +0 -0
  83. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/states/test_state_cleanup.py +0 -27
  84. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/states/test_state_detecting.py +0 -83
  85. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/states/test_state_download_train_model.py +0 -67
  86. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/states/test_state_prepare.py +0 -55
  87. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/states/test_state_sync_confusion_matrix.py +0 -117
  88. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/states/test_state_train.py +0 -65
  89. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/states/test_state_upload_detections.py +0 -164
  90. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/states/test_state_upload_model.py +0 -88
  91. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/test_errors.py +0 -45
  92. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/test_trainer_states.py +0 -39
  93. learning_loop_node-0.18.2/learning_loop_node/tests/trainer/testing_trainer_logic.py +0 -94
  94. learning_loop_node-0.18.2/learning_loop_node/trainer/__init__.py +0 -0
  95. learning_loop_node-0.18.2/learning_loop_node/trainer/downloader.py +0 -31
  96. learning_loop_node-0.18.2/learning_loop_node/trainer/exceptions.py +0 -12
  97. learning_loop_node-0.18.2/learning_loop_node/trainer/executor.py +0 -109
  98. learning_loop_node-0.18.2/learning_loop_node/trainer/io_helpers.py +0 -181
  99. learning_loop_node-0.18.2/learning_loop_node/trainer/rest/__init__.py +0 -0
  100. learning_loop_node-0.18.2/learning_loop_node/trainer/rest/backdoor_controls.py +0 -120
  101. learning_loop_node-0.18.2/learning_loop_node/trainer/test_executor.py +0 -66
  102. learning_loop_node-0.18.2/learning_loop_node/trainer/trainer_logic.py +0 -192
  103. learning_loop_node-0.18.2/learning_loop_node/trainer/trainer_logic_generic.py +0 -560
  104. learning_loop_node-0.18.2/learning_loop_node/trainer/trainer_node.py +0 -106
  105. learning_loop_node-0.18.2/pyproject.toml +0 -47
  106. {learning_loop_node-0.18.2 → learning_loop_node-0.18.3}/README.md +0 -0
  107. {learning_loop_node-0.18.2 → learning_loop_node-0.18.3}/learning_loop_node/__init__.py +0 -0
  108. {learning_loop_node-0.18.2 → learning_loop_node-0.18.3}/learning_loop_node/data_exchanger.py +0 -0
  109. {learning_loop_node-0.18.2 → learning_loop_node-0.18.3}/learning_loop_node/globals.py +0 -0
  110. {learning_loop_node-0.18.2 → learning_loop_node-0.18.3}/learning_loop_node/loop_communication.py +0 -0
  111. {learning_loop_node-0.18.2 → learning_loop_node-0.18.3}/learning_loop_node/node.py +0 -0
  112. {learning_loop_node-0.18.2 → learning_loop_node-0.18.3}/learning_loop_node/py.typed +0 -0
  113. {learning_loop_node-0.18.2 → learning_loop_node-0.18.3}/learning_loop_node/rest.py +0 -0
@@ -1,42 +1,40 @@
1
- Metadata-Version: 2.1
2
- Name: learning-loop-node
3
- Version: 0.18.2
1
+ Metadata-Version: 2.4
2
+ Name: learning_loop_node
3
+ Version: 0.18.3
4
4
  Summary: Python Library for Nodes which connect to the Zauberzeug Learning Loop
5
- Home-page: https://github.com/zauberzeug/learning_loop_node
5
+ Author: Zauberzeug
6
+ Author-email: Zauberzeug GmbH <info@zauberzeug.com>
6
7
  License: MIT
7
- Author: Zauberzeug GmbH
8
- Author-email: info@zauberzeug.com
9
- Requires-Python: >=3.8,<4.0
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.8
13
- Classifier: Programming Language :: Python :: 3.9
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: Programming Language :: Python :: 3.11
16
- Requires-Dist: Pillow (>=10.0.0,<11.0.0)
17
- Requires-Dist: aiofiles (>=0.7.0,<0.8.0)
18
- Requires-Dist: aiohttp (>=3.8.4,<4.0.0)
19
- Requires-Dist: async_generator (>=1.10,<2.0)
20
- Requires-Dist: dacite (>=1.8.1,<2.0.0)
21
- Requires-Dist: fastapi (>=0.93,<0.109)
22
- Requires-Dist: fastapi-socketio (>=0.0.10,<0.0.11)
23
- Requires-Dist: fastapi-utils (>=0.2.1,<0.3.0)
24
- Requires-Dist: httpx (>=0.28.1,<0.29.0)
25
- Requires-Dist: icecream (>=2.1.0,<3.0.0)
26
- Requires-Dist: numpy (>=1.13.3,<2.0.0)
27
- Requires-Dist: psutil (>=5.8.0,<6.0.0)
28
- Requires-Dist: pynvml (>=11.4.1,<12.0.0)
29
- Requires-Dist: pytest-mock (==3.6.1)
30
- Requires-Dist: pytest-watch (>=4.2.0,<5.0.0)
31
- Requires-Dist: python-multipart (>=0.0.5,<0.0.6)
32
- Requires-Dist: python-socketio (>=5.7.2,<6.0.0)
33
- Requires-Dist: requests (>=2.25.1,<3.0.0)
34
- Requires-Dist: simplejson (>=3.17.2,<4.0.0)
35
- Requires-Dist: tqdm (>=4.63.0,<5.0.0)
36
- Requires-Dist: uvicorn[standard] (>=0.22.0,<0.23.0)
37
- Requires-Dist: werkzeug (>=2.0.1,<3.0.0)
38
8
  Project-URL: Repository, https://github.com/zauberzeug/learning_loop_node
9
+ Requires-Python: >=3.9
39
10
  Description-Content-Type: text/markdown
11
+ Requires-Dist: fastapi<1.0,>=0.128
12
+ Requires-Dist: uvicorn[standard]<0.23.0,>=0.22.0
13
+ Requires-Dist: fastapi-utils<0.9.0,>=0.8.0
14
+ Requires-Dist: requests<3.0.0,>=2.25.1
15
+ Requires-Dist: python-socketio<6.0.0,>=5.7.2
16
+ Requires-Dist: simplejson<4.0.0,>=3.17.2
17
+ Requires-Dist: icecream<3.0.0,>=2.1.0
18
+ Requires-Dist: aiofiles<0.8.0,>=0.7.0
19
+ Requires-Dist: async_generator<2.0.0,>=1.10
20
+ Requires-Dist: pytest-watch<5.0.0,>=4.2.0
21
+ Requires-Dist: python-multipart<0.0.19,>=0.0.18
22
+ Requires-Dist: psutil<6.0.0,>=5.8.0
23
+ Requires-Dist: numpy<3.0,>=2.0
24
+ Requires-Dist: Pillow<12.0.0,>=11.0.0
25
+ Requires-Dist: tqdm<5.0.0,>=4.66.3
26
+ Requires-Dist: pytest-mock<4.0.0,>=3.6.1
27
+ Requires-Dist: pynvml<12.0.0,>=11.4.1
28
+ Requires-Dist: aiohttp<4.0.0,>=3.13.3
29
+ Requires-Dist: httpx<0.29.0,>=0.28.1
30
+ Requires-Dist: dacite<2.0.0,>=1.8.1
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest-flakefinder<2.0.0,>=1.1.0; extra == "dev"
33
+ Requires-Dist: retry<0.10.0,>=0.9.2; extra == "dev"
34
+ Requires-Dist: debugpy<2.0.0,>=1.6.7.post1; extra == "dev"
35
+ Requires-Dist: pytest-asyncio<0.22.0,>=0.21.1; extra == "dev"
36
+ Requires-Dist: autopep8<3.0.0,>=2.0.2; extra == "dev"
37
+ Dynamic: author
40
38
 
41
39
  # Learning Loop Node
42
40
 
@@ -280,4 +278,3 @@ After a short time the converted model should be available as well.
280
278
  - Nodes add properties to `model.json`, which contains all the information which are needed by subsequent nodes. These are typically the properties:
281
279
  - `resolution`: resolution in which the model expects images (as `int`, since the resolution is mostly square - later, ` resolution_x`` resolution_y ` would also be conceivable or `resolutions` to give a list of possible resolutions)
282
280
  - `categories`: list of categories with name, id, (later also type), in the order in which they are used by the model -- this is neccessary to be robust about renamings
283
-
@@ -0,0 +1,280 @@
1
+ Metadata-Version: 2.4
2
+ Name: learning_loop_node
3
+ Version: 0.18.3
4
+ Summary: Python Library for Nodes which connect to the Zauberzeug Learning Loop
5
+ Author: Zauberzeug
6
+ Author-email: Zauberzeug GmbH <info@zauberzeug.com>
7
+ License: MIT
8
+ Project-URL: Repository, https://github.com/zauberzeug/learning_loop_node
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: fastapi<1.0,>=0.128
12
+ Requires-Dist: uvicorn[standard]<0.23.0,>=0.22.0
13
+ Requires-Dist: fastapi-utils<0.9.0,>=0.8.0
14
+ Requires-Dist: requests<3.0.0,>=2.25.1
15
+ Requires-Dist: python-socketio<6.0.0,>=5.7.2
16
+ Requires-Dist: simplejson<4.0.0,>=3.17.2
17
+ Requires-Dist: icecream<3.0.0,>=2.1.0
18
+ Requires-Dist: aiofiles<0.8.0,>=0.7.0
19
+ Requires-Dist: async_generator<2.0.0,>=1.10
20
+ Requires-Dist: pytest-watch<5.0.0,>=4.2.0
21
+ Requires-Dist: python-multipart<0.0.19,>=0.0.18
22
+ Requires-Dist: psutil<6.0.0,>=5.8.0
23
+ Requires-Dist: numpy<3.0,>=2.0
24
+ Requires-Dist: Pillow<12.0.0,>=11.0.0
25
+ Requires-Dist: tqdm<5.0.0,>=4.66.3
26
+ Requires-Dist: pytest-mock<4.0.0,>=3.6.1
27
+ Requires-Dist: pynvml<12.0.0,>=11.4.1
28
+ Requires-Dist: aiohttp<4.0.0,>=3.13.3
29
+ Requires-Dist: httpx<0.29.0,>=0.28.1
30
+ Requires-Dist: dacite<2.0.0,>=1.8.1
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest-flakefinder<2.0.0,>=1.1.0; extra == "dev"
33
+ Requires-Dist: retry<0.10.0,>=0.9.2; extra == "dev"
34
+ Requires-Dist: debugpy<2.0.0,>=1.6.7.post1; extra == "dev"
35
+ Requires-Dist: pytest-asyncio<0.22.0,>=0.21.1; extra == "dev"
36
+ Requires-Dist: autopep8<3.0.0,>=2.0.2; extra == "dev"
37
+ Dynamic: author
38
+
39
+ # Learning Loop Node
40
+
41
+ This Python library helps to write Nodes that interact with the Zauberzeug Learning Loop. There are 4 types of Nodes:
42
+
43
+ | Type | Purpose |
44
+ | --------- | ---------------------------------------------------- |
45
+ | Trainer | Runs training using the latest training data |
46
+ | Detector | Loads latest models from Loop and performs inference |
47
+ | Annotator | Used for custom annotation inside the Loop |
48
+ | Converter | Converts between different model formats |
49
+
50
+ ## General Usage
51
+
52
+ To start a node you have to implement the logic by inheriting from the corresponding base logic class. We provide samples in the 'mock' folders and recommend to follow that scheme. A complete trainer and detector example can be found [here](https://github.com/zauberzeug/yolov5_node).
53
+
54
+ #### Environment variables
55
+
56
+ You can configure connection to our Learning Loop by specifying the following environment variables before starting:
57
+
58
+ | Name | Alias | Purpose | Required by |
59
+ | ------------------------ | ------------ | ------------------------------------------------------------ | ------------------------- |
60
+ | LOOP_HOST | HOST | Learning Loop address (e.g. learning-loop.ai) | all |
61
+ | LOOP_USERNAME | USERNAME | Learning Loop user name | all besides Detector |
62
+ | LOOP_PASSWORD | PASSWORD | Learning Loop password | all besides Detector |
63
+ | LOOP_SSL_CERT_PATH | - | Path to the SSL certificate | all (opt.) |
64
+ | LOOP_ORGANIZATION | ORGANIZATION | Organization ID | Detector |
65
+ | LOOP_PROJECT | PROJECT | Project ID | Detector (opt.) |
66
+ | MIN_UNCERTAIN_THRESHOLD | - | smallest confidence (float) at which auto-upload will happen | Detector (opt.) |
67
+ | MAX_UNCERTAIN_THRESHOLD | - | largest confidence (float) at which auto-upload will happen | Detector (opt.) |
68
+ | INFERENCE_BATCH_SIZE | - | Batch size of trainer when calculating detections | Trainer (opt.) |
69
+ | RESTART_AFTER_TRAINING | - | Restart the trainer after training (set to 1) | Trainer (opt.) |
70
+ | KEEP_OLD_TRAININGS | - | Do not delete old trainings (set to 1) | Trainer (opt.) |
71
+ | TRAINER_IDLE_TIMEOUT_SEC | - | Automatically shutdown trainer after timeout (in seconds) | Trainer (opt.) |
72
+ | USE_BACKDOOR_CONTROLS | - | Always enable backdoor controls (set to 1) | Trainer / Detector (opt.) |
73
+
74
+ Note that organization and project IDs are always lower case and may differ from the names in the Learning Loop which can have uppercase letters.
75
+
76
+ #### Testing
77
+
78
+ We use github actions for CI. Tests can also be executed locally by running
79
+ `LOOP_HOST=XXXXXXXX LOOP_USERNAME=XXXXXXXX LOOP_PASSWORD=XXXXXXXX python -m pytest -v`
80
+ from learning_loop_node/learning_loop_node
81
+
82
+ ## Detector Node
83
+
84
+ Detector Nodes are normally deployed on edge devices like robots or machinery but can also run in the cloud to provide backend services for an app or similar. These nodes register themself at the Learning Loop. They provide REST and Socket.io APIs to run inference on images. The processed images can automatically be used for active learning: e.g. uncertain predictions will be send to the Learning Loop.
85
+
86
+ ### Inference API
87
+
88
+ Images can be send to the detector node via socketio or rest.
89
+ Via **REST** you may provide the following parameters:
90
+
91
+ - `camera_id`: a camera identifier (string) used to improve the autoupload filtering
92
+ - `tags`: comma separated list of tags to add to the image in the learning loop to add to the image in the learning loop
93
+ - `source`: optional source identifier (str) for the image (e.g. a robot id)
94
+ - `autoupload`: configures auto-submission to the learning loop; `filtered` (default), `all`, `disabled`
95
+ - `creation_date`: optional creation date (str) for the image in isoformat (e.g. `2023-01-30T12:34:56`)
96
+
97
+ Example usage:
98
+
99
+ `curl --request POST -F 'file=@test.jpg' -H 'autoupload: all' -H 'camera_id: front_cam' localhost:8004/detect`
100
+
101
+ To use the **SocketIO** inference EPs, the caller needs to connect to the detector node's SocketIO server and emit the `detect` or `batch_detect` event with the image data and image metadata. The `detect` endpoint receives a dictionary, with the following entries:
102
+
103
+ - `image`: The image data as dictionary with the following keys:
104
+ - `bytes`: bytes of the ndarray (retrieved via `ndarray.tobytes(order='C')`)
105
+ - `dtype`: data type of the ndarray as string (e.g. `uint8`, `float32`, etc.)
106
+ - `shape`: shape of the ndarray as tuple of ints (e.g. `(480, 640, 3)`)
107
+ - `camera_id`: optional camera identifier (string) used to improve the autoupload filtering
108
+ - `tags`: optional list of tags to add to the image in the learning loop
109
+ - `source`: optional source string
110
+ - `autoupload`: configures auto-submission to the learning loop; `filtered` (default), `all`, `disabled`
111
+ - `creation_date`: optional creation date (str) for the image in isoformat (e.g. `2023-01-30T12:34:56`)
112
+
113
+ The `batch_detect` endpoint receives a dictionary, with the same entries as the `detect` endpoint, except that the `image` entry is replaced by:
114
+
115
+ - `images`: List of image data dictionaries, each with the same structure as the `image` entry in the `detect` endpoint
116
+
117
+ Example code can be found [in the rosys implementation](https://github.com/zauberzeug/rosys/blob/main/rosys/vision/detector_hardware.py).
118
+
119
+ ### Upload API
120
+
121
+ The detector has a **REST** endpoint to upload images (and detections) to the Learning Loop. The endpoint takes a POST request with one or multiple images. The images are expected to be in jpg format. The following optional parameters may be set via headers:
122
+
123
+ - `source`: optional source identifier (str) for the image (e.g. a robot id)
124
+ - `creation_date`: optional creation date (str) for the image in isoformat (e.g. `2023-01-30T12:34:56`)
125
+ - `upload_priority`: A boolean flag to prioritize the upload (defaults to False)
126
+
127
+ Example:
128
+
129
+ `curl -X POST -F 'files=@test.jpg' "http://localhost:/upload"`
130
+
131
+ The detector also has a **SocketIO** upload endpoint that can be used to upload images and detections to the learning loop. The function receives a dictionary, with the following entries:
132
+
133
+ - `image`: the image data as dictionary with the following keys:
134
+ - `bytes`: bytes of the ndarray (retrieved via `ndarray.tobytes(order='C')`)
135
+ - `dtype`: data type of the ndarray as string (e.g. `uint8`, `float32`, etc.)
136
+ - `shape`: shape of the ndarray as tuple of ints (e.g. `(480, 640, 3)`)
137
+ - `metadata`: a dictionary representing the image metadata. If metadata contains detections and/or annotations, UUIDs for the classes are automatically determined based on the category names. Metadata should follow the schema of the `ImageMetadata` data class.
138
+ - `upload_priority`: Optional boolean flag to prioritize the upload (defaults to False)
139
+
140
+ The endpoint returns None if the upload was successful and an error message otherwise.
141
+
142
+ For both ways to upload an image, the tag `picked_by_system` is automatically added to the image metadata.
143
+
144
+ ### Changing the model versioning mode
145
+
146
+ The detector can be configured to one of the following behaviors:
147
+
148
+ - use a specific model version
149
+ - automatically update the model version according to the learning loop deployment target
150
+ - pause the model updates and use the version that was last loaded
151
+
152
+ The model versioning configuration can be accessed/changed via a REST endpoint. Example Usage:
153
+
154
+ - Fetch the current model versioning configuration: `curl http://localhost/model_version`
155
+ - Configure the detector to use a specific model version: `curl -X PUT -d "1.0" http://localhost/model_version`
156
+ - Configure the detector to automatically update the model version: `curl -X PUT -d "follow_loop" http://localhost/model_version`
157
+ - Pause the model updates: `curl -X PUT -d "pause" http://localhost/model_version`
158
+
159
+ Note that the configuration is not persistent, however, the default behavior on startup can be configured via the environment variable `VERSION_CONTROL_DEFAULT`.
160
+ 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.
161
+
162
+ The model versioning configuration can also be changed via a socketio event:
163
+
164
+ - Configure the detector to use a specific model version: `sio.emit('set_model_version_mode', '1.0')`
165
+ - Configure the detector to automatically update the model version: `sio.emit('set_model_version_mode', 'follow_loop')`
166
+ - Pause the model updates: `sio.emit('set_model_version_mode', 'pause')`
167
+
168
+ There is also a GET endpoint to fetch the current model versioning configuration:
169
+ `sio.emit('get_model_version')` or `curl http://localhost/model_version`
170
+
171
+ ### Changing the outbox mode
172
+
173
+ 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.
174
+
175
+ The continuous upload can be stopped/started via a REST enpoint:
176
+
177
+ Example Usage:
178
+
179
+ - Enable upload: `curl -X PUT -d "continuous_upload" http://localhost/outbox_mode`
180
+ - Disable upload: `curl -X PUT -d "stopped" http://localhost/outbox_mode`
181
+
182
+ The current state can be queried via a GET request:
183
+ `curl http://localhost/outbox_mode`
184
+
185
+ Alternatively, the outbox mode can be changed via a socketio event:
186
+
187
+ - Enable upload: `sio.emit('set_outbox_mode', 'continuous_upload')`
188
+ - Disable upload: `sio.emit('set_outbox_mode', 'stopped')`
189
+
190
+ The outbox mode can also be queried via:
191
+
192
+ - HTTP: `curl http://localhost/outbox_mode`
193
+ - SocketIO: `sio.emit('get_outbox_mode')`
194
+
195
+ ## Trainer Node
196
+
197
+ Trainers fetch the images and anntoations from the Learning Loop to train new models.
198
+
199
+ - if the command line tool "jpeginfo" is installed, the downloader will drop corrupted images automatically
200
+
201
+ ## Converter Node
202
+
203
+ A Conveter Node converts models from one format into another.
204
+
205
+ ## Annotator Node
206
+
207
+ ...
208
+
209
+ ### Test operability
210
+
211
+ Assumend there is a Converter Node which converts models of format 'format_a' into 'format_b'.
212
+ Upload a model with
213
+ `curl --request POST -F 'files=@my_model.zip' https://learning-loop.ai/api/zauberzeug/projects/demo/format_a`
214
+ The model should now be available for the format 'format_a'
215
+ `curl "https://learning-loop.ai/api/zauberzeug/projects/demo/models?format=format_a"`
216
+
217
+ ```json
218
+ {
219
+ "models": [
220
+ {
221
+ "id": "3c20d807-f71c-40dc-a996-8a8968aa5431",
222
+ "version": "4.0",
223
+ "formats": [
224
+ "format_a"
225
+ ],
226
+ "created": "2021-06-01T06:28:21.289092",
227
+ "comment": "uploaded at 2021-06-01 06:28:21.288442",
228
+ ...
229
+ }
230
+ ]
231
+ }
232
+ ```
233
+
234
+ but not in the format_b
235
+ `curl "https://learning-loop.ai/api/zauberzeug/projects/demo/models?format=format_b"`
236
+
237
+ ```json
238
+ {
239
+ "models": []
240
+ }
241
+ ```
242
+
243
+ Connect the Node to the Learning Loop by simply starting the container.
244
+ After a short time the converted model should be available as well.
245
+ `curl https://learning-loop.ai/api/zauberzeug/projects/demo/models?format=format_b`
246
+
247
+ ```json
248
+ {
249
+ "models": [
250
+ {
251
+ "id": "3c20d807-f71c-40dc-a996-8a8968aa5431",
252
+ "version": "4.0",
253
+ "formats": [
254
+ "format_a",
255
+ "format_b",
256
+ ],
257
+ "created": "2021-06-01T06:28:21.289092",
258
+ "comment": "uploaded at 2021-06-01 06:28:21.288442",
259
+ ...
260
+ }
261
+ ]
262
+ }
263
+ ```
264
+
265
+ ## About Models (the currency between Nodes)
266
+
267
+ - Models are packed in zips and saved on the Learning Loop (one for each format)
268
+ - Nodes and users can upload and download models with which they want to work
269
+ - In each zip there is a file called `model.json` which contains the metadata to interpret the other files in the package
270
+ - for base models (pretrained models from external sources) no `model.json` has to be sent, ie. these models should simply be zipped in such a way that the respective trainer can work with them.
271
+ - the loop adds or corrects the following properties in the `model.json` after receiving; it also creates the file if it is missing:
272
+ - `host`: uri to the loop
273
+ - `organization`: the ID of the organization
274
+ - `project`: the id of the project
275
+ - `version`: the version number that the loop assigned for this model (e.g. 1.3)
276
+ - `id`: the model UUID (currently not needed by anyone, since host, org, project, version clearly identify the model)
277
+ - `format`: the format e.g. yolo, tkdnn, yolor etc.
278
+ - Nodes add properties to `model.json`, which contains all the information which are needed by subsequent nodes. These are typically the properties:
279
+ - `resolution`: resolution in which the model expects images (as `int`, since the resolution is mostly square - later, ` resolution_x`` resolution_y ` would also be conceivable or `resolutions` to give a list of possible resolutions)
280
+ - `categories`: list of categories with name, id, (later also type), in the order in which they are used by the model -- this is neccessary to be robust about renamings
@@ -0,0 +1,15 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ learning_loop_node/__init__.py
5
+ learning_loop_node/data_exchanger.py
6
+ learning_loop_node/globals.py
7
+ learning_loop_node/loop_communication.py
8
+ learning_loop_node/node.py
9
+ learning_loop_node/py.typed
10
+ learning_loop_node/rest.py
11
+ learning_loop_node.egg-info/PKG-INFO
12
+ learning_loop_node.egg-info/SOURCES.txt
13
+ learning_loop_node.egg-info/dependency_links.txt
14
+ learning_loop_node.egg-info/requires.txt
15
+ learning_loop_node.egg-info/top_level.txt
@@ -0,0 +1,27 @@
1
+ fastapi<1.0,>=0.128
2
+ uvicorn[standard]<0.23.0,>=0.22.0
3
+ fastapi-utils<0.9.0,>=0.8.0
4
+ requests<3.0.0,>=2.25.1
5
+ python-socketio<6.0.0,>=5.7.2
6
+ simplejson<4.0.0,>=3.17.2
7
+ icecream<3.0.0,>=2.1.0
8
+ aiofiles<0.8.0,>=0.7.0
9
+ async_generator<2.0.0,>=1.10
10
+ pytest-watch<5.0.0,>=4.2.0
11
+ python-multipart<0.0.19,>=0.0.18
12
+ psutil<6.0.0,>=5.8.0
13
+ numpy<3.0,>=2.0
14
+ Pillow<12.0.0,>=11.0.0
15
+ tqdm<5.0.0,>=4.66.3
16
+ pytest-mock<4.0.0,>=3.6.1
17
+ pynvml<12.0.0,>=11.4.1
18
+ aiohttp<4.0.0,>=3.13.3
19
+ httpx<0.29.0,>=0.28.1
20
+ dacite<2.0.0,>=1.8.1
21
+
22
+ [dev]
23
+ pytest-flakefinder<2.0.0,>=1.1.0
24
+ retry<0.10.0,>=0.9.2
25
+ debugpy<2.0.0,>=1.6.7.post1
26
+ pytest-asyncio<0.22.0,>=0.21.1
27
+ autopep8<3.0.0,>=2.0.2
@@ -0,0 +1 @@
1
+ learning_loop_node
@@ -0,0 +1,49 @@
1
+ [project]
2
+ name = "learning_loop_node"
3
+ version = "0.18.3"
4
+ description = "Python Library for Nodes which connect to the Zauberzeug Learning Loop"
5
+ authors = [{ name = "Zauberzeug GmbH", email = "info@zauberzeug.com" }]
6
+ license = { text = "MIT" }
7
+ readme = "README.md"
8
+ requires-python = ">=3.9"
9
+ dependencies = [
10
+ "fastapi>=0.128,<1.0",
11
+ "uvicorn[standard]>=0.22.0,<0.23.0",
12
+ "fastapi-utils>=0.8.0,<0.9.0",
13
+ "requests>=2.25.1,<3.0.0",
14
+ "python-socketio>=5.7.2,<6.0.0",
15
+ "simplejson>=3.17.2,<4.0.0",
16
+ "icecream>=2.1.0,<3.0.0",
17
+ "aiofiles>=0.7.0,<0.8.0",
18
+ "async_generator>=1.10,<2.0.0",
19
+ "pytest-watch>=4.2.0,<5.0.0",
20
+ "python-multipart>=0.0.18,<0.0.19",
21
+ "psutil>=5.8.0,<6.0.0",
22
+ "numpy>=2.0,<3.0",
23
+ "Pillow>=11.0.0,<12.0.0",
24
+ "tqdm>=4.66.3,<5.0.0",
25
+ "pytest-mock>=3.6.1,<4.0.0",
26
+ "pynvml>=11.4.1,<12.0.0",
27
+ "aiohttp>=3.13.3,<4.0.0",
28
+ "httpx>=0.28.1,<0.29.0",
29
+ "dacite>=1.8.1,<2.0.0",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ dev = [
34
+ "pytest-flakefinder>=1.1.0,<2.0.0",
35
+ "retry>=0.9.2,<0.10.0",
36
+ "debugpy>=1.6.7.post1,<2.0.0",
37
+ "pytest-asyncio>=0.21.1,<0.22.0",
38
+ "autopep8>=2.0.2,<3.0.0",
39
+ ]
40
+
41
+ [project.urls]
42
+ Repository = "https://github.com/zauberzeug/learning_loop_node"
43
+
44
+ [build-system]
45
+ requires = ["setuptools>=61"]
46
+ build-backend = "setuptools.build_meta"
47
+
48
+ [tool.mypy]
49
+ ignore_missing_imports = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env python3
2
+ from setuptools import setup
3
+
4
+ setup(
5
+ name='Learning Loop Node',
6
+ version='0.2', # TODO wo/wie wird das genutzt?
7
+ author='Zauberzeug',
8
+ author_email='info@zauberzeug.com',
9
+ packages=['learning_loop_node'],
10
+ )
@@ -1,29 +0,0 @@
1
- from abc import abstractmethod
2
- from typing import Dict, Optional
3
-
4
- from ..data_classes import ToolOutput, UserInput
5
- from ..node import Node
6
-
7
-
8
- class AnnotatorLogic():
9
-
10
- def __init__(self) -> None:
11
- self._node: Optional[Node] = None
12
-
13
- def init(self, node: Node) -> None:
14
- self._node = node
15
-
16
- @abstractmethod
17
- async def handle_user_input(self, user_input: UserInput, history: Dict) -> ToolOutput:
18
- """ This method is called when a user input is received from the client.
19
- The function should return a ToolOutput object."""
20
-
21
- @abstractmethod
22
- def create_empty_history(self) -> Dict:
23
- """ This method is called when a new annotation session is started.
24
- The function should return an empty history object."""
25
-
26
- @abstractmethod
27
- def logout_user(self, sid: str) -> bool:
28
- """ This method is called when a user disconnects from the server.
29
- The function should return True if the user was logged out successfully."""
@@ -1,116 +0,0 @@
1
- from dataclasses import asdict
2
- from typing import Dict, Optional
3
-
4
- from dacite import from_dict
5
- from fastapi.encoders import jsonable_encoder
6
- from socketio import AsyncClient
7
-
8
- from ..data_classes import AnnotationNodeStatus, Context, NodeState, UserInput
9
- from ..data_classes.socket_response import SocketResponse
10
- from ..data_exchanger import DataExchanger
11
- from ..helpers.misc import create_image_folder, create_project_folder
12
- from ..node import Node
13
- from .annotator_logic import AnnotatorLogic
14
-
15
- # TODO: The use case 'segmentation' is hardcoded here. This should be more flexible.
16
-
17
-
18
- class AnnotatorNode(Node):
19
-
20
- def __init__(self, name: str, annotator_logic: AnnotatorLogic, uuid: Optional[str] = None):
21
- super().__init__(name, uuid=uuid, node_type='annotation_node')
22
- self.tool = annotator_logic
23
- self.histories: Dict = {}
24
- annotator_logic.init(self)
25
-
26
- def register_sio_events(self, sio_client: AsyncClient):
27
-
28
- @sio_client.event
29
- async def handle_user_input(user_input_dict):
30
- return await self._handle_user_input(user_input_dict)
31
-
32
- @sio_client.event
33
- async def user_logout(sid):
34
- self.reset_history(sid)
35
- return self.tool.logout_user(sid)
36
-
37
- async def _handle_user_input(self, user_input_dict: Dict) -> str:
38
- if not self.sio_client or not self.sio_client.connected:
39
- raise ConnectionError('SocketIO client is not connected')
40
-
41
- user_input = from_dict(data_class=UserInput, data=user_input_dict)
42
-
43
- if user_input.data.key_up == 'Escape':
44
- self.reset_history(user_input.frontend_id)
45
- return ''
46
-
47
- await self.download_image(user_input.data.context, user_input.data.image_uuid)
48
-
49
- try:
50
- tool_result = await self.tool.handle_user_input(user_input, self.get_history(user_input.frontend_id))
51
- except Exception:
52
- self.reset_history(user_input.frontend_id)
53
- raise
54
-
55
- if tool_result.annotation:
56
- await self.sio_client.call('update_segmentation_annotation', (user_input.data.context.organization,
57
- user_input.data.context.project,
58
- jsonable_encoder(asdict(tool_result.annotation))), timeout=30)
59
- return tool_result.svg
60
-
61
- def reset_history(self, frontend_id: str) -> None:
62
- """Reset the history for a given frontend_id."""
63
- if frontend_id in self.histories:
64
- del self.histories[frontend_id]
65
-
66
- def get_history(self, frontend_id: str) -> Dict:
67
- """Get the history for a given frontend_id. If no history exists, create a new one."""
68
- return self.histories.setdefault(frontend_id, self.tool.create_empty_history())
69
-
70
- async def send_status(self):
71
-
72
- if not self.sio_client or not self.sio_client.connected:
73
- raise ConnectionError('SocketIO client is not connected')
74
-
75
- status = AnnotationNodeStatus(
76
- id=self.uuid,
77
- name=self.name,
78
- state=NodeState.Online,
79
- capabilities=['segmentation']
80
- )
81
-
82
- self.log_status_on_change(status.state.value if status.state else 'None', status)
83
-
84
- try:
85
- result = await self.sio_client.call('update_annotation_node', jsonable_encoder(asdict(status)), timeout=10)
86
- except Exception:
87
- self.socket_connection_broken = True
88
- self.log.exception('Error for updating:')
89
- return
90
-
91
- if not isinstance(result, Dict):
92
- self.socket_connection_broken = True
93
- self.log.error('Expected Dict, got %s', type(result))
94
- return
95
-
96
- response = from_dict(data_class=SocketResponse, data=result)
97
-
98
- if not response.success:
99
- self.socket_connection_broken = True
100
- self.log.error('Response from loop was: %s', asdict(response))
101
-
102
- async def download_image(self, context: Context, uuid: str):
103
- project_folder = create_project_folder(context)
104
- images_folder = create_image_folder(project_folder)
105
-
106
- downloader = DataExchanger(context=context, loop_communicator=self.loop_communicator)
107
- await downloader.download_images([uuid], images_folder)
108
-
109
- async def on_startup(self):
110
- pass
111
-
112
- async def on_shutdown(self):
113
- pass
114
-
115
- async def on_repeat(self):
116
- await self.send_status()