code-loader 1.0.86__py3-none-any.whl → 1.0.87a0__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.
@@ -7,7 +7,7 @@ import numpy.typing as npt
7
7
  from code_loader.contract.enums import DataStateType, DataStateEnum, LeapDataType, ConfusionMatrixValue, \
8
8
  MetricDirection, DatasetMetadataType
9
9
  from code_loader.contract.visualizer_classes import LeapImage, LeapText, LeapGraph, LeapHorizontalBar, \
10
- LeapTextMask, LeapImageMask, LeapImageWithBBox, LeapImageWithHeatmap, LeapVideo
10
+ LeapTextMask, LeapImageMask, LeapImageWithBBox, LeapImageWithHeatmap
11
11
 
12
12
  custom_latent_space_attribute = "custom_latent_space"
13
13
 
@@ -94,7 +94,6 @@ class UnlabeledDataPreprocessHandler:
94
94
 
95
95
  VisualizerCallableInterface = Union[
96
96
  Callable[..., LeapImage],
97
- Callable[..., LeapVideo],
98
97
  Callable[..., LeapText],
99
98
  Callable[..., LeapGraph],
100
99
  Callable[..., LeapHorizontalBar],
@@ -105,7 +104,7 @@ VisualizerCallableInterface = Union[
105
104
  ]
106
105
 
107
106
  LeapData = Union[LeapImage, LeapText, LeapGraph, LeapHorizontalBar, LeapImageMask, LeapTextMask, LeapImageWithBBox,
108
- LeapImageWithHeatmap, LeapVideo]
107
+ LeapImageWithHeatmap]
109
108
 
110
109
  CustomCallableInterface = Callable[..., Any]
111
110
 
@@ -20,7 +20,7 @@ from code_loader.utils import to_numpy_return_wrapper, get_shape
20
20
  from code_loader.visualizers.default_visualizers import DefaultVisualizer, \
21
21
  default_graph_visualizer, \
22
22
  default_image_visualizer, default_horizontal_bar_visualizer, default_word_visualizer, \
23
- default_image_mask_visualizer, default_text_mask_visualizer, default_raw_data_visualizer, default_video_visualizer
23
+ default_image_mask_visualizer, default_text_mask_visualizer, default_raw_data_visualizer
24
24
 
25
25
 
26
26
  class LeapBinder:
@@ -48,8 +48,6 @@ class LeapBinder:
48
48
  def _extend_with_default_visualizers(self) -> None:
49
49
  self.set_visualizer(function=default_image_visualizer, name=DefaultVisualizer.Image.value,
50
50
  visualizer_type=LeapDataType.Image)
51
- self.set_visualizer(function=default_video_visualizer, name=DefaultVisualizer.Video.value,
52
- visualizer_type=LeapDataType.Video)
53
51
  self.set_visualizer(function=default_graph_visualizer, name=DefaultVisualizer.Graph.value,
54
52
  visualizer_type=LeapDataType.Graph)
55
53
  self.set_visualizer(function=default_raw_data_visualizer, name=DefaultVisualizer.RawData.value,
code_loader/leaploader.py CHANGED
@@ -22,7 +22,7 @@ from code_loader.contract.responsedataclasses import DatasetIntegParseResult, Da
22
22
  VisualizerInstance, PredictionTypeInstance, ModelSetup, CustomLayerInstance, MetricInstance, CustomLossInstance
23
23
  from code_loader.inner_leap_binder import global_leap_binder
24
24
  from code_loader.leaploaderbase import LeapLoaderBase
25
- from code_loader.utils import get_root_exception_file_and_line_number
25
+ from code_loader.utils import get_root_exception_file_and_line_number, flatten
26
26
 
27
27
 
28
28
  class LeapLoader(LeapLoaderBase):
@@ -471,22 +471,18 @@ class LeapLoader(LeapLoaderBase):
471
471
 
472
472
  return converted_value, is_none
473
473
 
474
- def _get_metadata(self, state: DataStateEnum, sample_id: Union[int, str]) -> Tuple[Dict[str, Union[str, int, bool, float]], Dict[str, bool]]:
474
+ def _get_metadata(self, state: DataStateEnum, sample_id: Union[int, str]) -> Tuple[
475
+ Dict[str, Union[str, int, bool, float]], Dict[str, bool]]:
475
476
  result_agg = {}
476
477
  is_none = {}
477
478
  preprocess_result = self._preprocess_result()
478
479
  preprocess_state = preprocess_result[state]
479
480
  for handler in global_leap_binder.setup_container.metadata:
480
481
  handler_result = handler.function(sample_id, preprocess_state)
481
- if isinstance(handler_result, dict):
482
- for single_metadata_name, single_metadata_result in handler_result.items():
483
- handler_name = f'{handler.name}_{single_metadata_name}'
484
- result_agg[handler_name], is_none[handler_name] = self._convert_metadata_to_correct_type(
485
- handler_name, single_metadata_result)
486
- else:
487
- handler_name = handler.name
488
- result_agg[handler_name], is_none[handler_name] = self._convert_metadata_to_correct_type(
489
- handler_name, handler_result)
482
+
483
+ for flat_name, flat_result in flatten(handler_result, prefix=handler.name):
484
+ result_agg[flat_name], is_none[flat_name] = self._convert_metadata_to_correct_type(
485
+ flat_name, flat_result)
490
486
 
491
487
  return result_agg, is_none
492
488
 
code_loader/utils.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import sys
2
2
  from pathlib import Path
3
3
  from types import TracebackType
4
- from typing import List, Union, Tuple, Any
4
+ from typing import List, Union, Tuple, Any, Iterator
5
5
  import traceback
6
6
  import numpy as np
7
7
  import numpy.typing as npt
@@ -66,3 +66,28 @@ def rescale_min_max(image: npt.NDArray[np.float32]) -> npt.NDArray[np.float32]:
66
66
  return image
67
67
 
68
68
 
69
+ def flatten(
70
+ value: Any,
71
+ *,
72
+ prefix: str = "",
73
+ list_token: str = "e",
74
+ ) -> Iterator[Tuple[str, Any]]:
75
+ """
76
+ Recursively walk `value` and yield (flat_key, leaf_value) pairs.
77
+
78
+ • Dicts → descend with new_prefix = f"{prefix}_{key}" (or just key if top level)
79
+ • Sequences → descend with new_prefix = f"{prefix}_{list_token}{idx}"
80
+ • Leaf scalars → yield the accumulated flat key and the scalar itself
81
+ """
82
+ if isinstance(value, dict):
83
+ for k, v in value.items():
84
+ new_prefix = f"{prefix}_{k}" if prefix else k
85
+ yield from flatten(v, prefix=new_prefix, list_token=list_token)
86
+
87
+ elif isinstance(value, (list, tuple)):
88
+ for idx, v in enumerate(value):
89
+ new_prefix = f"{prefix}_{list_token}{idx}"
90
+ yield from flatten(v, prefix=new_prefix, list_token=list_token)
91
+
92
+ else: # primitive leaf (str, int, float, bool, None…)
93
+ yield prefix, value
@@ -4,13 +4,12 @@ import numpy as np
4
4
  import numpy.typing as npt
5
5
 
6
6
  from code_loader.contract.visualizer_classes import LeapImage, LeapGraph, LeapHorizontalBar, LeapText, \
7
- LeapImageMask, LeapTextMask, LeapVideo
7
+ LeapImageMask, LeapTextMask
8
8
  from code_loader.utils import rescale_min_max
9
9
 
10
10
 
11
11
  class DefaultVisualizer(Enum):
12
12
  Image = 'Image'
13
- Video = 'Video'
14
13
  Graph = 'Graph'
15
14
  HorizontalBar = 'HorizontalBar'
16
15
  Text = 'Text'
@@ -24,10 +23,6 @@ def default_image_visualizer(data: npt.NDArray[np.float32]) -> LeapImage:
24
23
  return LeapImage(rescaled_data)
25
24
 
26
25
 
27
- def default_video_visualizer(data: npt.NDArray[np.float32]) -> LeapVideo:
28
- return LeapVideo(data)
29
-
30
-
31
26
  def default_graph_visualizer(data: npt.NDArray[np.float32]) -> LeapGraph:
32
27
  return LeapGraph(data)
33
28
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.86
3
+ Version: 1.0.87a0
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
1
  LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
2
2
  code_loader/__init__.py,sha256=6MMWr0ObOU7hkqQKgOqp4Zp3I28L7joGC9iCbQYtAJg,241
3
3
  code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- code_loader/contract/datasetclasses.py,sha256=ZN6XC-tg0qaT-GF4YiV2SsM2dUQW4fc1akLF-J4YT0w,7964
4
+ code_loader/contract/datasetclasses.py,sha256=rpsccWddYksLQhB0fDZKZsiuclb32wtAraLtvXZ0teM,7912
5
5
  code_loader/contract/enums.py,sha256=GEFkvUMXnCNt-GOoz7NJ9ecQZ2PPDettJNOsxsiM0wk,1622
6
6
  code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
7
7
  code_loader/contract/responsedataclasses.py,sha256=RSx9m_R3LawhK5o1nAcO3hfp2F9oJYtxZr_bpP3bTmw,4005
@@ -19,14 +19,14 @@ code_loader/experiment_api/types.py,sha256=MY8xFARHwdVA7p4dxyhD60ShmttgTvb4qdp1o
19
19
  code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZJEqBqc,3304
20
20
  code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
21
21
  code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
22
- code_loader/inner_leap_binder/leapbinder.py,sha256=yqKkw_c4ZhM9Gbv7tgja0EsrN3VpZIcVCiKkcGxYIaM,30816
22
+ code_loader/inner_leap_binder/leapbinder.py,sha256=q0nSOOL-yYO4DYZUy4O3sEkzb3SeF1__0POWyZUuh1o,30627
23
23
  code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=qcYyekpIN1hgbmSqTrN7o6IMpfu8ZWp2J_lhMEoV8I8,22598
24
- code_loader/leaploader.py,sha256=QPBG7xrNdzhnOiRtwUlVosyYcFNC_ivWgoS8nWOZ_5M,25768
24
+ code_loader/leaploader.py,sha256=t9ITSzECPg5sGXHxsYkcr45tDipd79hJw6lhwo4yEIE,25412
25
25
  code_loader/leaploaderbase.py,sha256=VH0vddRmkqLtcDlYPCO7hfz1_VbKo43lUdHDAbd4iJc,4198
26
- code_loader/utils.py,sha256=aw2i_fqW_ADjLB66FWZd9DfpCQ7mPdMyauROC5Nd51I,2197
26
+ code_loader/utils.py,sha256=4tXLum2AT3Z1ldD6BeYScNg0ATyE4oM8cuIGQxrXyjM,3163
27
27
  code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
- code_loader/visualizers/default_visualizers.py,sha256=f95WzLYO2KU8endWxrmtwjHx7diDfm8AaWjucYHT7GI,2439
29
- code_loader-1.0.86.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
30
- code_loader-1.0.86.dist-info/METADATA,sha256=qCACujoX1VjTPmmJ7eH5xCGckIGfTNEGLReZEpcACdc,849
31
- code_loader-1.0.86.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
- code_loader-1.0.86.dist-info/RECORD,,
28
+ code_loader/visualizers/default_visualizers.py,sha256=Ffx5VHVOe5ujBOsjBSxN_aIEVwFSQ6gbhTMG5aUS-po,2305
29
+ code_loader-1.0.87a0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
30
+ code_loader-1.0.87a0.dist-info/METADATA,sha256=EvdS0HJq0gncoWJXMFgC3LgMS6GnziuGieCRDw_vhtk,851
31
+ code_loader-1.0.87a0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
+ code_loader-1.0.87a0.dist-info/RECORD,,