code-loader 1.0.39__py3-none-any.whl → 1.0.40a1__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 +22 -5
- code_loader/contract/enums.py +6 -1
- code_loader/contract/visualizer_classes.py +1 -23
- code_loader/inner_leap_binder/leapbinder.py +9 -3
- code_loader/leaploader.py +13 -2
- code_loader/visualizers/default_visualizers.py +1 -2
- {code_loader-1.0.39.dist-info → code_loader-1.0.40a1.dist-info}/METADATA +1 -1
- code_loader-1.0.40a1.dist-info/RECORD +18 -0
- {code_loader-1.0.39.dist-info → code_loader-1.0.40a1.dist-info}/WHEEL +1 -1
- code_loader-1.0.39.dist-info/RECORD +0 -18
- {code_loader-1.0.39.dist-info → code_loader-1.0.40a1.dist-info}/LICENSE +0 -0
@@ -4,9 +4,9 @@ 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
|
-
LeapTextMask, LeapImageMask, LeapImageWithBBox
|
9
|
+
LeapTextMask, LeapImageMask, LeapImageWithBBox
|
10
10
|
|
11
11
|
custom_latent_space_attribute = "custom_latent_space"
|
12
12
|
|
@@ -17,8 +17,16 @@ class PreprocessResponse:
|
|
17
17
|
data: Any
|
18
18
|
|
19
19
|
|
20
|
+
@dataclass
|
21
|
+
class ElementInstance:
|
22
|
+
name: str
|
23
|
+
mask: npt.NDArray[np.float32]
|
24
|
+
|
25
|
+
|
20
26
|
SectionCallableInterface = Callable[[int, PreprocessResponse], npt.NDArray[np.float32]]
|
21
27
|
|
28
|
+
InstanceCallableInterface = Callable[[int, PreprocessResponse], List[ElementInstance]]
|
29
|
+
|
22
30
|
MetadataSectionCallableInterface = Union[
|
23
31
|
Callable[[int, PreprocessResponse], int],
|
24
32
|
Callable[[int, PreprocessResponse], Dict[str, int]],
|
@@ -50,12 +58,11 @@ VisualizerCallableInterface = Union[
|
|
50
58
|
Callable[..., LeapHorizontalBar],
|
51
59
|
Callable[..., LeapImageMask],
|
52
60
|
Callable[..., LeapTextMask],
|
53
|
-
Callable[..., LeapImageWithBBox]
|
54
|
-
Callable[..., LeapImageWithHeatmap]
|
61
|
+
Callable[..., LeapImageWithBBox]
|
55
62
|
]
|
56
63
|
|
57
64
|
VisualizerCallableReturnType = Union[LeapImage, LeapText, LeapGraph, LeapHorizontalBar,
|
58
|
-
LeapImageMask, LeapTextMask, LeapImageWithBBox
|
65
|
+
LeapImageMask, LeapTextMask, LeapImageWithBBox]
|
59
66
|
|
60
67
|
CustomCallableInterface = Callable[..., Any]
|
61
68
|
|
@@ -90,6 +97,7 @@ class MetricHandler:
|
|
90
97
|
arg_names: List[str]
|
91
98
|
direction: Optional[MetricDirection] = MetricDirection.Downward
|
92
99
|
|
100
|
+
|
93
101
|
@dataclass
|
94
102
|
class RawInputsForHeatmap:
|
95
103
|
raw_input_by_vizualizer_arg_name: Dict[str, npt.NDArray[np.float32]]
|
@@ -115,6 +123,14 @@ class InputHandler(DatasetBaseHandler):
|
|
115
123
|
shape: Optional[List[int]] = None
|
116
124
|
|
117
125
|
|
126
|
+
@dataclass
|
127
|
+
class ElementInstanceHandler:
|
128
|
+
input_name: str
|
129
|
+
instance_function: InstanceCallableInterface
|
130
|
+
analysis_type: InstanceAnalysisType
|
131
|
+
|
132
|
+
|
133
|
+
|
118
134
|
@dataclass
|
119
135
|
class GroundTruthHandler(DatasetBaseHandler):
|
120
136
|
shape: Optional[List[int]] = None
|
@@ -148,6 +164,7 @@ class DatasetIntegrationSetup:
|
|
148
164
|
unlabeled_data_preprocess: Optional[UnlabeledDataPreprocessHandler] = None
|
149
165
|
visualizers: List[VisualizerHandler] = field(default_factory=list)
|
150
166
|
inputs: List[InputHandler] = field(default_factory=list)
|
167
|
+
element_instances: List[ElementInstanceHandler] = field(default_factory=list)
|
151
168
|
ground_truths: List[GroundTruthHandler] = field(default_factory=list)
|
152
169
|
metadata: List[MetadataHandler] = field(default_factory=list)
|
153
170
|
prediction_types: List[PredictionTypeHandler] = field(default_factory=list)
|
code_loader/contract/enums.py
CHANGED
@@ -26,7 +26,6 @@ class LeapDataType(Enum):
|
|
26
26
|
ImageMask = 'ImageMask'
|
27
27
|
TextMask = 'TextMask'
|
28
28
|
ImageWithBBox = 'ImageWithBBox'
|
29
|
-
ImageWithHeatmap = 'ImageWithHeatmap'
|
30
29
|
|
31
30
|
|
32
31
|
class MetricDirection(Enum):
|
@@ -64,3 +63,9 @@ class ConfusionMatrixValue(Enum):
|
|
64
63
|
class TestingSectionEnum(Enum):
|
65
64
|
Warnings = "Warnings"
|
66
65
|
Errors = "Errors"
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
class InstanceAnalysisType(Enum):
|
70
|
+
MaskInput = "MaskInput"
|
71
|
+
MaskLatentSpace = "MaskLatentSpace"
|
@@ -135,27 +135,6 @@ class LeapTextMask:
|
|
135
135
|
validate_type(type(label), str)
|
136
136
|
|
137
137
|
|
138
|
-
@dataclass
|
139
|
-
class LeapImageWithHeatmap:
|
140
|
-
image: npt.NDArray[np.float32]
|
141
|
-
heatmaps: npt.NDArray[np.float32]
|
142
|
-
labels: List[str]
|
143
|
-
type: LeapDataType = LeapDataType.ImageWithHeatmap
|
144
|
-
|
145
|
-
def __post_init__(self) -> None:
|
146
|
-
validate_type(self.type, LeapDataType.ImageWithHeatmap)
|
147
|
-
validate_type(type(self.heatmaps), np.ndarray)
|
148
|
-
validate_type(self.heatmaps.dtype, np.float32)
|
149
|
-
validate_type(type(self.image), np.ndarray)
|
150
|
-
validate_type(self.image.dtype, np.float32)
|
151
|
-
validate_type(type(self.labels), list)
|
152
|
-
for label in self.labels:
|
153
|
-
validate_type(type(label), str)
|
154
|
-
if self.heatmaps.shape[0] != len(self.labels):
|
155
|
-
raise LeapValidationError(
|
156
|
-
'Number of heatmaps and labels must be equal')
|
157
|
-
|
158
|
-
|
159
138
|
map_leap_data_type_to_visualizer_class = {
|
160
139
|
LeapDataType.Image.value: LeapImage,
|
161
140
|
LeapDataType.Graph.value: LeapGraph,
|
@@ -163,6 +142,5 @@ map_leap_data_type_to_visualizer_class = {
|
|
163
142
|
LeapDataType.HorizontalBar.value: LeapHorizontalBar,
|
164
143
|
LeapDataType.ImageMask.value: LeapImageMask,
|
165
144
|
LeapDataType.TextMask.value: LeapTextMask,
|
166
|
-
LeapDataType.ImageWithBBox.value: LeapImageWithBBox
|
167
|
-
LeapDataType.ImageWithHeatmap.value: LeapImageWithHeatmap
|
145
|
+
LeapDataType.ImageWithBBox.value: LeapImageWithBBox
|
168
146
|
}
|
@@ -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
|
@@ -101,6 +102,10 @@ class LeapBinder:
|
|
101
102
|
|
102
103
|
self._encoder_names.append(name)
|
103
104
|
|
105
|
+
def set_instance_element(self, input_name: str, instance_function: Optional[InstanceCallableInterface] = None,
|
106
|
+
analysis_type: InstanceAnalysisType = InstanceAnalysisType.MaskInput) -> None:
|
107
|
+
self.setup_container.element_instances.append(ElementInstanceHandler(input_name, instance_function, analysis_type))
|
108
|
+
|
104
109
|
def add_custom_loss(self, function: CustomCallableInterface, name: str) -> None:
|
105
110
|
arg_names = inspect.getfullargspec(function)[0]
|
106
111
|
self.setup_container.custom_loss_handlers.append(CustomLossHandler(name, function, arg_names))
|
@@ -132,7 +137,8 @@ class LeapBinder:
|
|
132
137
|
custom_layer.kernel_index = kernel_index
|
133
138
|
|
134
139
|
if use_custom_latent_space and not hasattr(custom_layer, custom_latent_space_attribute):
|
135
|
-
raise Exception(
|
140
|
+
raise Exception(
|
141
|
+
f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
|
136
142
|
|
137
143
|
init_args = inspect.getfullargspec(custom_layer.__init__)[0][1:]
|
138
144
|
call_args = inspect.getfullargspec(custom_layer.call)[0][1:]
|
code_loader/leaploader.py
CHANGED
@@ -5,14 +5,14 @@ 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
|
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
|
15
|
+
PredictionTypeHandler, MetadataHandler, CustomLayerHandler, MetricHandler, ElementInstance
|
16
16
|
from code_loader.contract.enums import DataStateEnum, TestingSectionEnum, DataStateType, DatasetMetadataType
|
17
17
|
from code_loader.contract.exceptions import DatasetScriptException
|
18
18
|
from code_loader.contract.responsedataclasses import DatasetIntegParseResult, DatasetTestResultPayload, \
|
@@ -298,6 +298,17 @@ class LeapLoader:
|
|
298
298
|
def _get_inputs(self, state: DataStateEnum, idx: int) -> Dict[str, npt.NDArray[np.float32]]:
|
299
299
|
return self._get_dataset_handlers(global_leap_binder.setup_container.inputs, state, idx)
|
300
300
|
|
301
|
+
def get_instance_elements(self, state: DataStateEnum, idx: int, input_name: str) \
|
302
|
+
-> Tuple[Optional[List[ElementInstance]], Optional[InstanceAnalysisType]]:
|
303
|
+
preprocess_result = self._preprocess_result()
|
304
|
+
preprocess_state = preprocess_result[state]
|
305
|
+
for element_instance in global_leap_binder.setup_container.element_instances:
|
306
|
+
if element_instance.input_name == input_name:
|
307
|
+
return element_instance.instance_function(idx, preprocess_state), element_instance.analysis_type
|
308
|
+
|
309
|
+
return None, None
|
310
|
+
|
311
|
+
|
301
312
|
def _get_gt(self, state: DataStateEnum, idx: int) -> Dict[str, npt.NDArray[np.float32]]:
|
302
313
|
return self._get_dataset_handlers(global_leap_binder.setup_container.ground_truths, state, idx)
|
303
314
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
from enum import Enum
|
2
|
-
from typing import List
|
3
2
|
|
4
3
|
import numpy as np
|
5
4
|
import numpy.typing as npt
|
@@ -17,7 +16,7 @@ class DefaultVisualizer(Enum):
|
|
17
16
|
ImageMask = 'ImageMask'
|
18
17
|
TextMask = 'TextMask'
|
19
18
|
RawData = 'RawData'
|
20
|
-
|
19
|
+
|
21
20
|
|
22
21
|
def default_image_visualizer(data: npt.NDArray[np.float32]) -> LeapImage:
|
23
22
|
rescaled_data = rescale_min_max(data)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
2
|
+
code_loader/__init__.py,sha256=V3DEXSN6Ie6PlGeSAbzjp9ufRj0XPJLpD7pDLLYxk6M,122
|
3
|
+
code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
code_loader/contract/datasetclasses.py,sha256=45g-iy_HEd1Q7LAMaAjNbYqJxgEwvTlNNC_V6hN5koU,5141
|
5
|
+
code_loader/contract/enums.py,sha256=3jBkDBa7od9SrSZdozrvy4InvyuRk4Ov1yEMsQxc-Pg,1665
|
6
|
+
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
7
|
+
code_loader/contract/responsedataclasses.py,sha256=WSHmFZWOFhGL1eED1u-aoRotPQg2owFQ-t3xSViWXSI,2808
|
8
|
+
code_loader/contract/visualizer_classes.py,sha256=1FjVO744J_EMuJfHWXGdvSz6vl3Vu7iS3CDfs8MzEEQ,5138
|
9
|
+
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
10
|
+
code_loader/inner_leap_binder/leapbinder.py,sha256=wf3yxyxhN8k_eFecmt7nTUqbD3uMEoGccZcrOilOftc,14054
|
11
|
+
code_loader/leaploader.py,sha256=D1CzclYll0kg_2sTZ_tS1-BFWlMCmiJZHrQCMwRiNtg,17882
|
12
|
+
code_loader/utils.py,sha256=61I4PgSl-ZBIe4DifLxMNlBELE-HQR2pB9efVYPceIU,2230
|
13
|
+
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
+
code_loader/visualizers/default_visualizers.py,sha256=HqWx2qfTrroGl2n8Fpmr_4X-rk7tE2oGapjO3gzz4WY,2226
|
15
|
+
code_loader-1.0.40a1.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
16
|
+
code_loader-1.0.40a1.dist-info/METADATA,sha256=o9NkQbpAF3lZIRPc147tORbE0NHH1gBJ7igKxKvDCIg,770
|
17
|
+
code_loader-1.0.40a1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
18
|
+
code_loader-1.0.40a1.dist-info/RECORD,,
|
@@ -1,18 +0,0 @@
|
|
1
|
-
LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
2
|
-
code_loader/__init__.py,sha256=V3DEXSN6Ie6PlGeSAbzjp9ufRj0XPJLpD7pDLLYxk6M,122
|
3
|
-
code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
code_loader/contract/datasetclasses.py,sha256=e4pEajPiktogtrctf29Q9IqG5VaZz0QE_ioc4Ri1ohs,4796
|
5
|
-
code_loader/contract/enums.py,sha256=6Lo7p5CUog68Fd31bCozIuOgIp_IhSiPqWWph2k3OGU,1602
|
6
|
-
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
7
|
-
code_loader/contract/responsedataclasses.py,sha256=WSHmFZWOFhGL1eED1u-aoRotPQg2owFQ-t3xSViWXSI,2808
|
8
|
-
code_loader/contract/visualizer_classes.py,sha256=EKkQ7qWS48LeT3JoJT8-uMdRDxVOkSp0q-rhVMxrEFY,5990
|
9
|
-
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
10
|
-
code_loader/inner_leap_binder/leapbinder.py,sha256=cayCJxnksr5lrEIX1HngiuPpTupStti4DD6KX3k-PBI,13610
|
11
|
-
code_loader/leaploader.py,sha256=pUySweZetJ6SsubCcZlDCJpvWmUrm5YlPlkZWQxY1hQ,17289
|
12
|
-
code_loader/utils.py,sha256=61I4PgSl-ZBIe4DifLxMNlBELE-HQR2pB9efVYPceIU,2230
|
13
|
-
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
-
code_loader/visualizers/default_visualizers.py,sha256=F2qRT6rNy7SOmr4QfqVxIkLlYEa00CwDkLJuA45lfSI,2254
|
15
|
-
code_loader-1.0.39.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
16
|
-
code_loader-1.0.39.dist-info/METADATA,sha256=saUXYJj72tcvhB7eKz-a0QKcVEFzs4cRVC7lDvD_COc,768
|
17
|
-
code_loader-1.0.39.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
18
|
-
code_loader-1.0.39.dist-info/RECORD,,
|
File without changes
|