code-loader 1.0.40a1__tar.gz → 1.0.41__tar.gz
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-1.0.40a1 → code_loader-1.0.41}/PKG-INFO +1 -1
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/contract/datasetclasses.py +5 -22
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/contract/enums.py +1 -6
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/contract/responsedataclasses.py +2 -1
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/contract/visualizer_classes.py +23 -1
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/inner_leap_binder/leapbinder.py +3 -9
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/leaploader.py +16 -15
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/visualizers/default_visualizers.py +2 -1
- {code_loader-1.0.40a1 → code_loader-1.0.41}/pyproject.toml +1 -1
- {code_loader-1.0.40a1 → code_loader-1.0.41}/LICENSE +0 -0
- {code_loader-1.0.40a1 → code_loader-1.0.41}/README.md +0 -0
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/__init__.py +0 -0
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/contract/__init__.py +0 -0
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/contract/exceptions.py +0 -0
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/inner_leap_binder/__init__.py +0 -0
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/utils.py +0 -0
- {code_loader-1.0.40a1 → code_loader-1.0.41}/code_loader/visualizers/__init__.py +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
|
8
8
|
from code_loader.contract.visualizer_classes import LeapImage, LeapText, LeapGraph, LeapHorizontalBar, \
|
9
|
-
LeapTextMask, LeapImageMask, LeapImageWithBBox
|
9
|
+
LeapTextMask, LeapImageMask, LeapImageWithBBox, LeapImageWithHeatmap
|
10
10
|
|
11
11
|
custom_latent_space_attribute = "custom_latent_space"
|
12
12
|
|
@@ -17,16 +17,8 @@ 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
|
-
|
26
20
|
SectionCallableInterface = Callable[[int, PreprocessResponse], npt.NDArray[np.float32]]
|
27
21
|
|
28
|
-
InstanceCallableInterface = Callable[[int, PreprocessResponse], List[ElementInstance]]
|
29
|
-
|
30
22
|
MetadataSectionCallableInterface = Union[
|
31
23
|
Callable[[int, PreprocessResponse], int],
|
32
24
|
Callable[[int, PreprocessResponse], Dict[str, int]],
|
@@ -58,11 +50,12 @@ VisualizerCallableInterface = Union[
|
|
58
50
|
Callable[..., LeapHorizontalBar],
|
59
51
|
Callable[..., LeapImageMask],
|
60
52
|
Callable[..., LeapTextMask],
|
61
|
-
Callable[..., LeapImageWithBBox]
|
53
|
+
Callable[..., LeapImageWithBBox],
|
54
|
+
Callable[..., LeapImageWithHeatmap]
|
62
55
|
]
|
63
56
|
|
64
57
|
VisualizerCallableReturnType = Union[LeapImage, LeapText, LeapGraph, LeapHorizontalBar,
|
65
|
-
LeapImageMask, LeapTextMask, LeapImageWithBBox]
|
58
|
+
LeapImageMask, LeapTextMask, LeapImageWithBBox, LeapImageWithHeatmap]
|
66
59
|
|
67
60
|
CustomCallableInterface = Callable[..., Any]
|
68
61
|
|
@@ -97,7 +90,6 @@ class MetricHandler:
|
|
97
90
|
arg_names: List[str]
|
98
91
|
direction: Optional[MetricDirection] = MetricDirection.Downward
|
99
92
|
|
100
|
-
|
101
93
|
@dataclass
|
102
94
|
class RawInputsForHeatmap:
|
103
95
|
raw_input_by_vizualizer_arg_name: Dict[str, npt.NDArray[np.float32]]
|
@@ -123,14 +115,6 @@ class InputHandler(DatasetBaseHandler):
|
|
123
115
|
shape: Optional[List[int]] = None
|
124
116
|
|
125
117
|
|
126
|
-
@dataclass
|
127
|
-
class ElementInstanceHandler:
|
128
|
-
input_name: str
|
129
|
-
instance_function: InstanceCallableInterface
|
130
|
-
analysis_type: InstanceAnalysisType
|
131
|
-
|
132
|
-
|
133
|
-
|
134
118
|
@dataclass
|
135
119
|
class GroundTruthHandler(DatasetBaseHandler):
|
136
120
|
shape: Optional[List[int]] = None
|
@@ -164,7 +148,6 @@ class DatasetIntegrationSetup:
|
|
164
148
|
unlabeled_data_preprocess: Optional[UnlabeledDataPreprocessHandler] = None
|
165
149
|
visualizers: List[VisualizerHandler] = field(default_factory=list)
|
166
150
|
inputs: List[InputHandler] = field(default_factory=list)
|
167
|
-
element_instances: List[ElementInstanceHandler] = field(default_factory=list)
|
168
151
|
ground_truths: List[GroundTruthHandler] = field(default_factory=list)
|
169
152
|
metadata: List[MetadataHandler] = field(default_factory=list)
|
170
153
|
prediction_types: List[PredictionTypeHandler] = field(default_factory=list)
|
@@ -26,6 +26,7 @@ class LeapDataType(Enum):
|
|
26
26
|
ImageMask = 'ImageMask'
|
27
27
|
TextMask = 'TextMask'
|
28
28
|
ImageWithBBox = 'ImageWithBBox'
|
29
|
+
ImageWithHeatmap = 'ImageWithHeatmap'
|
29
30
|
|
30
31
|
|
31
32
|
class MetricDirection(Enum):
|
@@ -63,9 +64,3 @@ class ConfusionMatrixValue(Enum):
|
|
63
64
|
class TestingSectionEnum(Enum):
|
64
65
|
Warnings = "Warnings"
|
65
66
|
Errors = "Errors"
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
class InstanceAnalysisType(Enum):
|
70
|
-
MaskInput = "MaskInput"
|
71
|
-
MaskLatentSpace = "MaskLatentSpace"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import List, Optional, Dict, Any
|
1
|
+
from typing import List, Optional, Dict, Any, Union
|
2
2
|
|
3
3
|
from dataclasses import dataclass, field
|
4
4
|
from code_loader.contract.enums import DatasetMetadataType, LeapDataType
|
@@ -104,6 +104,7 @@ class BoundingBox:
|
|
104
104
|
confidence: float
|
105
105
|
label: str
|
106
106
|
rotation: float = 0.0 # value between [0, 360], represent the degree of rotation.
|
107
|
+
metadata: Optional[Dict[str, Union[str, int, float]]] = None
|
107
108
|
|
108
109
|
|
109
110
|
@dataclass
|
@@ -135,6 +135,27 @@ 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
|
+
|
138
159
|
map_leap_data_type_to_visualizer_class = {
|
139
160
|
LeapDataType.Image.value: LeapImage,
|
140
161
|
LeapDataType.Graph.value: LeapGraph,
|
@@ -142,5 +163,6 @@ map_leap_data_type_to_visualizer_class = {
|
|
142
163
|
LeapDataType.HorizontalBar.value: LeapHorizontalBar,
|
143
164
|
LeapDataType.ImageMask.value: LeapImageMask,
|
144
165
|
LeapDataType.TextMask.value: LeapTextMask,
|
145
|
-
LeapDataType.ImageWithBBox.value: LeapImageWithBBox
|
166
|
+
LeapDataType.ImageWithBBox.value: LeapImageWithBBox,
|
167
|
+
LeapDataType.ImageWithHeatmap.value: LeapImageWithHeatmap
|
146
168
|
}
|
@@ -9,9 +9,8 @@ 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
|
-
|
14
|
-
from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType, MetricDirection, InstanceAnalysisType
|
12
|
+
CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler, custom_latent_space_attribute, RawInputsForHeatmap
|
13
|
+
from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType, MetricDirection
|
15
14
|
from code_loader.contract.responsedataclasses import DatasetTestResultPayload
|
16
15
|
from code_loader.contract.visualizer_classes import map_leap_data_type_to_visualizer_class
|
17
16
|
from code_loader.utils import to_numpy_return_wrapper, get_shape
|
@@ -102,10 +101,6 @@ class LeapBinder:
|
|
102
101
|
|
103
102
|
self._encoder_names.append(name)
|
104
103
|
|
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
|
-
|
109
104
|
def add_custom_loss(self, function: CustomCallableInterface, name: str) -> None:
|
110
105
|
arg_names = inspect.getfullargspec(function)[0]
|
111
106
|
self.setup_container.custom_loss_handlers.append(CustomLossHandler(name, function, arg_names))
|
@@ -137,8 +132,7 @@ class LeapBinder:
|
|
137
132
|
custom_layer.kernel_index = kernel_index
|
138
133
|
|
139
134
|
if use_custom_latent_space and not hasattr(custom_layer, custom_latent_space_attribute):
|
140
|
-
raise Exception(
|
141
|
-
f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
|
135
|
+
raise Exception(f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
|
142
136
|
|
143
137
|
init_args = inspect.getfullargspec(custom_layer.__init__)[0][1:]
|
144
138
|
call_args = inspect.getfullargspec(custom_layer.call)[0][1:]
|
@@ -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
|
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
|
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, \
|
@@ -30,6 +30,7 @@ class LeapLoader:
|
|
30
30
|
@lru_cache()
|
31
31
|
def exec_script(self) -> None:
|
32
32
|
try:
|
33
|
+
print("executing script")
|
33
34
|
self.evaluate_module()
|
34
35
|
except TypeError as e:
|
35
36
|
import traceback
|
@@ -41,25 +42,34 @@ class LeapLoader:
|
|
41
42
|
raise DatasetScriptException(getattr(e, 'message', repr(e))) from e
|
42
43
|
|
43
44
|
def evaluate_module(self) -> None:
|
45
|
+
print("evaluate_module")
|
46
|
+
|
44
47
|
def append_path_recursively(full_path: str) -> None:
|
45
48
|
if '/' not in full_path or full_path == '/':
|
46
49
|
return
|
47
50
|
|
48
51
|
parent_path = str(Path(full_path).parent)
|
52
|
+
print(f"evaluate_module.append_path_recursively full_path: {full_path}, parent_path: {parent_path}")
|
49
53
|
append_path_recursively(parent_path)
|
54
|
+
|
50
55
|
sys.path.append(parent_path)
|
51
56
|
|
52
57
|
file_path = Path(self.code_path, self.code_entry_name)
|
58
|
+
print(f"evaluate_module: self.code_path: {self.code_path} self.code_entry_name: {self.code_entry_name}, "
|
59
|
+
f"file_path for append_path_recursively: {str(file_path)}")
|
53
60
|
append_path_recursively(str(file_path))
|
54
61
|
|
55
62
|
spec = importlib.util.spec_from_file_location(self.code_path, file_path)
|
63
|
+
print(f"evaluate_module: spec: {str(spec)}")
|
56
64
|
if spec is None or spec.loader is None:
|
57
65
|
raise DatasetScriptException(f'Something is went wrong with spec file from: {file_path}')
|
58
66
|
|
59
67
|
file = importlib.util.module_from_spec(spec)
|
68
|
+
print(f"evaluate_module: file module_from_spec: {str(file)}")
|
60
69
|
if file is None:
|
61
70
|
raise DatasetScriptException(f'Something is went wrong with import module from: {file_path}')
|
62
71
|
|
72
|
+
print(f"evaluate_module: spec.loader.exec_module")
|
63
73
|
spec.loader.exec_module(file)
|
64
74
|
|
65
75
|
@lru_cache()
|
@@ -171,7 +181,8 @@ class LeapLoader:
|
|
171
181
|
preprocess_response, test_result, dataset_base_handler)
|
172
182
|
except Exception as e:
|
173
183
|
line_number, file_name, stacktrace = get_root_exception_file_and_line_number()
|
174
|
-
test_result[0].display[
|
184
|
+
test_result[0].display[
|
185
|
+
state_name] = f"{repr(e)} in file {file_name}, line_number: {line_number}\nStacktrace:\n{stacktrace}"
|
175
186
|
test_result[0].is_passed = False
|
176
187
|
|
177
188
|
result_payloads.extend(test_result)
|
@@ -298,17 +309,6 @@ class LeapLoader:
|
|
298
309
|
def _get_inputs(self, state: DataStateEnum, idx: int) -> Dict[str, npt.NDArray[np.float32]]:
|
299
310
|
return self._get_dataset_handlers(global_leap_binder.setup_container.inputs, state, idx)
|
300
311
|
|
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
|
-
|
312
312
|
def _get_gt(self, state: DataStateEnum, idx: int) -> Dict[str, npt.NDArray[np.float32]]:
|
313
313
|
return self._get_dataset_handlers(global_leap_binder.setup_container.ground_truths, state, idx)
|
314
314
|
|
@@ -354,7 +354,8 @@ class LeapLoader:
|
|
354
354
|
if isinstance(handler_result, dict):
|
355
355
|
for single_metadata_name, single_metadata_result in handler_result.items():
|
356
356
|
handler_name = f'{handler.name}_{single_metadata_name}'
|
357
|
-
result_agg[handler_name] = self._convert_metadata_to_correct_type(handler_name,
|
357
|
+
result_agg[handler_name] = self._convert_metadata_to_correct_type(handler_name,
|
358
|
+
single_metadata_result)
|
358
359
|
else:
|
359
360
|
handler_name = handler.name
|
360
361
|
result_agg[handler_name] = self._convert_metadata_to_correct_type(handler_name, handler_result)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
from enum import Enum
|
2
|
+
from typing import List
|
2
3
|
|
3
4
|
import numpy as np
|
4
5
|
import numpy.typing as npt
|
@@ -16,7 +17,7 @@ class DefaultVisualizer(Enum):
|
|
16
17
|
ImageMask = 'ImageMask'
|
17
18
|
TextMask = 'TextMask'
|
18
19
|
RawData = 'RawData'
|
19
|
-
|
20
|
+
|
20
21
|
|
21
22
|
def default_image_visualizer(data: npt.NDArray[np.float32]) -> LeapImage:
|
22
23
|
rescaled_data = rescale_min_max(data)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|