code-loader 1.0.42__py3-none-any.whl → 1.0.42a0__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 +19 -1
- code_loader/contract/enums.py +6 -0
- code_loader/inner_leap_binder/leapbinder.py +9 -3
- code_loader/leaploader.py +15 -3
- {code_loader-1.0.42.dist-info → code_loader-1.0.42a0.dist-info}/METADATA +1 -1
- {code_loader-1.0.42.dist-info → code_loader-1.0.42a0.dist-info}/RECORD +8 -8
- {code_loader-1.0.42.dist-info → code_loader-1.0.42a0.dist-info}/LICENSE +0 -0
- {code_loader-1.0.42.dist-info → code_loader-1.0.42a0.dist-info}/WHEEL +0 -0
@@ -4,7 +4,7 @@ from typing import Any, Callable, List, Optional, Dict, Union, Type
|
|
4
4
|
import numpy as np
|
5
5
|
import numpy.typing as npt
|
6
6
|
|
7
|
-
from code_loader.contract.enums import DataStateType, DataStateEnum, LeapDataType, ConfusionMatrixValue, MetricDirection
|
7
|
+
from code_loader.contract.enums import DataStateType, DataStateEnum, LeapDataType, ConfusionMatrixValue, MetricDirection, InstanceAnalysisType
|
8
8
|
from code_loader.contract.visualizer_classes import LeapImage, LeapText, LeapGraph, LeapHorizontalBar, \
|
9
9
|
LeapTextMask, LeapImageMask, LeapImageWithBBox, LeapImageWithHeatmap
|
10
10
|
|
@@ -36,8 +36,16 @@ class PreprocessResponse:
|
|
36
36
|
data: Any
|
37
37
|
|
38
38
|
|
39
|
+
@dataclass
|
40
|
+
class ElementInstance:
|
41
|
+
name: str
|
42
|
+
mask: npt.NDArray[np.float32]
|
43
|
+
|
44
|
+
|
39
45
|
SectionCallableInterface = Callable[[int, PreprocessResponse], npt.NDArray[np.float32]]
|
40
46
|
|
47
|
+
InstanceCallableInterface = Callable[[int, PreprocessResponse], List[ElementInstance]]
|
48
|
+
|
41
49
|
MetadataSectionCallableInterface = Union[
|
42
50
|
Callable[[int, PreprocessResponse], int],
|
43
51
|
Callable[[int, PreprocessResponse], Dict[str, int]],
|
@@ -109,6 +117,7 @@ class MetricHandler:
|
|
109
117
|
arg_names: List[str]
|
110
118
|
direction: Optional[MetricDirection] = MetricDirection.Downward
|
111
119
|
|
120
|
+
|
112
121
|
@dataclass
|
113
122
|
class RawInputsForHeatmap:
|
114
123
|
raw_input_by_vizualizer_arg_name: Dict[str, npt.NDArray[np.float32]]
|
@@ -134,6 +143,14 @@ class InputHandler(DatasetBaseHandler):
|
|
134
143
|
shape: Optional[List[int]] = None
|
135
144
|
|
136
145
|
|
146
|
+
@dataclass
|
147
|
+
class ElementInstanceHandler:
|
148
|
+
input_name: str
|
149
|
+
instance_function: InstanceCallableInterface
|
150
|
+
analysis_type: InstanceAnalysisType
|
151
|
+
|
152
|
+
|
153
|
+
|
137
154
|
@dataclass
|
138
155
|
class GroundTruthHandler(DatasetBaseHandler):
|
139
156
|
shape: Optional[List[int]] = None
|
@@ -167,6 +184,7 @@ class DatasetIntegrationSetup:
|
|
167
184
|
unlabeled_data_preprocess: Optional[UnlabeledDataPreprocessHandler] = None
|
168
185
|
visualizers: List[VisualizerHandler] = field(default_factory=list)
|
169
186
|
inputs: List[InputHandler] = field(default_factory=list)
|
187
|
+
element_instances: List[ElementInstanceHandler] = field(default_factory=list)
|
170
188
|
ground_truths: List[GroundTruthHandler] = field(default_factory=list)
|
171
189
|
metadata: List[MetadataHandler] = field(default_factory=list)
|
172
190
|
prediction_types: List[PredictionTypeHandler] = field(default_factory=list)
|
code_loader/contract/enums.py
CHANGED
@@ -9,8 +9,9 @@ from code_loader.contract.datasetclasses import SectionCallableInterface, InputH
|
|
9
9
|
PreprocessHandler, VisualizerCallableInterface, CustomLossHandler, CustomCallableInterface, PredictionTypeHandler, \
|
10
10
|
MetadataSectionCallableInterface, UnlabeledDataPreprocessHandler, CustomLayerHandler, MetricHandler, \
|
11
11
|
CustomCallableInterfaceMultiArgs, ConfusionMatrixCallableInterfaceMultiArgs, VisualizerCallableReturnType, \
|
12
|
-
CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler, custom_latent_space_attribute,
|
13
|
-
|
12
|
+
CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler, custom_latent_space_attribute, \
|
13
|
+
RawInputsForHeatmap, InstanceCallableInterface, ElementInstanceHandler
|
14
|
+
from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType, MetricDirection, InstanceAnalysisType
|
14
15
|
from code_loader.contract.responsedataclasses import DatasetTestResultPayload
|
15
16
|
from code_loader.contract.visualizer_classes import map_leap_data_type_to_visualizer_class
|
16
17
|
from code_loader.utils import to_numpy_return_wrapper, get_shape
|
@@ -202,6 +203,10 @@ class LeapBinder:
|
|
202
203
|
|
203
204
|
self._encoder_names.append(name)
|
204
205
|
|
206
|
+
def set_instance_element(self, input_name: str, instance_function: Optional[InstanceCallableInterface] = None,
|
207
|
+
analysis_type: InstanceAnalysisType = InstanceAnalysisType.MaskInput) -> None:
|
208
|
+
self.setup_container.element_instances.append(ElementInstanceHandler(input_name, instance_function, analysis_type))
|
209
|
+
|
205
210
|
def add_custom_loss(self, function: CustomCallableInterface, name: str) -> None:
|
206
211
|
"""
|
207
212
|
Add a custom loss function to the setup.
|
@@ -361,7 +366,8 @@ class LeapBinder:
|
|
361
366
|
custom_layer.kernel_index = kernel_index
|
362
367
|
|
363
368
|
if use_custom_latent_space and not hasattr(custom_layer, custom_latent_space_attribute):
|
364
|
-
raise Exception(
|
369
|
+
raise Exception(
|
370
|
+
f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
|
365
371
|
|
366
372
|
init_args = inspect.getfullargspec(custom_layer.__init__)[0][1:]
|
367
373
|
call_args = inspect.getfullargspec(custom_layer.call)[0][1:]
|
code_loader/leaploader.py
CHANGED
@@ -5,15 +5,16 @@ import sys
|
|
5
5
|
from contextlib import redirect_stdout
|
6
6
|
from functools import lru_cache
|
7
7
|
from pathlib import Path
|
8
|
-
from typing import Dict, List, Iterable, Union, Any
|
8
|
+
from typing import Dict, List, Iterable, Union, Any, Optional, Tuple
|
9
9
|
|
10
10
|
import numpy as np
|
11
11
|
import numpy.typing as npt
|
12
12
|
|
13
13
|
from code_loader.contract.datasetclasses import DatasetSample, DatasetBaseHandler, GroundTruthHandler, \
|
14
14
|
PreprocessResponse, VisualizerHandler, VisualizerCallableReturnType, CustomLossHandler, \
|
15
|
-
PredictionTypeHandler, MetadataHandler, CustomLayerHandler, MetricHandler
|
16
|
-
from code_loader.contract.enums import DataStateEnum, TestingSectionEnum, DataStateType, DatasetMetadataType
|
15
|
+
PredictionTypeHandler, MetadataHandler, CustomLayerHandler, MetricHandler, ElementInstance
|
16
|
+
from code_loader.contract.enums import DataStateEnum, TestingSectionEnum, DataStateType, DatasetMetadataType, \
|
17
|
+
InstanceAnalysisType
|
17
18
|
from code_loader.contract.exceptions import DatasetScriptException
|
18
19
|
from code_loader.contract.responsedataclasses import DatasetIntegParseResult, DatasetTestResultPayload, \
|
19
20
|
DatasetPreprocess, DatasetSetup, DatasetInputInstance, DatasetOutputInstance, DatasetMetadataInstance, \
|
@@ -298,6 +299,17 @@ class LeapLoader:
|
|
298
299
|
def _get_inputs(self, state: DataStateEnum, idx: int) -> Dict[str, npt.NDArray[np.float32]]:
|
299
300
|
return self._get_dataset_handlers(global_leap_binder.setup_container.inputs, state, idx)
|
300
301
|
|
302
|
+
def get_instance_elements(self, state: DataStateEnum, idx: int, input_name: str) \
|
303
|
+
-> Tuple[Optional[List[ElementInstance]], Optional[InstanceAnalysisType]]:
|
304
|
+
preprocess_result = self._preprocess_result()
|
305
|
+
preprocess_state = preprocess_result[state]
|
306
|
+
for element_instance in global_leap_binder.setup_container.element_instances:
|
307
|
+
if element_instance.input_name == input_name:
|
308
|
+
return element_instance.instance_function(idx, preprocess_state), element_instance.analysis_type
|
309
|
+
|
310
|
+
return None, None
|
311
|
+
|
312
|
+
|
301
313
|
def _get_gt(self, state: DataStateEnum, idx: int) -> Dict[str, npt.NDArray[np.float32]]:
|
302
314
|
return self._get_dataset_handlers(global_leap_binder.setup_container.ground_truths, state, idx)
|
303
315
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
2
2
|
code_loader/__init__.py,sha256=V3DEXSN6Ie6PlGeSAbzjp9ufRj0XPJLpD7pDLLYxk6M,122
|
3
3
|
code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
code_loader/contract/datasetclasses.py,sha256=
|
5
|
-
code_loader/contract/enums.py,sha256=
|
4
|
+
code_loader/contract/datasetclasses.py,sha256=eoDxCGZzvogp440dhWZBBm8oTs6XiqcHxE-JXD4txeA,6128
|
5
|
+
code_loader/contract/enums.py,sha256=2tKXamabooQjCe3EBkeBcZMA8vBbeGjDAbACvUTGqLE,1707
|
6
6
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
7
7
|
code_loader/contract/responsedataclasses.py,sha256=w7xVOv2S8Hyb5lqyomMGiKAWXDTSOG-FX1YW39bXD3A,3969
|
8
8
|
code_loader/contract/visualizer_classes.py,sha256=t0EKxTGFJoFBnKuMmjtFpj-L32xEFF3NV-E5XutVXa0,10118
|
9
9
|
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
10
|
-
code_loader/inner_leap_binder/leapbinder.py,sha256=
|
11
|
-
code_loader/leaploader.py,sha256=
|
10
|
+
code_loader/inner_leap_binder/leapbinder.py,sha256=7_ffUiGW54Y27f7eKnvpJ2XLOqfGfTCW5cMNaH21iIk,24464
|
11
|
+
code_loader/leaploader.py,sha256=gQaEpHyQx50FP-d0LS2PjQdm9aOUf3jok8ZeLbWkGZc,17917
|
12
12
|
code_loader/utils.py,sha256=61I4PgSl-ZBIe4DifLxMNlBELE-HQR2pB9efVYPceIU,2230
|
13
13
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
code_loader/visualizers/default_visualizers.py,sha256=F2qRT6rNy7SOmr4QfqVxIkLlYEa00CwDkLJuA45lfSI,2254
|
15
|
-
code_loader-1.0.
|
16
|
-
code_loader-1.0.
|
17
|
-
code_loader-1.0.
|
18
|
-
code_loader-1.0.
|
15
|
+
code_loader-1.0.42a0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
16
|
+
code_loader-1.0.42a0.dist-info/METADATA,sha256=HrRgFfW68Nr0KIBzK-C9Fwnxcw9SYotWTzWfwW2PF4I,770
|
17
|
+
code_loader-1.0.42a0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
18
|
+
code_loader-1.0.42a0.dist-info/RECORD,,
|
File without changes
|
File without changes
|