code-loader 1.0.58__tar.gz → 1.0.60.dev1__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.58 → code_loader-1.0.60.dev1}/PKG-INFO +1 -1
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/contract/datasetclasses.py +1 -1
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/contract/responsedataclasses.py +1 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/inner_leap_binder/leapbinder.py +4 -3
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/inner_leap_binder/leapbinder_decorators.py +9 -5
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/leaploader.py +6 -8
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/pyproject.toml +1 -1
- code_loader-1.0.58/code_loader/dualstream.py +0 -32
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/LICENSE +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/README.md +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/__init__.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/contract/__init__.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/contract/enums.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/contract/exceptions.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/contract/visualizer_classes.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/__init__.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/api.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/cli_config_utils.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/client.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/epoch.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/experiment.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/experiment_context.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/types.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/utils.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/inner_leap_binder/__init__.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/utils.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/code_loader/visualizers/__init__.py +0 -0
- {code_loader-1.0.58 → code_loader-1.0.60.dev1}/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)
|
@@ -357,9 +361,9 @@ def tensorleap_custom_loss(name: str):
|
|
357
361
|
(f'tensorleap_custom_loss validation failed: '
|
358
362
|
f'The return type should be a numpy array or a tensorflow tensor. Got {type(result)}.')
|
359
363
|
|
360
|
-
def inner(
|
361
|
-
_validate_input_args(
|
362
|
-
result = user_function(
|
364
|
+
def inner(*args, **kwargs):
|
365
|
+
_validate_input_args(*args, **kwargs)
|
366
|
+
result = user_function(*args, **kwargs)
|
363
367
|
_validate_result(result)
|
364
368
|
return result
|
365
369
|
|
@@ -19,7 +19,6 @@ from code_loader.contract.exceptions import DatasetScriptException
|
|
19
19
|
from code_loader.contract.responsedataclasses import DatasetIntegParseResult, DatasetTestResultPayload, \
|
20
20
|
DatasetPreprocess, DatasetSetup, DatasetInputInstance, DatasetOutputInstance, DatasetMetadataInstance, \
|
21
21
|
VisualizerInstance, PredictionTypeInstance, ModelSetup, CustomLayerInstance, MetricInstance, CustomLossInstance
|
22
|
-
from code_loader.dualstream import DualStream
|
23
22
|
from code_loader.inner_leap_binder import global_leap_binder
|
24
23
|
from code_loader.utils import get_root_exception_file_and_line_number
|
25
24
|
|
@@ -124,9 +123,8 @@ class LeapLoader:
|
|
124
123
|
test_payloads: List[DatasetTestResultPayload] = []
|
125
124
|
setup_response = None
|
126
125
|
general_error = None
|
127
|
-
|
128
|
-
|
129
|
-
with redirect_stdout(dual_stream):
|
126
|
+
stdout_steam = io.StringIO()
|
127
|
+
with redirect_stdout(stdout_steam):
|
130
128
|
try:
|
131
129
|
self.exec_script()
|
132
130
|
preprocess_test_payload = self._check_preprocess()
|
@@ -144,7 +142,7 @@ class LeapLoader:
|
|
144
142
|
general_error = f"Something went wrong. {repr(e.__cause__)} in file {file_name}, line_number: {line_number}\nStacktrace:\n{stacktrace}"
|
145
143
|
is_valid = False
|
146
144
|
|
147
|
-
print_log =
|
145
|
+
print_log = stdout_steam.getvalue()
|
148
146
|
is_valid_for_model = bool(global_leap_binder.setup_container.custom_layers)
|
149
147
|
model_setup = self.get_model_setup_response()
|
150
148
|
|
@@ -223,8 +221,8 @@ class LeapLoader:
|
|
223
221
|
if global_leap_binder.setup_container.unlabeled_data_preprocess:
|
224
222
|
unlabeled_length = global_leap_binder.setup_container.unlabeled_data_preprocess.data_length
|
225
223
|
dataset_preprocess = DatasetPreprocess(
|
226
|
-
training_length=setup.preprocess.data_length
|
227
|
-
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),
|
228
226
|
test_length=setup.preprocess.data_length.get(DataStateType.test),
|
229
227
|
unlabeled_length=unlabeled_length
|
230
228
|
)
|
@@ -233,7 +231,7 @@ class LeapLoader:
|
|
233
231
|
for inp in setup.inputs:
|
234
232
|
if inp.shape is None:
|
235
233
|
raise Exception(f"cant calculate shape for input, input name:{inp.name}")
|
236
|
-
inputs.append(DatasetInputInstance(name=inp.name, shape=inp.shape))
|
234
|
+
inputs.append(DatasetInputInstance(name=inp.name, shape=inp.shape, channel_dim=inp.channel_dim))
|
237
235
|
|
238
236
|
ground_truths = []
|
239
237
|
for gt in setup.ground_truths:
|
@@ -1,32 +0,0 @@
|
|
1
|
-
from io import StringIO
|
2
|
-
from typing import IO
|
3
|
-
|
4
|
-
|
5
|
-
class DualStream(StringIO):
|
6
|
-
def __init__(self, stream1: IO[str], stream2: StringIO):
|
7
|
-
super().__init__()
|
8
|
-
self.stream1 = stream1 # Usually sys.stdout
|
9
|
-
self.stream2 = stream2 # The StringIO stream
|
10
|
-
|
11
|
-
def write(self, s: str) -> int:
|
12
|
-
# Write to both streams and return the length of the written string
|
13
|
-
self.stream1.write(s)
|
14
|
-
self.stream2.write(s)
|
15
|
-
return len(s)
|
16
|
-
|
17
|
-
def flush(self) -> None:
|
18
|
-
self.stream1.flush()
|
19
|
-
self.stream2.flush()
|
20
|
-
|
21
|
-
def close(self) -> None:
|
22
|
-
# Do not close sys.stdout
|
23
|
-
self.stream2.close()
|
24
|
-
|
25
|
-
def readable(self) -> bool:
|
26
|
-
return False
|
27
|
-
|
28
|
-
def writable(self) -> bool:
|
29
|
-
return True
|
30
|
-
|
31
|
-
def seekable(self) -> bool:
|
32
|
-
return False
|
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.58 → code_loader-1.0.60.dev1}/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.58 → code_loader-1.0.60.dev1}/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.58 → code_loader-1.0.60.dev1}/code_loader/visualizers/default_visualizers.py
RENAMED
File without changes
|