code-loader 1.0.117__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/contract/datasetclasses.py +30 -7
- code_loader/contract/mapping.py +11 -0
- code_loader/inner_leap_binder/leapbinder.py +14 -1
- code_loader/inner_leap_binder/leapbinder_decorators.py +1046 -146
- code_loader/leaploader.py +47 -29
- code_loader/leaploaderbase.py +30 -5
- code_loader/mixpanel_tracker.py +106 -10
- code_loader/plot_functions/plot_functions.py +1 -2
- code_loader/utils.py +6 -6
- code_loader-1.0.153.dev4.dist-info/LICENSE +21 -0
- {code_loader-1.0.117.dist-info → code_loader-1.0.153.dev4.dist-info}/METADATA +3 -3
- {code_loader-1.0.117.dist-info → code_loader-1.0.153.dev4.dist-info}/RECORD +14 -13
- {code_loader-1.0.117.dist-info → code_loader-1.0.153.dev4.dist-info}/WHEEL +1 -1
- /code_loader-1.0.117.dist-info/LICENSE → /LICENSE +0 -0
|
@@ -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
|
|
@@ -40,12 +41,10 @@ class PreprocessResponse:
|
|
|
40
41
|
sample_id_type: Optional[Union[Type[str], Type[int]]] = None
|
|
41
42
|
sample_ids_to_instance_mappings: Optional[Dict[str, List[str]]] = None # in use only for element instance
|
|
42
43
|
instance_to_sample_ids_mappings: Optional[Dict[str, str]] = None # in use only for element instance
|
|
43
|
-
instance_ids_to_names: Optional[Dict[str, str]] = None # in use only for element instance
|
|
44
44
|
|
|
45
45
|
def __post_init__(self) -> None:
|
|
46
46
|
assert self.sample_ids_to_instance_mappings is None, f"Keep sample_ids_to_instance_mappings None when initializing PreprocessResponse"
|
|
47
47
|
assert self.instance_to_sample_ids_mappings is None, f"Keep instance_to_sample_ids_mappings None when initializing PreprocessResponse"
|
|
48
|
-
assert self.instance_ids_to_names is None, f"Keep instance_ids_to_names None when initializing PreprocessResponse"
|
|
49
48
|
|
|
50
49
|
if self.length is not None and self.sample_ids is None:
|
|
51
50
|
self.sample_ids = [i for i in range(self.length)]
|
|
@@ -58,7 +57,19 @@ class PreprocessResponse:
|
|
|
58
57
|
for sample_id in self.sample_ids:
|
|
59
58
|
assert isinstance(sample_id, str), f"Sample id should be of type str. Got: {type(sample_id)}"
|
|
60
59
|
else:
|
|
61
|
-
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)}"
|
|
62
73
|
|
|
63
74
|
def __hash__(self) -> int:
|
|
64
75
|
return id(self)
|
|
@@ -71,9 +82,13 @@ class PreprocessResponse:
|
|
|
71
82
|
class ElementInstance:
|
|
72
83
|
name: str
|
|
73
84
|
mask: npt.NDArray[np.float32]
|
|
85
|
+
instance_metadata: Dict[str, Union[Optional[str], int, bool, Optional[float]]]
|
|
86
|
+
|
|
74
87
|
|
|
75
88
|
SectionCallableInterface = Callable[[Union[int, str], PreprocessResponse], npt.NDArray[np.float32]]
|
|
76
|
-
InstanceCallableInterface = Callable[[Union[int, str], PreprocessResponse],
|
|
89
|
+
InstanceCallableInterface = Callable[[Union[int, str], PreprocessResponse, int], Optional[ElementInstance]]
|
|
90
|
+
InstanceLengthCallableInterface = Callable[[Union[int, str], PreprocessResponse], int]
|
|
91
|
+
|
|
77
92
|
|
|
78
93
|
MetadataSectionCallableInterface = Union[
|
|
79
94
|
Callable[[Union[int, str], PreprocessResponse], int],
|
|
@@ -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
|
|
254
|
-
|
|
276
|
+
custom_latent_space: Optional[npt.NDArray[np.float32]] = None
|
|
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
|
"""
|