code-loader 1.0.117rc0__py3-none-any.whl → 1.0.118.dev2__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.
Potentially problematic release.
This version of code-loader might be problematic. Click here for more details.
- code_loader/contract/datasetclasses.py +7 -0
- code_loader/inner_leap_binder/leapbinder.py +14 -1
- code_loader/inner_leap_binder/leapbinder_decorators.py +51 -7
- code_loader/leaploader.py +8 -2
- code_loader-1.0.118.dev2.dist-info/LICENSE +21 -0
- {code_loader-1.0.117rc0.dist-info → code_loader-1.0.118.dev2.dist-info}/METADATA +3 -3
- {code_loader-1.0.117rc0.dist-info → code_loader-1.0.118.dev2.dist-info}/RECORD +9 -8
- {code_loader-1.0.117rc0.dist-info → code_loader-1.0.118.dev2.dist-info}/WHEEL +1 -1
- /code_loader-1.0.117rc0.dist-info/LICENSE → /LICENSE +0 -0
|
@@ -212,6 +212,11 @@ class MetadataHandler:
|
|
|
212
212
|
metadata_type: Optional[Union[DatasetMetadataType, Dict[str, DatasetMetadataType]]] = None
|
|
213
213
|
|
|
214
214
|
|
|
215
|
+
@dataclass
|
|
216
|
+
class CustomLatentSpaceHandler:
|
|
217
|
+
function: SectionCallableInterface
|
|
218
|
+
name: str = 'custom_latent_space'
|
|
219
|
+
|
|
215
220
|
@dataclass
|
|
216
221
|
class PredictionTypeHandler:
|
|
217
222
|
name: str
|
|
@@ -241,6 +246,7 @@ class DatasetIntegrationSetup:
|
|
|
241
246
|
custom_loss_handlers: List[CustomLossHandler] = field(default_factory=list)
|
|
242
247
|
metrics: List[MetricHandler] = field(default_factory=list)
|
|
243
248
|
custom_layers: Dict[str, CustomLayerHandler] = field(default_factory=dict)
|
|
249
|
+
custom_latent_space: Optional[CustomLatentSpaceHandler] = None
|
|
244
250
|
|
|
245
251
|
|
|
246
252
|
@dataclass
|
|
@@ -252,4 +258,5 @@ class DatasetSample:
|
|
|
252
258
|
index: Union[int, str]
|
|
253
259
|
state: DataStateEnum
|
|
254
260
|
instance_masks: Optional[Dict[str, List[ElementInstance]]] = None
|
|
261
|
+
custom_latent_space: Optional[npt.NDArray[np.float32]] = None
|
|
255
262
|
|
|
@@ -11,7 +11,7 @@ from code_loader.contract.datasetclasses import SectionCallableInterface, InputH
|
|
|
11
11
|
CustomCallableInterfaceMultiArgs, ConfusionMatrixCallableInterfaceMultiArgs, LeapData, \
|
|
12
12
|
CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler, custom_latent_space_attribute, \
|
|
13
13
|
RawInputsForHeatmap, VisualizerHandlerData, MetricHandlerData, CustomLossHandlerData, SamplePreprocessResponse, \
|
|
14
|
-
ElementInstanceMasksHandler, InstanceCallableInterface
|
|
14
|
+
ElementInstanceMasksHandler, InstanceCallableInterface, CustomLatentSpaceHandler
|
|
15
15
|
from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType, MetricDirection, DatasetMetadataType
|
|
16
16
|
from code_loader.contract.mapping import NodeConnection, NodeMapping, NodeMappingType
|
|
17
17
|
from code_loader.contract.responsedataclasses import DatasetTestResultPayload
|
|
@@ -421,6 +421,19 @@ class LeapBinder:
|
|
|
421
421
|
"""
|
|
422
422
|
self.setup_container.metadata.append(MetadataHandler(name, function, metadata_type))
|
|
423
423
|
|
|
424
|
+
def set_custom_latent_space(self, function: SectionCallableInterface) -> None:
|
|
425
|
+
"""
|
|
426
|
+
Set a custom latent space function.
|
|
427
|
+
|
|
428
|
+
Args:
|
|
429
|
+
function (SectionCallableInterface): The metadata handler function.
|
|
430
|
+
This function receives:
|
|
431
|
+
subset (PreprocessResponse): The subset of the data.
|
|
432
|
+
index (int): The index of the sample within the subset.
|
|
433
|
+
This function should numpy float32 array contains the latent space vec of the sample.
|
|
434
|
+
"""
|
|
435
|
+
self.setup_container.custom_latent_space = CustomLatentSpaceHandler(function)
|
|
436
|
+
|
|
424
437
|
def set_custom_layer(self, custom_layer: Type[Any], name: str, inspect_layer: bool = False,
|
|
425
438
|
kernel_index: Optional[int] = None, use_custom_latent_space: bool = False) -> None:
|
|
426
439
|
"""
|
|
@@ -443,6 +443,55 @@ def tensorleap_metadata(
|
|
|
443
443
|
return decorating_function
|
|
444
444
|
|
|
445
445
|
|
|
446
|
+
|
|
447
|
+
def tensorleap_custom_latent_space():
|
|
448
|
+
def decorating_function(user_function: SectionCallableInterface):
|
|
449
|
+
def _validate_input_args(sample_id: Union[int, str], preprocess_response: PreprocessResponse):
|
|
450
|
+
assert isinstance(sample_id, (int, str)), \
|
|
451
|
+
(f'tensorleap_custom_latent_space validation failed: '
|
|
452
|
+
f'Argument sample_id should be either int or str. Got {type(sample_id)}.')
|
|
453
|
+
assert isinstance(preprocess_response, PreprocessResponse), \
|
|
454
|
+
(f'tensorleap_custom_latent_space validation failed: '
|
|
455
|
+
f'Argument preprocess_response should be a PreprocessResponse. Got {type(preprocess_response)}.')
|
|
456
|
+
assert type(sample_id) == preprocess_response.sample_id_type, \
|
|
457
|
+
(f'tensorleap_custom_latent_space validation failed: '
|
|
458
|
+
f'Argument sample_id should be as the same type as defined in the preprocess response '
|
|
459
|
+
f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
|
|
460
|
+
|
|
461
|
+
def _validate_result(result):
|
|
462
|
+
assert isinstance(result, np.ndarray), \
|
|
463
|
+
(f'tensorleap_custom_loss validation failed: '
|
|
464
|
+
f'The return type should be a numpy array. Got {type(result)}.')
|
|
465
|
+
|
|
466
|
+
def inner_without_validate(sample_id, preprocess_response):
|
|
467
|
+
global _called_from_inside_tl_decorator
|
|
468
|
+
_called_from_inside_tl_decorator += 1
|
|
469
|
+
|
|
470
|
+
try:
|
|
471
|
+
result = user_function(sample_id, preprocess_response)
|
|
472
|
+
finally:
|
|
473
|
+
_called_from_inside_tl_decorator -= 1
|
|
474
|
+
|
|
475
|
+
return result
|
|
476
|
+
|
|
477
|
+
leap_binder.set_custom_latent_space(inner_without_validate)
|
|
478
|
+
|
|
479
|
+
def inner(sample_id, preprocess_response):
|
|
480
|
+
if os.environ.get(mapping_runtime_mode_env_var_mame):
|
|
481
|
+
return None
|
|
482
|
+
|
|
483
|
+
_validate_input_args(sample_id, preprocess_response)
|
|
484
|
+
|
|
485
|
+
result = inner_without_validate(sample_id, preprocess_response)
|
|
486
|
+
|
|
487
|
+
_validate_result(result)
|
|
488
|
+
return result
|
|
489
|
+
|
|
490
|
+
return inner
|
|
491
|
+
|
|
492
|
+
return decorating_function
|
|
493
|
+
|
|
494
|
+
|
|
446
495
|
def tensorleap_preprocess():
|
|
447
496
|
def decorating_function(user_function: Callable[[], List[PreprocessResponse]]):
|
|
448
497
|
leap_binder.set_preprocess(user_function)
|
|
@@ -760,14 +809,8 @@ def tensorleap_custom_loss(name: str, connects_to=None):
|
|
|
760
809
|
f'Please choose another')
|
|
761
810
|
|
|
762
811
|
valid_types = (np.ndarray, SamplePreprocessResponse)
|
|
763
|
-
try:
|
|
764
|
-
import tensorflow as tf
|
|
765
|
-
valid_types = (np.ndarray, SamplePreprocessResponse, tf.Tensor)
|
|
766
|
-
except ImportError:
|
|
767
|
-
pass
|
|
768
812
|
|
|
769
813
|
def _validate_input_args(*args, **kwargs):
|
|
770
|
-
|
|
771
814
|
for i, arg in enumerate(args):
|
|
772
815
|
if isinstance(arg, list):
|
|
773
816
|
for y, elem in enumerate(arg):
|
|
@@ -786,10 +829,11 @@ def tensorleap_custom_loss(name: str, connects_to=None):
|
|
|
786
829
|
f'Argument #{_arg_name} should be a numpy array. Got {type(arg)}.')
|
|
787
830
|
|
|
788
831
|
def _validate_result(result):
|
|
789
|
-
assert isinstance(result,
|
|
832
|
+
assert isinstance(result, np.ndarray), \
|
|
790
833
|
(f'tensorleap_custom_loss validation failed: '
|
|
791
834
|
f'The return type should be a numpy array. Got {type(result)}.')
|
|
792
835
|
|
|
836
|
+
|
|
793
837
|
@functools.wraps(user_function)
|
|
794
838
|
def inner_without_validate(*args, **kwargs):
|
|
795
839
|
global _called_from_inside_tl_decorator
|
code_loader/leaploader.py
CHANGED
|
@@ -16,7 +16,7 @@ from code_loader.contract.datasetclasses import DatasetSample, DatasetBaseHandle
|
|
|
16
16
|
PreprocessResponse, VisualizerHandler, LeapData, \
|
|
17
17
|
PredictionTypeHandler, MetadataHandler, CustomLayerHandler, MetricHandler, VisualizerHandlerData, MetricHandlerData, \
|
|
18
18
|
MetricCallableReturnType, CustomLossHandlerData, CustomLossHandler, RawInputsForHeatmap, SamplePreprocessResponse, \
|
|
19
|
-
ElementInstance
|
|
19
|
+
ElementInstance, custom_latent_space_attribute
|
|
20
20
|
from code_loader.contract.enums import DataStateEnum, TestingSectionEnum, DataStateType, DatasetMetadataType
|
|
21
21
|
from code_loader.contract.exceptions import DatasetScriptException
|
|
22
22
|
from code_loader.contract.responsedataclasses import DatasetIntegParseResult, DatasetTestResultPayload, \
|
|
@@ -162,12 +162,18 @@ class LeapLoader(LeapLoaderBase):
|
|
|
162
162
|
self._preprocess_result(update_unlabeled_preprocess=True)
|
|
163
163
|
|
|
164
164
|
metadata, metadata_is_none = self._get_metadata(state, sample_id)
|
|
165
|
+
|
|
166
|
+
custom_latent_space = None
|
|
167
|
+
if global_leap_binder.setup_container.custom_latent_space is not None:
|
|
168
|
+
custom_latent_space = global_leap_binder.setup_container.custom_latent_space.function(sample_id, preprocess_result[state])
|
|
169
|
+
|
|
165
170
|
sample = DatasetSample(inputs=self._get_inputs(state, sample_id),
|
|
166
171
|
gt=None if state == DataStateEnum.unlabeled else self._get_gt(state, sample_id),
|
|
167
172
|
metadata=metadata,
|
|
168
173
|
metadata_is_none=metadata_is_none,
|
|
169
174
|
index=sample_id,
|
|
170
|
-
state=state
|
|
175
|
+
state=state,
|
|
176
|
+
custom_latent_space=custom_latent_space)
|
|
171
177
|
return sample
|
|
172
178
|
|
|
173
179
|
def get_sample_with_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> DatasetSample:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 TensorLeap
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: code-loader
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.118.dev2
|
|
4
4
|
Summary:
|
|
5
|
+
Home-page: https://github.com/tensorleap/code-loader
|
|
5
6
|
License: MIT
|
|
6
7
|
Author: dorhar
|
|
7
8
|
Author-email: doron.harnoy@tensorleap.ai
|
|
@@ -19,7 +20,6 @@ Requires-Dist: numpy (>=2.3.2,<3.0.0) ; python_version >= "3.11" and python_vers
|
|
|
19
20
|
Requires-Dist: psutil (>=5.9.5,<6.0.0)
|
|
20
21
|
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
|
21
22
|
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
22
|
-
Project-URL: Homepage, https://github.com/tensorleap/code-loader
|
|
23
23
|
Project-URL: Repository, https://github.com/tensorleap/code-loader
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
|
1
2
|
code_loader/__init__.py,sha256=outxRQ0M-zMfV0QGVJmAed5qWfRmyD0TV6-goEGAzBw,406
|
|
2
3
|
code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
code_loader/contract/datasetclasses.py,sha256=
|
|
4
|
+
code_loader/contract/datasetclasses.py,sha256=dzEzQY5F-uTNB28omGcdZp4cIXWn7NJhNyL0_Y04Yyo,9092
|
|
4
5
|
code_loader/contract/enums.py,sha256=GEFkvUMXnCNt-GOoz7NJ9ecQZ2PPDettJNOsxsiM0wk,1622
|
|
5
6
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
|
6
7
|
code_loader/contract/mapping.py,sha256=e11h_sprwOyE32PcqgRq9JvyahQrPzwqgkhmbQLKLQY,1165
|
|
@@ -19,9 +20,9 @@ code_loader/experiment_api/types.py,sha256=MY8xFARHwdVA7p4dxyhD60ShmttgTvb4qdp1o
|
|
|
19
20
|
code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZJEqBqc,3304
|
|
20
21
|
code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
|
|
21
22
|
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
|
22
|
-
code_loader/inner_leap_binder/leapbinder.py,sha256=
|
|
23
|
-
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=
|
|
24
|
-
code_loader/leaploader.py,sha256=
|
|
23
|
+
code_loader/inner_leap_binder/leapbinder.py,sha256=Q3D9yVM-GNEJfYRFvMV__BoZbcWOgnWKhrZXAv6Tu7o,33232
|
|
24
|
+
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=QpM0gx8ZplGp2XykZXBk0QBh2_5fqW9cgLNOoM4Sacs,42948
|
|
25
|
+
code_loader/leaploader.py,sha256=xym-Pl8nT_iV-1cA5iXr-BZbqAhYOu-vbcwyv3nSCa4,30063
|
|
25
26
|
code_loader/leaploaderbase.py,sha256=lKdw2pd6H9hFsxVmc7jJMoZd_vlG5He1ooqT-cR_yq8,4496
|
|
26
27
|
code_loader/mixpanel_tracker.py,sha256=U20vQXH8G7XIVXxcpQcVEZSuIwwGnyH5RMHXWZZG8HI,4639
|
|
27
28
|
code_loader/plot_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -30,7 +31,7 @@ code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6Lz
|
|
|
30
31
|
code_loader/utils.py,sha256=_j8b60pimoNAvWMRj7hEkkT6C76qES6cZoBFHpXHMxA,2698
|
|
31
32
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
33
|
code_loader/visualizers/default_visualizers.py,sha256=onRnLE_TXfgLN4o52hQIOOhUcFexGlqJ3xSpQDVLuZM,2604
|
|
33
|
-
code_loader-1.0.
|
|
34
|
-
code_loader-1.0.
|
|
35
|
-
code_loader-1.0.
|
|
36
|
-
code_loader-1.0.
|
|
34
|
+
code_loader-1.0.118.dev2.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
|
35
|
+
code_loader-1.0.118.dev2.dist-info/METADATA,sha256=DPZQTmlglWeE5wDy7VPnOjgpoqWa_YpmUTsFT5_MWzA,1095
|
|
36
|
+
code_loader-1.0.118.dev2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
37
|
+
code_loader-1.0.118.dev2.dist-info/RECORD,,
|
|
File without changes
|