code-loader 1.0.112.dev6__py3-none-any.whl → 1.0.153.dev4__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/__init__.py +6 -0
- code_loader/contract/datasetclasses.py +27 -4
- code_loader/contract/mapping.py +11 -0
- code_loader/inner_leap_binder/leapbinder.py +14 -1
- code_loader/inner_leap_binder/leapbinder_decorators.py +993 -142
- code_loader/leaploader.py +53 -25
- code_loader/leaploaderbase.py +30 -5
- code_loader/mixpanel_tracker.py +230 -0
- code_loader/plot_functions/plot_functions.py +1 -2
- code_loader/utils.py +1 -1
- {code_loader-1.0.112.dev6.dist-info → code_loader-1.0.153.dev4.dist-info}/METADATA +4 -2
- {code_loader-1.0.112.dev6.dist-info → code_loader-1.0.153.dev4.dist-info}/RECORD +14 -13
- {code_loader-1.0.112.dev6.dist-info → code_loader-1.0.153.dev4.dist-info}/LICENSE +0 -0
- {code_loader-1.0.112.dev6.dist-info → code_loader-1.0.153.dev4.dist-info}/WHEEL +0 -0
code_loader/__init__.py
CHANGED
|
@@ -2,3 +2,9 @@ from code_loader.leaploader import LeapLoader
|
|
|
2
2
|
from code_loader.inner_leap_binder import global_leap_binder as leap_binder
|
|
3
3
|
from code_loader.experiment_api.experiment import init_experiment
|
|
4
4
|
from code_loader.experiment_api.client import Client
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from code_loader.mixpanel_tracker import track_code_loader_loaded
|
|
8
|
+
track_code_loader_loaded({'event_type': 'module_import'})
|
|
9
|
+
except Exception:
|
|
10
|
+
pass
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import warnings
|
|
1
2
|
from dataclasses import dataclass, field
|
|
2
|
-
from typing import Any, Callable, List, Optional, Dict, Union, Type
|
|
3
|
+
from typing import Any, Callable, List, Optional, Dict, Union, Type, Literal
|
|
3
4
|
import re
|
|
4
5
|
import numpy as np
|
|
5
6
|
import numpy.typing as npt
|
|
@@ -56,7 +57,19 @@ class PreprocessResponse:
|
|
|
56
57
|
for sample_id in self.sample_ids:
|
|
57
58
|
assert isinstance(sample_id, str), f"Sample id should be of type str. Got: {type(sample_id)}"
|
|
58
59
|
else:
|
|
59
|
-
raise Exception("length is deprecated.")
|
|
60
|
+
raise Exception("length is deprecated, please use sample_ids instead.")
|
|
61
|
+
|
|
62
|
+
if self.state is None:
|
|
63
|
+
from code_loader.inner_leap_binder.leapbinder_decorators import store_warning_by_param
|
|
64
|
+
store_warning_by_param(
|
|
65
|
+
param_name="PreprocessResponse.state",
|
|
66
|
+
user_func_name="tensorleap_preprocess",
|
|
67
|
+
default_value=str("specific order"),
|
|
68
|
+
link_to_docs="https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/preprocess-function",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
else:
|
|
72
|
+
assert isinstance(self.state, DataStateType), f"PreprocessResponse.state must be of type {DataStateType.__name__} but got {type(self.state)}"
|
|
60
73
|
|
|
61
74
|
def __hash__(self) -> int:
|
|
62
75
|
return id(self)
|
|
@@ -69,9 +82,11 @@ class PreprocessResponse:
|
|
|
69
82
|
class ElementInstance:
|
|
70
83
|
name: str
|
|
71
84
|
mask: npt.NDArray[np.float32]
|
|
85
|
+
instance_metadata: Dict[str, Union[Optional[str], int, bool, Optional[float]]]
|
|
86
|
+
|
|
72
87
|
|
|
73
88
|
SectionCallableInterface = Callable[[Union[int, str], PreprocessResponse], npt.NDArray[np.float32]]
|
|
74
|
-
InstanceCallableInterface = Callable[[Union[int, str], PreprocessResponse,
|
|
89
|
+
InstanceCallableInterface = Callable[[Union[int, str], PreprocessResponse, int], Optional[ElementInstance]]
|
|
75
90
|
InstanceLengthCallableInterface = Callable[[Union[int, str], PreprocessResponse], int]
|
|
76
91
|
|
|
77
92
|
|
|
@@ -212,11 +227,17 @@ class MetadataHandler:
|
|
|
212
227
|
metadata_type: Optional[Union[DatasetMetadataType, Dict[str, DatasetMetadataType]]] = None
|
|
213
228
|
|
|
214
229
|
|
|
230
|
+
@dataclass
|
|
231
|
+
class CustomLatentSpaceHandler:
|
|
232
|
+
function: SectionCallableInterface
|
|
233
|
+
name: str = 'custom_latent_space'
|
|
234
|
+
|
|
215
235
|
@dataclass
|
|
216
236
|
class PredictionTypeHandler:
|
|
217
237
|
name: str
|
|
218
238
|
labels: List[str]
|
|
219
|
-
channel_dim: int =
|
|
239
|
+
channel_dim: Union[int, Literal["tl_default_value"]]= "tl_default_value"
|
|
240
|
+
|
|
220
241
|
|
|
221
242
|
|
|
222
243
|
@dataclass
|
|
@@ -241,6 +262,7 @@ class DatasetIntegrationSetup:
|
|
|
241
262
|
custom_loss_handlers: List[CustomLossHandler] = field(default_factory=list)
|
|
242
263
|
metrics: List[MetricHandler] = field(default_factory=list)
|
|
243
264
|
custom_layers: Dict[str, CustomLayerHandler] = field(default_factory=dict)
|
|
265
|
+
custom_latent_space: Optional[CustomLatentSpaceHandler] = None
|
|
244
266
|
|
|
245
267
|
|
|
246
268
|
@dataclass
|
|
@@ -251,5 +273,6 @@ class DatasetSample:
|
|
|
251
273
|
metadata_is_none: Dict[str, bool]
|
|
252
274
|
index: Union[int, str]
|
|
253
275
|
state: DataStateEnum
|
|
276
|
+
custom_latent_space: Optional[npt.NDArray[np.float32]] = None
|
|
254
277
|
instance_masks: Optional[Dict[str, ElementInstance]] = None
|
|
255
278
|
|
code_loader/contract/mapping.py
CHANGED
|
@@ -21,12 +21,22 @@ class NodeMappingType(Enum):
|
|
|
21
21
|
Prediction1 = 'Prediction1'
|
|
22
22
|
Prediction2 = 'Prediction2'
|
|
23
23
|
Prediction3 = 'Prediction3'
|
|
24
|
+
Prediction4 = 'Prediction4'
|
|
25
|
+
Prediction5 = 'Prediction5'
|
|
26
|
+
Prediction6 = 'Prediction6'
|
|
27
|
+
Prediction7 = 'Prediction7'
|
|
28
|
+
Prediction8 = 'Prediction8'
|
|
29
|
+
Prediction9 = 'Prediction9'
|
|
24
30
|
Input0 = 'Input0'
|
|
25
31
|
Input1 = 'Input1'
|
|
26
32
|
Input2 = 'Input2'
|
|
27
33
|
Input3 = 'Input3'
|
|
28
34
|
Input4 = 'Input4'
|
|
29
35
|
Input5 = 'Input5'
|
|
36
|
+
Input6 = 'Input6'
|
|
37
|
+
Input7 = 'Input7'
|
|
38
|
+
Input8 = 'Input8'
|
|
39
|
+
Input9 = 'Input9'
|
|
30
40
|
PredictionLabels = 'PredictionLabels'
|
|
31
41
|
|
|
32
42
|
|
|
@@ -39,6 +49,7 @@ class NodeMapping:
|
|
|
39
49
|
arg_names: Optional[List[str]] = None
|
|
40
50
|
|
|
41
51
|
|
|
52
|
+
|
|
42
53
|
@dataclass
|
|
43
54
|
class NodeConnection:
|
|
44
55
|
node: NodeMapping
|
|
@@ -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
|
"""
|