code-loader 1.0.40a0__py3-none-any.whl → 1.0.41__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.
@@ -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
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]]
@@ -121,7 +113,6 @@ class DatasetBaseHandler:
121
113
  @dataclass
122
114
  class InputHandler(DatasetBaseHandler):
123
115
  shape: Optional[List[int]] = None
124
- instance_function: Optional[InstanceCallableInterface] = None
125
116
 
126
117
 
127
118
  @dataclass
@@ -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):
@@ -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,8 +9,7 @@ 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
- RawInputsForHeatmap, InstanceCallableInterface
12
+ CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler, custom_latent_space_attribute, RawInputsForHeatmap
14
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
@@ -96,10 +95,9 @@ class LeapBinder:
96
95
  def set_unlabeled_data_preprocess(self, function: Callable[[], PreprocessResponse]) -> None:
97
96
  self.setup_container.unlabeled_data_preprocess = UnlabeledDataPreprocessHandler(function)
98
97
 
99
- def set_input(self, function: SectionCallableInterface, name: str,
100
- instance_function: Optional[InstanceCallableInterface] = None) -> None:
98
+ def set_input(self, function: SectionCallableInterface, name: str) -> None:
101
99
  function = to_numpy_return_wrapper(function)
102
- self.setup_container.inputs.append(InputHandler(name, function, instance_function=instance_function))
100
+ self.setup_container.inputs.append(InputHandler(name, function))
103
101
 
104
102
  self._encoder_names.append(name)
105
103
 
@@ -134,8 +132,7 @@ class LeapBinder:
134
132
  custom_layer.kernel_index = kernel_index
135
133
 
136
134
  if use_custom_latent_space and not hasattr(custom_layer, custom_latent_space_attribute):
137
- raise Exception(
138
- 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__}")
139
136
 
140
137
  init_args = inspect.getfullargspec(custom_layer.__init__)[0][1:]
141
138
  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, Optional
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, ElementInstance
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[state_name] = f"{repr(e)} in file {file_name}, line_number: {line_number}\nStacktrace:\n{stacktrace}"
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,15 +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) -> 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
-
310
312
  def _get_gt(self, state: DataStateEnum, idx: int) -> Dict[str, npt.NDArray[np.float32]]:
311
313
  return self._get_dataset_handlers(global_leap_binder.setup_container.ground_truths, state, idx)
312
314
 
@@ -352,7 +354,8 @@ class LeapLoader:
352
354
  if isinstance(handler_result, dict):
353
355
  for single_metadata_name, single_metadata_result in handler_result.items():
354
356
  handler_name = f'{handler.name}_{single_metadata_name}'
355
- result_agg[handler_name] = self._convert_metadata_to_correct_type(handler_name, single_metadata_result)
357
+ result_agg[handler_name] = self._convert_metadata_to_correct_type(handler_name,
358
+ single_metadata_result)
356
359
  else:
357
360
  handler_name = handler.name
358
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.40a0
3
+ Version: 1.0.41
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -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=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=JgISOk1fVAD7dBLmwp2IzCkpItwO7YP3SDqzTX5FMDA,2880
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=SCAJWVTmuAZ4G4SvPljaxDS1zaM_8BOSO45fKhz4L7g,17956
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.41.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
16
+ code_loader-1.0.41.dist-info/METADATA,sha256=QmhzHlZeg1rUYSRKrDAsdJtCYMEZl-9bolsHDtXYuHk,768
17
+ code_loader-1.0.41.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
18
+ code_loader-1.0.41.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -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=eVPrNAoU3ViaxeZQof-qS2bWsgtuJXTqfCF9psS1f7k,4950
5
- code_loader/contract/enums.py,sha256=wJSMFXL_E-JWK_XAgsqOZwOLDiRfcT_rp0oQ3P_edNI,1560
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=n9oiuC-bFLQsG-ZRSO6VeOWg2CB6qHZciAjRlIFKmi8,13778
11
- code_loader/leaploader.py,sha256=hsU1SdUTZIU_sRMGs9LjxMuvIECKsKWq_wL9W5sKMX4,17780
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.40a0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
16
- code_loader-1.0.40a0.dist-info/METADATA,sha256=ZZDeEYKHHQLlyqMKFzGXyKpWqui6gg9HWXcWrU6FdSs,770
17
- code_loader-1.0.40a0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
18
- code_loader-1.0.40a0.dist-info/RECORD,,