code-loader 1.0.70.dev2__tar.gz → 1.0.72__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 (31) hide show
  1. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/PKG-INFO +1 -1
  2. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/contract/datasetclasses.py +3 -1
  3. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/contract/visualizer_classes.py +3 -2
  4. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/inner_leap_binder/leapbinder.py +16 -9
  5. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/inner_leap_binder/leapbinder_decorators.py +25 -12
  6. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/pyproject.toml +1 -1
  7. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/LICENSE +0 -0
  8. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/README.md +0 -0
  9. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/__init__.py +0 -0
  10. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/contract/__init__.py +0 -0
  11. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/contract/enums.py +0 -0
  12. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/contract/exceptions.py +0 -0
  13. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/contract/responsedataclasses.py +0 -0
  14. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/default_losses.py +0 -0
  15. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/default_metrics.py +0 -0
  16. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/__init__.py +0 -0
  17. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/api.py +0 -0
  18. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/cli_config_utils.py +0 -0
  19. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/client.py +0 -0
  20. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/epoch.py +0 -0
  21. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/experiment.py +0 -0
  22. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/experiment_context.py +0 -0
  23. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/types.py +0 -0
  24. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/utils.py +0 -0
  25. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
  26. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/inner_leap_binder/__init__.py +0 -0
  27. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/leaploader.py +0 -0
  28. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/leaploaderbase.py +0 -0
  29. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/utils.py +0 -0
  30. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/visualizers/__init__.py +0 -0
  31. {code_loader-1.0.70.dev2 → code_loader-1.0.72}/code_loader/visualizers/default_visualizers.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.70.dev2
3
+ Version: 1.0.72
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -132,7 +132,8 @@ class CustomLossHandler:
132
132
  class MetricHandlerData:
133
133
  name: str
134
134
  arg_names: List[str]
135
- direction: Optional[MetricDirection] = MetricDirection.Downward
135
+ direction: Union[None, MetricDirection, Dict[str, MetricDirection]] = MetricDirection.Downward
136
+ compute_insights: Union[bool, Dict[str, bool]] = True
136
137
 
137
138
 
138
139
  @dataclass
@@ -171,6 +172,7 @@ class InputHandler(DatasetBaseHandler):
171
172
  shape: Optional[List[int]] = None
172
173
  channel_dim: Optional[int] = -1
173
174
 
175
+
174
176
  @dataclass
175
177
  class GroundTruthHandler(DatasetBaseHandler):
176
178
  shape: Optional[List[int]] = None
@@ -170,12 +170,13 @@ class LeapHorizontalBar:
170
170
  Example:
171
171
  body_data = np.random.rand(5).astype(np.float32)
172
172
  labels = ['Class A', 'Class B', 'Class C', 'Class D', 'Class E']
173
- leap_horizontal_bar = LeapHorizontalBar(body=body_data, labels=labels)
173
+ gt_data = np.array([0.1, 0.2, 0.3, 0.4, 0.5]).astype(np.float32)
174
+ leap_horizontal_bar = LeapHorizontalBar(body=body_data, labels=labels, gt=gt_data)
174
175
  """
175
176
  body: npt.NDArray[np.float32]
176
177
  labels: List[str]
177
- type: LeapDataType = LeapDataType.HorizontalBar
178
178
  gt: Optional[npt.NDArray[np.float32]] = None
179
+ type: LeapDataType = LeapDataType.HorizontalBar
179
180
 
180
181
 
181
182
  def __post_init__(self) -> None:
@@ -33,6 +33,7 @@ class LeapBinder:
33
33
  setup_container (DatasetIntegrationSetup): Container to hold setup configurations.
34
34
  cache_container (Dict[str, Any]): Cache container to store intermediate data.
35
35
  """
36
+
36
37
  def __init__(self) -> None:
37
38
  self.setup_container = DatasetIntegrationSetup()
38
39
  self.cache_container: Dict[str, Any] = {"word_to_index": {}}
@@ -239,23 +240,31 @@ class LeapBinder:
239
240
  leap_binder.add_custom_loss(custom_loss_function, name='custom_loss')
240
241
  """
241
242
  arg_names = inspect.getfullargspec(function)[0]
242
- self.setup_container.custom_loss_handlers.append(CustomLossHandler(CustomLossHandlerData(name, arg_names), function))
243
+ self.setup_container.custom_loss_handlers.append(
244
+ CustomLossHandler(CustomLossHandlerData(name, arg_names), function))
243
245
 
244
246
  def add_custom_metric(self,
245
247
  function: Union[CustomCallableInterfaceMultiArgs,
246
248
  CustomMultipleReturnCallableInterfaceMultiArgs,
247
249
  ConfusionMatrixCallableInterfaceMultiArgs],
248
250
  name: str,
249
- direction: Optional[MetricDirection] = MetricDirection.Downward) -> None:
251
+ direction: Optional[
252
+ Union[MetricDirection, Dict[str, MetricDirection]]] = MetricDirection.Downward,
253
+ compute_insights: Union[bool, Dict[str, bool]] = True) -> None:
250
254
  """
251
255
  Add a custom metric to the setup.
252
256
 
253
257
  Args:
254
258
  function (Union[CustomCallableInterfaceMultiArgs, CustomMultipleReturnCallableInterfaceMultiArgs, ConfusionMatrixCallableInterfaceMultiArgs]): The custom metric function.
255
259
  name (str): The name of the custom metric.
256
- direction (Optional[MetricDirection]): The direction of the metric, either MetricDirection.Upward or MetricDirection.Downward.
260
+ direction (Optional[Union[MetricDirection, Dict[str, MetricDirection]]]): The direction of the metric, either
261
+ MetricDirection.Upward or MetricDirection.Downward, in case custom metric return a dictionary of metrics we can
262
+ supply a dictionary of directions correspondingly.
257
263
  - MetricDirection.Upward: Indicates that higher values of the metric are better and should be maximized.
258
264
  - MetricDirection.Downward: Indicates that lower values of the metric are better and should be minimized.
265
+ compute_insights (Union[bool, Dict[str, bool]]): Whether to compute insights or not. in case custom metric
266
+ return a dictionary of metrics we can supply a dictionary of values correspondingly
267
+
259
268
 
260
269
 
261
270
  Example:
@@ -265,7 +274,8 @@ class LeapBinder:
265
274
  leap_binder.add_custom_metric(custom_metric_function, name='custom_metric', direction=MetricDirection.Downward)
266
275
  """
267
276
  arg_names = inspect.getfullargspec(function)[0]
268
- self.setup_container.metrics.append(MetricHandler(MetricHandlerData(name, arg_names, direction), function))
277
+ metric_handler_data = MetricHandlerData(name, arg_names, direction, compute_insights)
278
+ self.setup_container.metrics.append(MetricHandler(metric_handler_data, function))
269
279
 
270
280
  def add_prediction(self, name: str, labels: List[str], channel_dim: int = -1) -> None:
271
281
  """
@@ -377,7 +387,8 @@ class LeapBinder:
377
387
  custom_layer.kernel_index = kernel_index
378
388
 
379
389
  if use_custom_latent_space and not hasattr(custom_layer, custom_latent_space_attribute):
380
- raise Exception(f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
390
+ raise Exception(
391
+ f"{custom_latent_space_attribute} function has not been set for custom layer: {custom_layer.__name__}")
381
392
 
382
393
  init_args = inspect.getfullargspec(custom_layer.__init__)[0][1:]
383
394
  call_args = inspect.getfullargspec(custom_layer.call)[0][1:]
@@ -490,7 +501,3 @@ class LeapBinder:
490
501
 
491
502
  def set_batch_size_to_validate(self, batch_size: int) -> None:
492
503
  self.batch_size_to_validate = batch_size
493
-
494
-
495
-
496
-
@@ -1,6 +1,6 @@
1
1
  # mypy: ignore-errors
2
2
 
3
- from typing import Optional, Union, Callable, List
3
+ from typing import Optional, Union, Callable, List, Dict
4
4
 
5
5
  import numpy as np
6
6
  import numpy.typing as npt
@@ -15,18 +15,18 @@ from code_loader.contract.visualizer_classes import LeapImage, LeapImageMask, Le
15
15
  LeapHorizontalBar, LeapImageWithBBox, LeapImageWithHeatmap
16
16
 
17
17
 
18
- def tensorleap_custom_metric(name: str, direction: Optional[MetricDirection] = MetricDirection.Downward):
19
- def decorating_function(
20
- user_function: Union[CustomCallableInterfaceMultiArgs,
21
- CustomMultipleReturnCallableInterfaceMultiArgs,
22
- ConfusionMatrixCallableInterfaceMultiArgs]
23
- ):
18
+ def tensorleap_custom_metric(name: str,
19
+ direction: Union[MetricDirection, Dict[str, MetricDirection]] = MetricDirection.Downward,
20
+ compute_insights: Union[bool, Dict[str, bool]] = True):
21
+ def decorating_function(user_function: Union[CustomCallableInterfaceMultiArgs,
22
+ CustomMultipleReturnCallableInterfaceMultiArgs,
23
+ ConfusionMatrixCallableInterfaceMultiArgs]):
24
24
  for metric_handler in leap_binder.setup_container.metrics:
25
25
  if metric_handler.metric_handler_data.name == name:
26
26
  raise Exception(f'Metric with name {name} already exists. '
27
27
  f'Please choose another')
28
28
 
29
- leap_binder.add_custom_metric(user_function, name, direction)
29
+ leap_binder.add_custom_metric(user_function, name, direction, compute_insights)
30
30
 
31
31
  def _validate_input_args(*args, **kwargs) -> None:
32
32
  for i, arg in enumerate(args):
@@ -76,6 +76,19 @@ def tensorleap_custom_metric(name: str, direction: Optional[MetricDirection] = M
76
76
  (f'tensorleap_custom_metric validation failed: '
77
77
  f'Keys in the return dict should be of type str. Got {type(key)}.')
78
78
  _validate_single_metric(value)
79
+
80
+ if isinstance(direction, dict):
81
+ for direction_key in direction:
82
+ assert direction_key in result, \
83
+ (f'tensorleap_custom_metric validation failed: '
84
+ f'Keys in the direction mapping should be part of result keys. Got key {direction_key}.')
85
+
86
+ if isinstance(compute_insights, dict):
87
+ for ci_key in compute_insights:
88
+ assert ci_key in result, \
89
+ (f'tensorleap_custom_metric validation failed: '
90
+ f'Keys in the compute_insights mapping should be part of result keys. Got key {ci_key}.')
91
+
79
92
  else:
80
93
  _validate_single_metric(result)
81
94
 
@@ -356,15 +369,15 @@ def tensorleap_custom_loss(name: str):
356
369
  f'Element #{y} of list should be a numpy array. Got {type(elem)}.')
357
370
  else:
358
371
  assert isinstance(arg, valid_types), (f'tensorleap_custom_loss validation failed: '
359
- f'Argument #{i} should be a numpy array. Got {type(arg)}.')
372
+ f'Argument #{i} should be a numpy array. Got {type(arg)}.')
360
373
  for _arg_name, arg in kwargs.items():
361
374
  if isinstance(arg, list):
362
375
  for y, elem in enumerate(arg):
363
- assert isinstance(elem,valid_types), (f'tensorleap_custom_loss validation failed: '
364
- f'Element #{y} of list should be a numpy array. Got {type(elem)}.')
376
+ assert isinstance(elem, valid_types), (f'tensorleap_custom_loss validation failed: '
377
+ f'Element #{y} of list should be a numpy array. Got {type(elem)}.')
365
378
  else:
366
379
  assert isinstance(arg, valid_types), (f'tensorleap_custom_loss validation failed: '
367
- f'Argument #{_arg_name} should be a numpy array. Got {type(arg)}.')
380
+ f'Argument #{_arg_name} should be a numpy array. Got {type(arg)}.')
368
381
 
369
382
  def _validate_result(result):
370
383
  assert isinstance(result, valid_types), \
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "code-loader"
3
- version = "1.0.70.dev2"
3
+ version = "1.0.72"
4
4
  description = ""
5
5
  authors = ["dorhar <doron.harnoy@tensorleap.ai>"]
6
6
  license = "MIT"
File without changes