code-loader 1.0.59__tar.gz → 1.0.60.dev2__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.
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/PKG-INFO +1 -1
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/contract/datasetclasses.py +1 -1
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/contract/responsedataclasses.py +1 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/inner_leap_binder/leapbinder.py +4 -3
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/inner_leap_binder/leapbinder_decorators.py +6 -2
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/leaploader.py +3 -3
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/pyproject.toml +1 -1
- code_loader-1.0.59/code_loader/code_inegration_processes_manager.py +0 -83
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/LICENSE +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/README.md +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/__init__.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/contract/__init__.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/contract/enums.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/contract/exceptions.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/contract/visualizer_classes.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/__init__.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/api.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/cli_config_utils.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/client.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/epoch.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/experiment.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/experiment_context.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/types.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/utils.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/inner_leap_binder/__init__.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/utils.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/visualizers/__init__.py +0 -0
- {code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/visualizers/default_visualizers.py +0 -0
@@ -181,13 +181,14 @@ class LeapBinder:
|
|
181
181
|
"""
|
182
182
|
self.setup_container.unlabeled_data_preprocess = UnlabeledDataPreprocessHandler(function)
|
183
183
|
|
184
|
-
def set_input(self, function: SectionCallableInterface, name: str) -> None:
|
184
|
+
def set_input(self, function: SectionCallableInterface, name: str, channel_dim: int = -1) -> None:
|
185
185
|
"""
|
186
186
|
Set the input handler function.
|
187
187
|
|
188
188
|
Args:
|
189
189
|
function (SectionCallableInterface): The input handler function.
|
190
190
|
name (str): The name of the input section.
|
191
|
+
channel_dim (int): The dimension of the channels axis
|
191
192
|
|
192
193
|
Example:
|
193
194
|
def input_encoder(subset: PreprocessResponse, index: int) -> np.ndarray:
|
@@ -197,10 +198,10 @@ class LeapBinder:
|
|
197
198
|
img = normalize(img)
|
198
199
|
return img
|
199
200
|
|
200
|
-
leap_binder.set_input(input_encoder, name='input_encoder')
|
201
|
+
leap_binder.set_input(input_encoder, name='input_encoder', channel_dim=-1)
|
201
202
|
"""
|
202
203
|
function = to_numpy_return_wrapper(function)
|
203
|
-
self.setup_container.inputs.append(InputHandler(name, function))
|
204
|
+
self.setup_container.inputs.append(InputHandler(name, function, channel_dim=channel_dim))
|
204
205
|
|
205
206
|
self._encoder_names.append(name)
|
206
207
|
|
@@ -245,14 +245,16 @@ def tensorleap_unlabeled_preprocess():
|
|
245
245
|
return decorating_function
|
246
246
|
|
247
247
|
|
248
|
-
def tensorleap_input_encoder(name: str):
|
248
|
+
def tensorleap_input_encoder(name: str, channel_dim=-1):
|
249
249
|
def decorating_function(user_function: SectionCallableInterface):
|
250
250
|
for input_handler in leap_binder.setup_container.inputs:
|
251
251
|
if input_handler.name == name:
|
252
252
|
raise Exception(f'Input with name {name} already exists. '
|
253
253
|
f'Please choose another')
|
254
|
+
if channel_dim < 0 and channel_dim != -1:
|
255
|
+
raise Exception(f"Channel dim for input {name} is expected to be either -1 or positive")
|
254
256
|
|
255
|
-
leap_binder.set_input(user_function, name)
|
257
|
+
leap_binder.set_input(user_function, name, channel_dim=channel_dim)
|
256
258
|
|
257
259
|
def _validate_input_args(sample_id: Union[int, str], preprocess_response: PreprocessResponse):
|
258
260
|
assert isinstance(sample_id, (int, str)), \
|
@@ -273,6 +275,8 @@ def tensorleap_input_encoder(name: str):
|
|
273
275
|
assert result.dtype == np.float32, \
|
274
276
|
(f'tensorleap_input_encoder validation failed: '
|
275
277
|
f'The return type should be a numpy array of type float32. Got {result.dtype}.')
|
278
|
+
assert channel_dim - 1 <= len(result.shape), (f'tensorleap_input_encoder validation failed: '
|
279
|
+
f'The channel_dim ({channel_dim}) should be <= to the rank of the resulting input rank ({len(result.shape)}).')
|
276
280
|
|
277
281
|
def inner(sample_id, preprocess_response):
|
278
282
|
_validate_input_args(sample_id, preprocess_response)
|
@@ -221,8 +221,8 @@ class LeapLoader:
|
|
221
221
|
if global_leap_binder.setup_container.unlabeled_data_preprocess:
|
222
222
|
unlabeled_length = global_leap_binder.setup_container.unlabeled_data_preprocess.data_length
|
223
223
|
dataset_preprocess = DatasetPreprocess(
|
224
|
-
training_length=setup.preprocess.data_length
|
225
|
-
validation_length=setup.preprocess.data_length
|
224
|
+
training_length=setup.preprocess.data_length.get(DataStateType.training, 0),
|
225
|
+
validation_length=setup.preprocess.data_length.get(DataStateType.validation, 0),
|
226
226
|
test_length=setup.preprocess.data_length.get(DataStateType.test),
|
227
227
|
unlabeled_length=unlabeled_length
|
228
228
|
)
|
@@ -231,7 +231,7 @@ class LeapLoader:
|
|
231
231
|
for inp in setup.inputs:
|
232
232
|
if inp.shape is None:
|
233
233
|
raise Exception(f"cant calculate shape for input, input name:{inp.name}")
|
234
|
-
inputs.append(DatasetInputInstance(name=inp.name, shape=inp.shape))
|
234
|
+
inputs.append(DatasetInputInstance(name=inp.name, shape=inp.shape, channel_dim=inp.channel_dim))
|
235
235
|
|
236
236
|
ground_truths = []
|
237
237
|
for gt in setup.ground_truths:
|
@@ -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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/cli_config_utils.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/experiment_api/experiment_context.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{code_loader-1.0.59 → code_loader-1.0.60.dev2}/code_loader/visualizers/default_visualizers.py
RENAMED
File without changes
|