code-loader 1.0.28__py3-none-any.whl → 1.0.31__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 +3 -1
- code_loader/inner_leap_binder/leapbinder.py +5 -2
- code_loader/leaploader.py +2 -2
- {code_loader-1.0.28.dist-info → code_loader-1.0.31.dist-info}/METADATA +1 -1
- {code_loader-1.0.28.dist-info → code_loader-1.0.31.dist-info}/RECORD +7 -8
- code_loader/code_inegration_processes_manager.py +0 -83
- {code_loader-1.0.28.dist-info → code_loader-1.0.31.dist-info}/LICENSE +0 -0
- {code_loader-1.0.28.dist-info → code_loader-1.0.31.dist-info}/WHEEL +0 -0
@@ -8,6 +8,8 @@ from code_loader.contract.enums import DataStateType, DataStateEnum, LeapDataTyp
|
|
8
8
|
from code_loader.contract.visualizer_classes import LeapImage, LeapText, LeapGraph, LeapHorizontalBar, \
|
9
9
|
LeapTextMask, LeapImageMask, LeapImageWithBBox
|
10
10
|
|
11
|
+
custom_latent_space_attribute = "custom_latent_space"
|
12
|
+
|
11
13
|
|
12
14
|
@dataclass
|
13
15
|
class PreprocessResponse:
|
@@ -52,7 +54,7 @@ VisualizerCallableInterface = Union[
|
|
52
54
|
]
|
53
55
|
|
54
56
|
VisualizerCallableReturnType = Union[LeapImage, LeapText, LeapGraph, LeapHorizontalBar,
|
55
|
-
|
57
|
+
LeapImageMask, LeapTextMask, LeapImageWithBBox]
|
56
58
|
|
57
59
|
CustomCallableInterface = Callable[..., Any]
|
58
60
|
|
@@ -9,7 +9,7 @@ from code_loader.contract.datasetclasses import SectionCallableInterface, InputH
|
|
9
9
|
PreprocessHandler, VisualizerCallableInterface, CustomLossHandler, CustomCallableInterface, PredictionTypeHandler, \
|
10
10
|
MetadataSectionCallableInterface, UnlabeledDataPreprocessHandler, CustomLayerHandler, MetricHandler, \
|
11
11
|
CustomCallableInterfaceMultiArgs, ConfusionMatrixCallableInterfaceMultiArgs, VisualizerCallableReturnType, \
|
12
|
-
CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler
|
12
|
+
CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler, custom_latent_space_attribute
|
13
13
|
from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType
|
14
14
|
from code_loader.contract.responsedataclasses import DatasetTestResultPayload
|
15
15
|
from code_loader.contract.visualizer_classes import map_leap_data_type_to_visualizer_class
|
@@ -120,10 +120,13 @@ class LeapBinder:
|
|
120
120
|
self.setup_container.metadata.append(MetadataHandler(name, function))
|
121
121
|
|
122
122
|
def set_custom_layer(self, custom_layer: Type[Any], name: str, inspect_layer: bool = False,
|
123
|
-
kernel_index: Optional[int] = None) -> None:
|
123
|
+
kernel_index: Optional[int] = None, use_custom_latent_space: bool = False) -> None:
|
124
124
|
if inspect_layer and kernel_index is not None:
|
125
125
|
custom_layer.kernel_index = kernel_index
|
126
126
|
|
127
|
+
if use_custom_latent_space and not hasattr(custom_layer, custom_latent_space_attribute):
|
128
|
+
raise Exception(f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
|
129
|
+
|
127
130
|
init_args = inspect.getfullargspec(custom_layer.__init__)[0][1:]
|
128
131
|
call_args = inspect.getfullargspec(custom_layer.call)[0][1:]
|
129
132
|
self.setup_container.custom_layers[name] = CustomLayerHandler(name, custom_layer, init_args, call_args)
|
code_loader/leaploader.py
CHANGED
@@ -128,11 +128,11 @@ class LeapLoader:
|
|
128
128
|
setup_response = self.get_dataset_setup_response(handlers_test_payloads)
|
129
129
|
except DatasetScriptException as e:
|
130
130
|
line_number, file_name, stacktrace = get_root_exception_file_and_line_number()
|
131
|
-
general_error = f"{repr(e.__cause__)} in file {file_name}, line_number: {line_number}\nStacktrace:\n{stacktrace}"
|
131
|
+
general_error = f"Something went wrong. {repr(e.__cause__)} in file {file_name}, line_number: {line_number}\nStacktrace:\n{stacktrace}"
|
132
132
|
is_valid = False
|
133
133
|
except Exception as e:
|
134
134
|
line_number, file_name, stacktrace = get_root_exception_file_and_line_number()
|
135
|
-
general_error = f"{repr(e.__cause__)} in file {file_name}, line_number: {line_number}\nStacktrace:\n{stacktrace}"
|
135
|
+
general_error = f"Something went wrong. {repr(e.__cause__)} in file {file_name}, line_number: {line_number}\nStacktrace:\n{stacktrace}"
|
136
136
|
is_valid = False
|
137
137
|
|
138
138
|
print_log = stdout_steam.getvalue()
|
@@ -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=
|
4
|
+
code_loader/contract/datasetclasses.py,sha256=LbfWSWuqtvvn-hurYnkJVltLZNzjRF76h8HAlZdPwiU,4472
|
6
5
|
code_loader/contract/enums.py,sha256=KDIeNl79e8rCp4ybJat7U03j50McrcBTWUxko5SXrug,1481
|
7
6
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
8
7
|
code_loader/contract/responsedataclasses.py,sha256=0bo4iLbfu6-3tpgzeKakIH2i_1jtR8BiLdupa1TVT0o,2679
|
9
8
|
code_loader/contract/visualizer_classes.py,sha256=1FjVO744J_EMuJfHWXGdvSz6vl3Vu7iS3CDfs8MzEEQ,5138
|
10
9
|
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
11
|
-
code_loader/inner_leap_binder/leapbinder.py,sha256=
|
12
|
-
code_loader/leaploader.py,sha256=
|
10
|
+
code_loader/inner_leap_binder/leapbinder.py,sha256=MYYOZA2vpQo06p6kdOGqYUS7-QWlIlmGO99p_ITe3JQ,12840
|
11
|
+
code_loader/leaploader.py,sha256=S8gpDJCk0K2prvja7GzNWqLlBRx7h2jAd-PoL0RevY0,17243
|
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.31.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
16
|
+
code_loader-1.0.31.dist-info/METADATA,sha256=UjP-_7vnZtTuKG3oVVfB-928yBG4vyvDA2T4vPgA_Oo,768
|
17
|
+
code_loader-1.0.31.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
18
|
+
code_loader-1.0.31.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
|
File without changes
|