code-loader 1.0.42__tar.gz → 1.0.42a0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.42
3
+ Version: 1.0.42a0
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -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)
@@ -64,3 +64,9 @@ class ConfusionMatrixValue(Enum):
64
64
  class TestingSectionEnum(Enum):
65
65
  Warnings = "Warnings"
66
66
  Errors = "Errors"
67
+
68
+
69
+
70
+ class InstanceAnalysisType(Enum):
71
+ MaskInput = "MaskInput"
72
+ MaskLatentSpace = "MaskLatentSpace"
@@ -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, RawInputsForHeatmap
13
- from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType, MetricDirection
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(f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
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:]
@@ -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,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "code-loader"
3
- version = "1.0.42"
3
+ version = "1.0.42a0"
4
4
  description = ""
5
5
  authors = ["dorhar <doron.harnoy@tensorleap.ai>"]
6
6
  license = "MIT"
File without changes
File without changes