code-loader 1.0.37__py3-none-any.whl → 1.0.38.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- code_loader/contract/datasetclasses.py +5 -4
- code_loader/contract/enums.py +1 -0
- code_loader/contract/visualizer_classes.py +20 -1
- {code_loader-1.0.37.dist-info → code_loader-1.0.38.dev1.dist-info}/METADATA +1 -1
- {code_loader-1.0.37.dist-info → code_loader-1.0.38.dev1.dist-info}/RECORD +7 -8
- {code_loader-1.0.37.dist-info → code_loader-1.0.38.dev1.dist-info}/WHEEL +1 -1
- code_loader/code_inegration_processes_manager.py +0 -83
- {code_loader-1.0.37.dist-info → code_loader-1.0.38.dev1.dist-info}/LICENSE +0 -0
@@ -6,7 +6,7 @@ import numpy.typing as npt
|
|
6
6
|
|
7
7
|
from code_loader.contract.enums import DataStateType, DataStateEnum, LeapDataType, ConfusionMatrixValue, MetricDirection
|
8
8
|
from code_loader.contract.visualizer_classes import LeapImage, LeapText, LeapGraph, LeapHorizontalBar, \
|
9
|
-
LeapTextMask, LeapImageMask, LeapImageWithBBox
|
9
|
+
LeapTextMask, LeapImageMask, LeapImageWithBBox, LeapImageWithHeatmap
|
10
10
|
|
11
11
|
custom_latent_space_attribute = "custom_latent_space"
|
12
12
|
|
@@ -50,11 +50,12 @@ VisualizerCallableInterface = Union[
|
|
50
50
|
Callable[..., LeapHorizontalBar],
|
51
51
|
Callable[..., LeapImageMask],
|
52
52
|
Callable[..., LeapTextMask],
|
53
|
-
Callable[..., LeapImageWithBBox]
|
53
|
+
Callable[..., LeapImageWithBBox],
|
54
|
+
Callable[..., LeapImageWithHeatmap]
|
54
55
|
]
|
55
56
|
|
56
57
|
VisualizerCallableReturnType = Union[LeapImage, LeapText, LeapGraph, LeapHorizontalBar,
|
57
|
-
LeapImageMask, LeapTextMask, LeapImageWithBBox]
|
58
|
+
LeapImageMask, LeapTextMask, LeapImageWithBBox, LeapImageWithHeatmap]
|
58
59
|
|
59
60
|
CustomCallableInterface = Callable[..., Any]
|
60
61
|
|
@@ -91,7 +92,7 @@ class MetricHandler:
|
|
91
92
|
|
92
93
|
@dataclass
|
93
94
|
class RawInputsForHeatmap:
|
94
|
-
raw_input_by_vizualizer_arg_name: Dict[str, np.
|
95
|
+
raw_input_by_vizualizer_arg_name: Dict[str, npt.NDArray[np.float32]]
|
95
96
|
|
96
97
|
|
97
98
|
@dataclass
|
code_loader/contract/enums.py
CHANGED
@@ -135,6 +135,24 @@ class LeapTextMask:
|
|
135
135
|
validate_type(type(label), str)
|
136
136
|
|
137
137
|
|
138
|
+
@dataclass
|
139
|
+
class LeapImageWithHeatmap:
|
140
|
+
image: npt.NDArray[np.float32]
|
141
|
+
heatmaps: npt.NDArray[np.float32]
|
142
|
+
labels: List[str]
|
143
|
+
type: LeapDataType = LeapDataType.ImageWithHeatmap
|
144
|
+
|
145
|
+
def __post_init__(self) -> None:
|
146
|
+
validate_type(self.type, LeapDataType.ImageWithHeatmap)
|
147
|
+
validate_type(type(self.heatmaps), np.ndarray)
|
148
|
+
validate_type(self.heatmaps.dtype, np.float32)
|
149
|
+
validate_type(type(self.image), np.ndarray)
|
150
|
+
validate_type(self.image.dtype, np.float32)
|
151
|
+
validate_type(type(self.labels), list)
|
152
|
+
for label in self.labels:
|
153
|
+
validate_type(type(label), str)
|
154
|
+
|
155
|
+
|
138
156
|
map_leap_data_type_to_visualizer_class = {
|
139
157
|
LeapDataType.Image.value: LeapImage,
|
140
158
|
LeapDataType.Graph.value: LeapGraph,
|
@@ -142,5 +160,6 @@ map_leap_data_type_to_visualizer_class = {
|
|
142
160
|
LeapDataType.HorizontalBar.value: LeapHorizontalBar,
|
143
161
|
LeapDataType.ImageMask.value: LeapImageMask,
|
144
162
|
LeapDataType.TextMask.value: LeapTextMask,
|
145
|
-
LeapDataType.ImageWithBBox.value: LeapImageWithBBox
|
163
|
+
LeapDataType.ImageWithBBox.value: LeapImageWithBBox,
|
164
|
+
LeapDataType.ImageWithHeatmap.value: LeapImageWithHeatmap
|
146
165
|
}
|
@@ -1,19 +1,18 @@
|
|
1
1
|
LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
2
2
|
code_loader/__init__.py,sha256=V3DEXSN6Ie6PlGeSAbzjp9ufRj0XPJLpD7pDLLYxk6M,122
|
3
|
-
code_loader/code_inegration_processes_manager.py,sha256=XslWOPeNQk4RAFJ_f3tP5Oe3EgcIR7BE7Y8r9Ty73-o,3261
|
4
3
|
code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
code_loader/contract/datasetclasses.py,sha256=
|
6
|
-
code_loader/contract/enums.py,sha256=
|
4
|
+
code_loader/contract/datasetclasses.py,sha256=e4pEajPiktogtrctf29Q9IqG5VaZz0QE_ioc4Ri1ohs,4796
|
5
|
+
code_loader/contract/enums.py,sha256=6Lo7p5CUog68Fd31bCozIuOgIp_IhSiPqWWph2k3OGU,1602
|
7
6
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
8
7
|
code_loader/contract/responsedataclasses.py,sha256=WSHmFZWOFhGL1eED1u-aoRotPQg2owFQ-t3xSViWXSI,2808
|
9
|
-
code_loader/contract/visualizer_classes.py,sha256=
|
8
|
+
code_loader/contract/visualizer_classes.py,sha256=fP7lzIq1SnvxZhfUpC4Q86yxUTaEllYu4pRJ5HaaJdU,5845
|
10
9
|
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
11
10
|
code_loader/inner_leap_binder/leapbinder.py,sha256=cayCJxnksr5lrEIX1HngiuPpTupStti4DD6KX3k-PBI,13610
|
12
11
|
code_loader/leaploader.py,sha256=pUySweZetJ6SsubCcZlDCJpvWmUrm5YlPlkZWQxY1hQ,17289
|
13
12
|
code_loader/utils.py,sha256=61I4PgSl-ZBIe4DifLxMNlBELE-HQR2pB9efVYPceIU,2230
|
14
13
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
14
|
code_loader/visualizers/default_visualizers.py,sha256=HqWx2qfTrroGl2n8Fpmr_4X-rk7tE2oGapjO3gzz4WY,2226
|
16
|
-
code_loader-1.0.
|
17
|
-
code_loader-1.0.
|
18
|
-
code_loader-1.0.
|
19
|
-
code_loader-1.0.
|
15
|
+
code_loader-1.0.38.dev1.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
16
|
+
code_loader-1.0.38.dev1.dist-info/METADATA,sha256=otbPNH618fzsuVdHsOFgpei9WmfFmagAcUqTXk5GoWE,773
|
17
|
+
code_loader-1.0.38.dev1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
18
|
+
code_loader-1.0.38.dev1.dist-info/RECORD,,
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# mypy: ignore-errors
|
2
|
-
import traceback
|
3
|
-
from dataclasses import dataclass
|
4
|
-
|
5
|
-
from typing import List, Tuple, Optional
|
6
|
-
|
7
|
-
from multiprocessing import Process, Queue
|
8
|
-
|
9
|
-
from code_loader.leap_loader_parallelized_base import LeapLoaderParallelizedBase
|
10
|
-
from code_loader.leaploader import LeapLoader
|
11
|
-
from code_loader.contract.enums import DataStateEnum
|
12
|
-
from code_loader.metric_calculator_parallelized import MetricCalculatorParallelized
|
13
|
-
from code_loader.samples_generator_parallelized import SamplesGeneratorParallelized
|
14
|
-
|
15
|
-
|
16
|
-
@dataclass
|
17
|
-
class SampleSerializableError:
|
18
|
-
state: DataStateEnum
|
19
|
-
index: int
|
20
|
-
leap_script_trace: str
|
21
|
-
exception_as_str: str
|
22
|
-
|
23
|
-
|
24
|
-
class CodeIntegrationProcessesManager:
|
25
|
-
def __init__(self, code_path: str, code_entry_name: str, n_workers: Optional[int] = 2,
|
26
|
-
max_samples_in_queue: int = 128) -> None:
|
27
|
-
self.metric_calculator_parallelized = MetricCalculatorParallelized(code_path, code_entry_name)
|
28
|
-
self.samples_generator_parallelized = SamplesGeneratorParallelized(code_path, code_entry_name)
|
29
|
-
|
30
|
-
def _create_and_start_process(self) -> Process:
|
31
|
-
process = self.multiprocessing_context.Process(
|
32
|
-
target=CodeIntegrationProcessesManager._process_func,
|
33
|
-
args=(self.code_path, self.code_entry_name, self._inputs_waiting_to_be_process,
|
34
|
-
self._ready_processed_results))
|
35
|
-
process.daemon = True
|
36
|
-
process.start()
|
37
|
-
return process
|
38
|
-
|
39
|
-
def _run_and_warm_first_process(self):
|
40
|
-
process = self._create_and_start_process()
|
41
|
-
self.processes = [process]
|
42
|
-
|
43
|
-
# needed in order to make sure the preprocess func runs once in nonparallel
|
44
|
-
self._start_process_inputs([(DataStateEnum.training, 0)])
|
45
|
-
self._get_next_ready_processed_result()
|
46
|
-
|
47
|
-
def _operation_decider(self):
|
48
|
-
if self.metric_calculator_parallelized._ready_processed_results.empty() and not \
|
49
|
-
self.metric_calculator_parallelized._inputs_waiting_to_be_process.empty():
|
50
|
-
return 'metric'
|
51
|
-
|
52
|
-
if self.samples_generator_parallelized._ready_processed_results.empty() and not \
|
53
|
-
self.samples_generator_parallelized._inputs_waiting_to_be_process.empty():
|
54
|
-
return 'dataset'
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
@staticmethod
|
60
|
-
def _process_func(code_path: str, code_entry_name: str,
|
61
|
-
samples_to_process: Queue, ready_samples: Queue,
|
62
|
-
metrics_to_process: Queue, ready_metrics: Queue) -> None:
|
63
|
-
import os
|
64
|
-
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
65
|
-
|
66
|
-
leap_loader = LeapLoader(code_path, code_entry_name)
|
67
|
-
while True:
|
68
|
-
|
69
|
-
# decide on sample or metric to process
|
70
|
-
state, idx = samples_to_process.get(block=True)
|
71
|
-
leap_loader._preprocess_result()
|
72
|
-
try:
|
73
|
-
sample = leap_loader.get_sample(state, idx)
|
74
|
-
except Exception as e:
|
75
|
-
leap_script_trace = traceback.format_exc().split('File "<string>"')[-1]
|
76
|
-
ready_samples.put(SampleSerializableError(state, idx, leap_script_trace, str(e)))
|
77
|
-
continue
|
78
|
-
|
79
|
-
ready_samples.put(sample)
|
80
|
-
|
81
|
-
def generate_samples(self, sample_identities: List[Tuple[DataStateEnum, int]]):
|
82
|
-
return self.start_process_inputs(sample_identities)
|
83
|
-
|
File without changes
|