sciveo 0.1.24__tar.gz → 0.1.26__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 (125) hide show
  1. {sciveo-0.1.24 → sciveo-0.1.26}/PKG-INFO +1 -1
  2. sciveo-0.1.26/sciveo/media/__init__.py +56 -0
  3. sciveo-0.1.26/sciveo/media/ml/__init__.py +56 -0
  4. sciveo-0.1.26/sciveo/media/ml/base.py +48 -0
  5. sciveo-0.1.26/sciveo/media/ml/encoders/__init__.py +56 -0
  6. sciveo-0.1.26/sciveo/media/ml/encoders/base.py +24 -0
  7. sciveo-0.1.26/sciveo/media/ml/encoders/normalizer.py +32 -0
  8. sciveo-0.1.26/sciveo/media/ml/nlp/__init__.py +56 -0
  9. sciveo-0.1.26/sciveo/media/ml/nlp/search.py +70 -0
  10. sciveo-0.1.26/sciveo/media/ml/time_series/__init__.py +56 -0
  11. sciveo-0.1.26/sciveo/media/ml/time_series/dataset.py +67 -0
  12. sciveo-0.1.26/sciveo/media/ml/time_series/predictor.py +105 -0
  13. sciveo-0.1.26/sciveo/media/ml/time_series/trainer.py +126 -0
  14. sciveo-0.1.26/sciveo/media/ml/time_series/window_generator.py +121 -0
  15. sciveo-0.1.26/sciveo/media/pipelines/__init__.py +56 -0
  16. sciveo-0.1.26/sciveo/media/pipelines/base.py +165 -0
  17. sciveo-0.1.26/sciveo/media/pipelines/job_daemon.py +59 -0
  18. sciveo-0.1.26/sciveo/media/pipelines/layouts/__init__.py +56 -0
  19. sciveo-0.1.26/sciveo/media/pipelines/layouts/base.py +25 -0
  20. sciveo-0.1.26/sciveo/media/pipelines/pipeline.py +183 -0
  21. sciveo-0.1.26/sciveo/media/pipelines/postprocessors/__init__.py +56 -0
  22. sciveo-0.1.26/sciveo/media/pipelines/postprocessors/base.py +26 -0
  23. sciveo-0.1.26/sciveo/media/pipelines/postprocessors/default.py +155 -0
  24. sciveo-0.1.26/sciveo/media/pipelines/processors/__init__.py +56 -0
  25. sciveo-0.1.26/sciveo/media/pipelines/processors/audio/__init__.py +56 -0
  26. sciveo-0.1.26/sciveo/media/pipelines/processors/audio/audio.py +99 -0
  27. sciveo-0.1.26/sciveo/media/pipelines/processors/audio/audio_extractor_process.py +151 -0
  28. sciveo-0.1.26/sciveo/media/pipelines/processors/aws.py +49 -0
  29. sciveo-0.1.26/sciveo/media/pipelines/processors/base.py +81 -0
  30. sciveo-0.1.26/sciveo/media/pipelines/processors/file/__init__.py +56 -0
  31. sciveo-0.1.26/sciveo/media/pipelines/processors/file/archive.py +90 -0
  32. sciveo-0.1.26/sciveo/media/pipelines/processors/image/__init__.py +56 -0
  33. sciveo-0.1.26/sciveo/media/pipelines/processors/image/album.py +129 -0
  34. sciveo-0.1.26/sciveo/media/pipelines/processors/image/album_in_image.py +126 -0
  35. sciveo-0.1.26/sciveo/media/pipelines/processors/image/depth_esimation.py +85 -0
  36. sciveo-0.1.26/sciveo/media/pipelines/processors/image/embeddings.py +80 -0
  37. sciveo-0.1.26/sciveo/media/pipelines/processors/image/filters.py +268 -0
  38. sciveo-0.1.26/sciveo/media/pipelines/processors/image/generators.py +309 -0
  39. sciveo-0.1.26/sciveo/media/pipelines/processors/image/histogram.py +72 -0
  40. sciveo-0.1.26/sciveo/media/pipelines/processors/image/mask.py +131 -0
  41. sciveo-0.1.26/sciveo/media/pipelines/processors/image/resize.py +51 -0
  42. sciveo-0.1.26/sciveo/media/pipelines/processors/image/segmentation.py +87 -0
  43. sciveo-0.1.26/sciveo/media/pipelines/processors/image/watermark.py +90 -0
  44. sciveo-0.1.26/sciveo/media/pipelines/processors/media_info.py +153 -0
  45. sciveo-0.1.26/sciveo/media/pipelines/processors/nlp/__init__.py +56 -0
  46. sciveo-0.1.26/sciveo/media/pipelines/processors/nlp/address.py +160 -0
  47. sciveo-0.1.26/sciveo/media/pipelines/processors/qr.py +79 -0
  48. sciveo-0.1.26/sciveo/media/pipelines/processors/sci/__init__.py +56 -0
  49. sciveo-0.1.26/sciveo/media/pipelines/processors/sci/base.py +164 -0
  50. sciveo-0.1.26/sciveo/media/pipelines/processors/sci/dataset.py +99 -0
  51. sciveo-0.1.26/sciveo/media/pipelines/processors/sci/time_series/__init__.py +56 -0
  52. sciveo-0.1.26/sciveo/media/pipelines/processors/sci/time_series/predictor.py +108 -0
  53. sciveo-0.1.26/sciveo/media/pipelines/processors/sci/time_series/trainer.py +185 -0
  54. sciveo-0.1.26/sciveo/media/pipelines/processors/tpu_base.py +36 -0
  55. sciveo-0.1.26/sciveo/media/pipelines/processors/video/__init__.py +56 -0
  56. sciveo-0.1.26/sciveo/media/pipelines/processors/video/generators.py +49 -0
  57. sciveo-0.1.26/sciveo/media/pipelines/processors/video/motion_detection.py +73 -0
  58. sciveo-0.1.26/sciveo/media/pipelines/processors/video/resize.py +77 -0
  59. sciveo-0.1.26/sciveo/media/pipelines/processors/video/video_album.py +119 -0
  60. sciveo-0.1.26/sciveo/media/pipelines/processors/video/video_frames.py +58 -0
  61. sciveo-0.1.26/sciveo/media/pipelines/processors/video/video_resample.py +65 -0
  62. sciveo-0.1.26/sciveo/media/pipelines/queues.py +68 -0
  63. sciveo-0.1.26/sciveo/media/pipelines/server.py +73 -0
  64. sciveo-0.1.26/sciveo/media/pipelines/web/__init__.py +56 -0
  65. sciveo-0.1.26/sciveo/media/pipelines/web/server.py +106 -0
  66. sciveo-0.1.26/sciveo/tools/aws/__init__.py +56 -0
  67. sciveo-0.1.26/sciveo/tools/aws/priority_queue.py +109 -0
  68. sciveo-0.1.26/sciveo/tools/aws/s3.py +49 -0
  69. sciveo-0.1.26/sciveo/version.py +2 -0
  70. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo.egg-info/PKG-INFO +1 -1
  71. sciveo-0.1.26/sciveo.egg-info/SOURCES.txt +121 -0
  72. sciveo-0.1.24/sciveo/version.py +0 -2
  73. sciveo-0.1.24/sciveo.egg-info/SOURCES.txt +0 -54
  74. {sciveo-0.1.24 → sciveo-0.1.26}/README.md +0 -0
  75. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/__init__.py +0 -0
  76. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/api/__init__.py +0 -0
  77. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/api/base.py +0 -0
  78. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/api/upload.py +0 -0
  79. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/cli.py +0 -0
  80. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/common/__init__.py +0 -0
  81. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/common/configuration.py +0 -0
  82. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/common/model.py +0 -0
  83. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/common/optimizers.py +0 -0
  84. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/common/sampling.py +0 -0
  85. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/content/__init__.py +0 -0
  86. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/content/dataset.py +0 -0
  87. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/content/experiment.py +0 -0
  88. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/content/project.py +0 -0
  89. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/content/runner.py +0 -0
  90. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/monitoring/__init__.py +0 -0
  91. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/monitoring/monitor.py +0 -0
  92. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/monitoring/start.py +0 -0
  93. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/network/__init__.py +0 -0
  94. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/network/camera.py +0 -0
  95. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/network/sniffer.py +0 -0
  96. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/network/tools.py +0 -0
  97. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/__init__.py +0 -0
  98. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/array.py +0 -0
  99. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/common.py +0 -0
  100. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/compress.py +0 -0
  101. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/configuration.py +0 -0
  102. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/crypto.py +0 -0
  103. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/daemon.py +0 -0
  104. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/formating.py +0 -0
  105. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/hardware.py +0 -0
  106. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/http.py +0 -0
  107. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/logger.py +0 -0
  108. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/os.py +0 -0
  109. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/random.py +0 -0
  110. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/remote.py +0 -0
  111. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/simple_counter.py +0 -0
  112. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/synchronized.py +0 -0
  113. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo/tools/timers.py +0 -0
  114. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo.egg-info/dependency_links.txt +0 -0
  115. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo.egg-info/entry_points.txt +0 -0
  116. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo.egg-info/requires.txt +0 -0
  117. {sciveo-0.1.24 → sciveo-0.1.26}/sciveo.egg-info/top_level.txt +0 -0
  118. {sciveo-0.1.24 → sciveo-0.1.26}/setup.cfg +0 -0
  119. {sciveo-0.1.24 → sciveo-0.1.26}/setup.py +0 -0
  120. {sciveo-0.1.24 → sciveo-0.1.26}/test/test_compress.py +0 -0
  121. {sciveo-0.1.24 → sciveo-0.1.26}/test/test_configuration.py +0 -0
  122. {sciveo-0.1.24 → sciveo-0.1.26}/test/test_crypto.py +0 -0
  123. {sciveo-0.1.24 → sciveo-0.1.26}/test/test_monitoring.py +0 -0
  124. {sciveo-0.1.24 → sciveo-0.1.26}/test/test_runner.py +0 -0
  125. {sciveo-0.1.24 → sciveo-0.1.26}/test/test_sampling.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.24
3
+ Version: 0.1.26
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -0,0 +1,56 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2023
10
+ #
11
+
12
+ from builtins import ImportError
13
+
14
+ try:
15
+
16
+ import os
17
+ import time
18
+
19
+ from sciveo.tools.logger import *
20
+ from sciveo.tools.daemon import TasksDaemon, __upload_content__
21
+ from sciveo.content.runner import ProjectRunner
22
+ from sciveo.content.dataset import Dataset
23
+ from sciveo.monitoring.start import MonitorStart
24
+ from sciveo.network.tools import NetworkTools
25
+ from sciveo.version import __version__
26
+
27
+
28
+ TasksDaemon.current = TasksDaemon(num_threads=int(os.environ.get("SCIVEO_TASKS_NUM_THREADS", 1)))
29
+
30
+
31
+ # New Experiment
32
+ def open():
33
+ if ProjectRunner.current is not None:
34
+ return ProjectRunner.current.project
35
+ else:
36
+ error("there is no started project")
37
+
38
+ def start(project, function, configuration={}, **kwargs):
39
+ TasksDaemon.current.start()
40
+ ProjectRunner.current = ProjectRunner(project=project, function=function, configuration=configuration, **kwargs)
41
+ ProjectRunner.current.run()
42
+
43
+ # Dataset info
44
+ def dataset(info={}):
45
+ return Dataset.get(info)
46
+
47
+ # Monitoring start
48
+ def monitor(**kwargs):
49
+ MonitorStart(**kwargs)()
50
+
51
+ # Network tools
52
+ def network(**kwargs):
53
+ return NetworkTools(**kwargs)
54
+
55
+ except ImportError as e:
56
+ pass
@@ -0,0 +1,56 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2023
10
+ #
11
+
12
+ from builtins import ImportError
13
+
14
+ try:
15
+
16
+ import os
17
+ import time
18
+
19
+ from sciveo.tools.logger import *
20
+ from sciveo.tools.daemon import TasksDaemon, __upload_content__
21
+ from sciveo.content.runner import ProjectRunner
22
+ from sciveo.content.dataset import Dataset
23
+ from sciveo.monitoring.start import MonitorStart
24
+ from sciveo.network.tools import NetworkTools
25
+ from sciveo.version import __version__
26
+
27
+
28
+ TasksDaemon.current = TasksDaemon(num_threads=int(os.environ.get("SCIVEO_TASKS_NUM_THREADS", 1)))
29
+
30
+
31
+ # New Experiment
32
+ def open():
33
+ if ProjectRunner.current is not None:
34
+ return ProjectRunner.current.project
35
+ else:
36
+ error("there is no started project")
37
+
38
+ def start(project, function, configuration={}, **kwargs):
39
+ TasksDaemon.current.start()
40
+ ProjectRunner.current = ProjectRunner(project=project, function=function, configuration=configuration, **kwargs)
41
+ ProjectRunner.current.run()
42
+
43
+ # Dataset info
44
+ def dataset(info={}):
45
+ return Dataset.get(info)
46
+
47
+ # Monitoring start
48
+ def monitor(**kwargs):
49
+ MonitorStart(**kwargs)()
50
+
51
+ # Network tools
52
+ def network(**kwargs):
53
+ return NetworkTools(**kwargs)
54
+
55
+ except ImportError as e:
56
+ pass
@@ -0,0 +1,48 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import matplotlib.pyplot as plt
13
+ import matplotlib.dates as mdates
14
+
15
+ import numpy as np
16
+ import pandas as pd
17
+
18
+ from sciveo.tools.logger import *
19
+ from sciveo.tools.array import *
20
+ from sciveo.media.ml.encoders.normalizer import *
21
+
22
+
23
+ class BaseDataSet:
24
+ def __init__(self, data, columns=None):
25
+ self.data = data
26
+ self.normalizer = Normalizer()
27
+
28
+ if columns is not None:
29
+ self.data = self.data[columns]
30
+ self.columns = self.data.columns
31
+
32
+ def normalize(self):
33
+ self.data = self.normalizer.transform(self.data)
34
+ def denormalize(self, key):
35
+ self.dataset[key] = self.normalizer.inverse(self.dataset[key])
36
+
37
+ # Split dataset
38
+ def split(self, ratios=[["train", 0.85], ["val", 0.10], ["test", 0.05]]):
39
+ self.ratios = ratios
40
+ self.dataset = {}
41
+ prev_idx = 0
42
+ for k, v in ratios:
43
+ next_idx = prev_idx + int(self.data.shape[0] * v)
44
+ self.dataset[k] = self.data[prev_idx:next_idx]
45
+ prev_idx = next_idx
46
+
47
+ def summary(self):
48
+ return self.data.describe().transpose()[["count", "min", "max", "mean", "std", "25%", "50%", "75%"]]
@@ -0,0 +1,56 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2023
10
+ #
11
+
12
+ from builtins import ImportError
13
+
14
+ try:
15
+
16
+ import os
17
+ import time
18
+
19
+ from sciveo.tools.logger import *
20
+ from sciveo.tools.daemon import TasksDaemon, __upload_content__
21
+ from sciveo.content.runner import ProjectRunner
22
+ from sciveo.content.dataset import Dataset
23
+ from sciveo.monitoring.start import MonitorStart
24
+ from sciveo.network.tools import NetworkTools
25
+ from sciveo.version import __version__
26
+
27
+
28
+ TasksDaemon.current = TasksDaemon(num_threads=int(os.environ.get("SCIVEO_TASKS_NUM_THREADS", 1)))
29
+
30
+
31
+ # New Experiment
32
+ def open():
33
+ if ProjectRunner.current is not None:
34
+ return ProjectRunner.current.project
35
+ else:
36
+ error("there is no started project")
37
+
38
+ def start(project, function, configuration={}, **kwargs):
39
+ TasksDaemon.current.start()
40
+ ProjectRunner.current = ProjectRunner(project=project, function=function, configuration=configuration, **kwargs)
41
+ ProjectRunner.current.run()
42
+
43
+ # Dataset info
44
+ def dataset(info={}):
45
+ return Dataset.get(info)
46
+
47
+ # Monitoring start
48
+ def monitor(**kwargs):
49
+ MonitorStart(**kwargs)()
50
+
51
+ # Network tools
52
+ def network(**kwargs):
53
+ return NetworkTools(**kwargs)
54
+
55
+ except ImportError as e:
56
+ pass
@@ -0,0 +1,24 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+
13
+ class BaseEncoder:
14
+ def fit(self, X):
15
+ pass
16
+
17
+ def transform(self, X):
18
+ pass
19
+
20
+ def fit_transform(self, X):
21
+ pass
22
+
23
+ def inverse(self, X):
24
+ pass
@@ -0,0 +1,32 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ from sciveo.media.ml.encoders.base import *
13
+
14
+
15
+ class Normalizer:
16
+ def __init(self):
17
+ self.mean = 0
18
+ self.std = 0
19
+
20
+ def fit(self, X):
21
+ self.mean = X.mean(axis=0)
22
+ self.std = X.std(axis=0)
23
+
24
+ def transform(self, X):
25
+ return (X - self.mean) / self.std
26
+
27
+ def fit_transform(self, X):
28
+ self.fit(X)
29
+ return self.transform(X)
30
+
31
+ def inverse(self, X):
32
+ return X * self.std + self.mean
@@ -0,0 +1,56 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2023
10
+ #
11
+
12
+ from builtins import ImportError
13
+
14
+ try:
15
+
16
+ import os
17
+ import time
18
+
19
+ from sciveo.tools.logger import *
20
+ from sciveo.tools.daemon import TasksDaemon, __upload_content__
21
+ from sciveo.content.runner import ProjectRunner
22
+ from sciveo.content.dataset import Dataset
23
+ from sciveo.monitoring.start import MonitorStart
24
+ from sciveo.network.tools import NetworkTools
25
+ from sciveo.version import __version__
26
+
27
+
28
+ TasksDaemon.current = TasksDaemon(num_threads=int(os.environ.get("SCIVEO_TASKS_NUM_THREADS", 1)))
29
+
30
+
31
+ # New Experiment
32
+ def open():
33
+ if ProjectRunner.current is not None:
34
+ return ProjectRunner.current.project
35
+ else:
36
+ error("there is no started project")
37
+
38
+ def start(project, function, configuration={}, **kwargs):
39
+ TasksDaemon.current.start()
40
+ ProjectRunner.current = ProjectRunner(project=project, function=function, configuration=configuration, **kwargs)
41
+ ProjectRunner.current.run()
42
+
43
+ # Dataset info
44
+ def dataset(info={}):
45
+ return Dataset.get(info)
46
+
47
+ # Monitoring start
48
+ def monitor(**kwargs):
49
+ MonitorStart(**kwargs)()
50
+
51
+ # Network tools
52
+ def network(**kwargs):
53
+ return NetworkTools(**kwargs)
54
+
55
+ except ImportError as e:
56
+ pass
@@ -0,0 +1,70 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import os
13
+ import requests
14
+
15
+ import numpy as np
16
+ import pandas as pd
17
+
18
+ import torch
19
+ from transformers import pipeline, AutoTokenizer, AutoModel
20
+ from transformers import AutoModelForSeq2SeqLM
21
+
22
+ from annoy import AnnoyIndex
23
+ from sciveo.tools.logger import *
24
+
25
+ from sciveo.media.pipelines.base import ApiContent
26
+
27
+
28
+ class SearchTrainer:
29
+ def __init__(self, name) -> None:
30
+ self.name = name
31
+ self.api = ApiContent()
32
+
33
+ dataset_path = os.environ.get("MEDIA_DATASETS_BASE_PATH", "data")
34
+ self.db_path = os.path.join(dataset_path, f"{self.name}.vdb")
35
+ self.data_path = os.path.join(dataset_path, f"{self.name}.csv")
36
+
37
+ def init(self):
38
+ cache_dir = os.path.join(os.environ['MEDIA_MODELS_BASE_PATH'], "models/")
39
+ self.pipe = AutoModel.from_pretrained(
40
+ 'softel/mpnet-base-v0.3',
41
+ cache_dir=cache_dir, resume_download=True
42
+ )
43
+ self.tokenizer = AutoTokenizer.from_pretrained(
44
+ 'softel/mpnet-base-v0.3',
45
+ cache_dir=cache_dir, resume_download=True
46
+ )
47
+ self.vdb = AnnoyIndex(768, 'euclidean')
48
+
49
+ def api_load(self):
50
+ fields = "fields=['guid','content_type,'owner','description','name','parent','processors']"
51
+ url_postfix = f"content_type=image&content_type=video&~description=&{fields}"
52
+ self.data = self.api.read(url_postfix, limit=10)
53
+ url_postfix = f"content_type=image&processors=image-diffusion&{fields}"
54
+ self.data += self.api.read(url_postfix, limit=10)
55
+
56
+ def embed(self, text):
57
+ inputs = self.tokenizer.encode_plus(text, return_tensors='pt')
58
+ outputs = self.pipe(**inputs)
59
+ sequence_output = outputs[0]
60
+ input_mask_expanded = inputs['attention_mask'].unsqueeze(-1).expand(sequence_output.size()).float()
61
+ embeddings = torch.sum(sequence_output * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
62
+ return embeddings.detach().numpy()[0]
63
+
64
+ def train(self):
65
+ self.api_load()
66
+
67
+
68
+ if __name__ == '__main__':
69
+ trainer = SearchTrainer("content_search")
70
+ trainer.api_load()
@@ -0,0 +1,56 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2023
10
+ #
11
+
12
+ from builtins import ImportError
13
+
14
+ try:
15
+
16
+ import os
17
+ import time
18
+
19
+ from sciveo.tools.logger import *
20
+ from sciveo.tools.daemon import TasksDaemon, __upload_content__
21
+ from sciveo.content.runner import ProjectRunner
22
+ from sciveo.content.dataset import Dataset
23
+ from sciveo.monitoring.start import MonitorStart
24
+ from sciveo.network.tools import NetworkTools
25
+ from sciveo.version import __version__
26
+
27
+
28
+ TasksDaemon.current = TasksDaemon(num_threads=int(os.environ.get("SCIVEO_TASKS_NUM_THREADS", 1)))
29
+
30
+
31
+ # New Experiment
32
+ def open():
33
+ if ProjectRunner.current is not None:
34
+ return ProjectRunner.current.project
35
+ else:
36
+ error("there is no started project")
37
+
38
+ def start(project, function, configuration={}, **kwargs):
39
+ TasksDaemon.current.start()
40
+ ProjectRunner.current = ProjectRunner(project=project, function=function, configuration=configuration, **kwargs)
41
+ ProjectRunner.current.run()
42
+
43
+ # Dataset info
44
+ def dataset(info={}):
45
+ return Dataset.get(info)
46
+
47
+ # Monitoring start
48
+ def monitor(**kwargs):
49
+ MonitorStart(**kwargs)()
50
+
51
+ # Network tools
52
+ def network(**kwargs):
53
+ return NetworkTools(**kwargs)
54
+
55
+ except ImportError as e:
56
+ pass
@@ -0,0 +1,67 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import matplotlib.pyplot as plt
13
+ import matplotlib.dates as mdates
14
+
15
+ import numpy as np
16
+ import pandas as pd
17
+
18
+ import tensorflow as tf
19
+ from tensorflow import keras
20
+
21
+ from sciveo.tools.logger import *
22
+ from sciveo.tools.array import *
23
+ from sciveo.media.ml.encoders.normalizer import *
24
+ from sciveo.media.ml.time_series.window_generator import *
25
+ from sciveo.media.ml.base import BaseDataSet
26
+
27
+
28
+ class TimeSeriesDataSet(BaseDataSet):
29
+ def __init__(self, data, time_col, format='%Y-%m-%d %H24:%M:%S', columns=None, new_period_columns=True):
30
+ super().__init__(data, columns)
31
+
32
+ debug(f"time_col [{time_col}] format[{format}]")
33
+ debug("columns", self.data.columns)
34
+
35
+ self.time_col = time_col
36
+ if "datetime" not in str(self.data[time_col].dtype):
37
+ self.data[time_col] = pd.to_datetime(self.data[time_col], format=format)
38
+ self.data = self.data.set_index(time_col).sort_index()
39
+ self.date_time = self.data.index
40
+
41
+ if new_period_columns:
42
+ timestamp_s = self.date_time.map(pd.Timestamp.timestamp)
43
+ hour = 60 * 60
44
+ day = 24 * hour
45
+ periods = [
46
+ hour,
47
+ day,
48
+ 91.310625 * day,
49
+ 365.2425 * day
50
+ ]
51
+ for period in periods:
52
+ self.data[f"period-sin-{period / day}"] = np.sin(timestamp_s * (2 * np.pi / period))
53
+ # self.data[f"period-cos-{period / day}"] = np.cos(timestamp_s * (2 * np.pi / period))
54
+
55
+ self.columns = self.data.columns
56
+
57
+ self.normalizer.fit(self.data)
58
+
59
+ def plots(self, max_columns=3, max_points=120):
60
+ plot_cols = list(self.data.columns)[:max_columns]
61
+ plot_features = self.data[plot_cols]
62
+ plot_features.index = self.date_time
63
+ _ = plot_features.plot(subplots=True)
64
+
65
+ plot_features = self.data[plot_cols][:max_points]
66
+ plot_features.index = self.date_time[:max_points]
67
+ _ = plot_features.plot(subplots=True)
@@ -0,0 +1,105 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import os
13
+ import joblib
14
+
15
+ import matplotlib.pyplot as plt
16
+ import matplotlib.dates as mdates
17
+
18
+ import numpy as np
19
+ import pandas as pd
20
+
21
+ import tensorflow as tf
22
+ from tensorflow import keras
23
+
24
+ from sciveo.tools.logger import *
25
+ from sciveo.tools.array import *
26
+ from sciveo.media.ml.encoders.normalizer import *
27
+ from sciveo.media.ml.time_series.window_generator import *
28
+ from sciveo.media.ml.time_series.dataset import *
29
+
30
+
31
+ class TimeSeriesPredictor:
32
+ def __init__(self, model_path):
33
+ self.model_path = model_path
34
+
35
+ self.model_data = joblib.load(self.model_path)
36
+
37
+ self.window_generator = WindowGenerator(
38
+ input_width=self.model_data["window"]["input_width"],
39
+ label_width=0,
40
+ shift=self.model_data["window"]["shift"]
41
+ )
42
+
43
+ def predict(self, df, x_expand_factor=2):
44
+ normalizer = self.model_data["normalizer"]
45
+ L = self.model_data["window"]["input_width"]
46
+ F = len(self.model_data["columns"])
47
+ predict_df = df[-L:][self.model_data["columns"]]
48
+ predict_df.index = pd.to_datetime(predict_df.index)
49
+
50
+ x_plot = list(predict_df.index)
51
+ x_plot = self.expand_dates(x_plot, x_expand_factor)
52
+
53
+ predict_df = normalizer.transform(predict_df)
54
+
55
+ X = predict_df.values.reshape((1, L, F)).astype('float32')
56
+ X = tf.convert_to_tensor(X)
57
+
58
+ predictions = self.model_data["model"](X)
59
+ predictions = normalizer.inverse(predictions)
60
+ X = normalizer.inverse(X)
61
+ debug(f"predict {L} shapes: predict_df[{predict_df.shape}] x_plot[{len(x_plot)}] X[{X.shape}] predictions[{predictions.shape}]")
62
+ return predictions, X, x_plot
63
+
64
+ def expand_dates(self, list_dates, expand_factor):
65
+ n = len(list_dates) * expand_factor
66
+ delta = (list_dates[1] - list_dates[0]) # TODO: create more robust delta computation, currently assume equidistant
67
+ expanded_dates = [list_dates[0] + i * delta for i in range(n)]
68
+ return expanded_dates
69
+
70
+ def plot(self, predictions, X, x_plot, plot_col_index, labels=None, image_local_path=None, dpi=100, width=640, height=480):
71
+ L = X.shape[1]
72
+ plot_col = self.model_data["columns"][plot_col_index]
73
+ plt.figure(figsize=(12, 8), dpi=dpi)
74
+
75
+ plt.subplot(1, 1, 1)
76
+ plt.ylabel(f'{plot_col}')
77
+
78
+ plt.plot(
79
+ x_plot[:L], X[0, :, plot_col_index],
80
+ label='X', marker='.', zorder=-10
81
+ )
82
+
83
+ plt.scatter(
84
+ x_plot[L:], predictions[0, :, plot_col_index],
85
+ marker='X', edgecolors='k', label='Predictions',
86
+ c='#ff7f0e', s=64
87
+ )
88
+
89
+ if labels is not None:
90
+ plt.scatter(
91
+ x_plot[L:], labels[0, :, plot_col_index],
92
+ edgecolors='k', label='Labels', c='#2ca02c', s=64
93
+ )
94
+
95
+ plt.xticks(rotation=45)
96
+ plt.tight_layout()
97
+ plt.legend(title=plot_col, loc='upper left')
98
+ plt.xlabel("date time")
99
+
100
+ if image_local_path is not None:
101
+ plt.savefig(image_local_path, format='png', dpi=dpi, bbox_inches='tight', pad_inches=0)
102
+ debug("plot savefig", image_local_path)
103
+ else:
104
+ plt.show()
105
+ plt.close()