code-loader 1.0.39__tar.gz → 1.0.40a0__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.
Files changed (27) hide show
  1. {code_loader-1.0.39 → code_loader-1.0.40a0}/PKG-INFO +1 -1
  2. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/contract/datasetclasses.py +13 -4
  3. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/contract/enums.py +0 -1
  4. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/contract/visualizer_classes.py +1 -23
  5. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/inner_leap_binder/leapbinder.py +7 -4
  6. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/leaploader.py +11 -2
  7. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/visualizers/default_visualizers.py +1 -2
  8. {code_loader-1.0.39 → code_loader-1.0.40a0}/pyproject.toml +1 -1
  9. code_loader-1.0.39/code_loader/contract/__pycache__/__init__.cpython-38.pyc +0 -0
  10. code_loader-1.0.39/code_loader/contract/__pycache__/datasetclasses.cpython-38.pyc +0 -0
  11. code_loader-1.0.39/code_loader/contract/__pycache__/enums.cpython-38.pyc +0 -0
  12. code_loader-1.0.39/code_loader/contract/__pycache__/exceptions.cpython-38.pyc +0 -0
  13. code_loader-1.0.39/code_loader/contract/__pycache__/responsedataclasses.cpython-38.pyc +0 -0
  14. code_loader-1.0.39/code_loader/contract/__pycache__/visualizer_classes.cpython-38.pyc +0 -0
  15. code_loader-1.0.39/code_loader/inner_leap_binder/__pycache__/__init__.cpython-38.pyc +0 -0
  16. code_loader-1.0.39/code_loader/inner_leap_binder/__pycache__/leapbinder.cpython-38.pyc +0 -0
  17. code_loader-1.0.39/code_loader/visualizers/__pycache__/__init__.cpython-38.pyc +0 -0
  18. code_loader-1.0.39/code_loader/visualizers/__pycache__/default_visualizers.cpython-38.pyc +0 -0
  19. {code_loader-1.0.39 → code_loader-1.0.40a0}/LICENSE +0 -0
  20. {code_loader-1.0.39 → code_loader-1.0.40a0}/README.md +0 -0
  21. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/__init__.py +0 -0
  22. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/contract/__init__.py +0 -0
  23. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/contract/exceptions.py +0 -0
  24. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/contract/responsedataclasses.py +0 -0
  25. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/inner_leap_binder/__init__.py +0 -0
  26. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/utils.py +0 -0
  27. {code_loader-1.0.39 → code_loader-1.0.40a0}/code_loader/visualizers/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.39
3
+ Version: 1.0.40a0
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -6,7 +6,7 @@ import numpy.typing as npt
6
6
 
7
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, LeapImageWithHeatmap
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, LeapImageWithHeatmap]
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]]
@@ -113,6 +121,7 @@ class DatasetBaseHandler:
113
121
  @dataclass
114
122
  class InputHandler(DatasetBaseHandler):
115
123
  shape: Optional[List[int]] = None
124
+ instance_function: Optional[InstanceCallableInterface] = None
116
125
 
117
126
 
118
127
  @dataclass
@@ -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):
@@ -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,7 +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, RawInputsForHeatmap
12
+ CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler, custom_latent_space_attribute, \
13
+ RawInputsForHeatmap, InstanceCallableInterface
13
14
  from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType, MetricDirection
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
@@ -95,9 +96,10 @@ class LeapBinder:
95
96
  def set_unlabeled_data_preprocess(self, function: Callable[[], PreprocessResponse]) -> None:
96
97
  self.setup_container.unlabeled_data_preprocess = UnlabeledDataPreprocessHandler(function)
97
98
 
98
- def set_input(self, function: SectionCallableInterface, name: str) -> None:
99
+ def set_input(self, function: SectionCallableInterface, name: str,
100
+ instance_function: Optional[InstanceCallableInterface] = None) -> None:
99
101
  function = to_numpy_return_wrapper(function)
100
- self.setup_container.inputs.append(InputHandler(name, function))
102
+ self.setup_container.inputs.append(InputHandler(name, function, instance_function=instance_function))
101
103
 
102
104
  self._encoder_names.append(name)
103
105
 
@@ -132,7 +134,8 @@ class LeapBinder:
132
134
  custom_layer.kernel_index = kernel_index
133
135
 
134
136
  if use_custom_latent_space and not hasattr(custom_layer, custom_latent_space_attribute):
135
- raise Exception(f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
137
+ raise Exception(
138
+ f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
136
139
 
137
140
  init_args = inspect.getfullargspec(custom_layer.__init__)[0][1:]
138
141
  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, 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,15 @@ 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) -> Optional[List[ElementInstance]]:
302
+ preprocess_result = self._preprocess_result()
303
+ preprocess_state = preprocess_result[state]
304
+ for input in global_leap_binder.setup_container.inputs:
305
+ if input.name == input_name:
306
+ if input.instance_function is not None:
307
+ return input.instance_function(idx, preprocess_state)
308
+
309
+
301
310
  def _get_gt(self, state: DataStateEnum, idx: int) -> Dict[str, npt.NDArray[np.float32]]:
302
311
  return self._get_dataset_handlers(global_leap_binder.setup_container.ground_truths, state, idx)
303
312
 
@@ -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)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "code-loader"
3
- version = "1.0.39"
3
+ version = "1.0.40a0"
4
4
  description = ""
5
5
  authors = ["dorhar <doron.harnoy@tensorleap.ai>"]
6
6
  license = "MIT"
File without changes
File without changes