code-loader 1.0.111__tar.gz → 1.0.112.dev0__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.

Potentially problematic release.


This version of code-loader might be problematic. Click here for more details.

Files changed (35) hide show
  1. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/PKG-INFO +2 -2
  2. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/contract/datasetclasses.py +4 -4
  3. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/inner_leap_binder/leapbinder_decorators.py +55 -13
  4. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/leaploader.py +6 -6
  5. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/leaploaderbase.py +1 -1
  6. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/utils.py +4 -6
  7. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/pyproject.toml +2 -2
  8. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/LICENSE +0 -0
  9. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/README.md +0 -0
  10. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/__init__.py +0 -0
  11. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/contract/__init__.py +0 -0
  12. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/contract/enums.py +0 -0
  13. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/contract/exceptions.py +0 -0
  14. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/contract/mapping.py +0 -0
  15. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/contract/responsedataclasses.py +0 -0
  16. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/contract/visualizer_classes.py +0 -0
  17. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/default_losses.py +0 -0
  18. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/default_metrics.py +0 -0
  19. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/__init__.py +0 -0
  20. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/api.py +0 -0
  21. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/cli_config_utils.py +0 -0
  22. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/client.py +0 -0
  23. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/epoch.py +0 -0
  24. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/experiment.py +0 -0
  25. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/experiment_context.py +0 -0
  26. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/types.py +0 -0
  27. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/utils.py +0 -0
  28. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
  29. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/inner_leap_binder/__init__.py +0 -0
  30. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/inner_leap_binder/leapbinder.py +0 -0
  31. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/plot_functions/__init__.py +0 -0
  32. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/plot_functions/plot_functions.py +0 -0
  33. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/plot_functions/visualize.py +0 -0
  34. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/visualizers/__init__.py +0 -0
  35. {code_loader-1.0.111 → code_loader-1.0.112.dev0}/code_loader/visualizers/default_visualizers.py +0 -0
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.111
3
+ Version: 1.0.112.dev0
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
7
7
  Author: dorhar
8
8
  Author-email: doron.harnoy@tensorleap.ai
9
- Requires-Python: >=3.8,<=3.12
9
+ Requires-Python: >=3.8,<3.13
10
10
  Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.8
@@ -40,12 +40,10 @@ class PreprocessResponse:
40
40
  sample_id_type: Optional[Union[Type[str], Type[int]]] = None
41
41
  sample_ids_to_instance_mappings: Optional[Dict[str, List[str]]] = None # in use only for element instance
42
42
  instance_to_sample_ids_mappings: Optional[Dict[str, str]] = None # in use only for element instance
43
- instance_ids_to_names: Optional[Dict[str, str]] = None # in use only for element instance
44
43
 
45
44
  def __post_init__(self) -> None:
46
45
  assert self.sample_ids_to_instance_mappings is None, f"Keep sample_ids_to_instance_mappings None when initializing PreprocessResponse"
47
46
  assert self.instance_to_sample_ids_mappings is None, f"Keep instance_to_sample_ids_mappings None when initializing PreprocessResponse"
48
- assert self.instance_ids_to_names is None, f"Keep instance_ids_to_names None when initializing PreprocessResponse"
49
47
 
50
48
  if self.length is not None and self.sample_ids is None:
51
49
  self.sample_ids = [i for i in range(self.length)]
@@ -73,7 +71,9 @@ class ElementInstance:
73
71
  mask: npt.NDArray[np.float32]
74
72
 
75
73
  SectionCallableInterface = Callable[[Union[int, str], PreprocessResponse], npt.NDArray[np.float32]]
76
- InstanceCallableInterface = Callable[[Union[int, str], PreprocessResponse], List[ElementInstance]]
74
+ InstanceCallableInterface = Callable[[Union[int, str], PreprocessResponse, Union[int, str]], ElementInstance]
75
+ InstanceLengthCallableInterface = Callable[[Union[int, str], PreprocessResponse], int]
76
+
77
77
 
78
78
  MetadataSectionCallableInterface = Union[
79
79
  Callable[[Union[int, str], PreprocessResponse], int],
@@ -251,5 +251,5 @@ class DatasetSample:
251
251
  metadata_is_none: Dict[str, bool]
252
252
  index: Union[int, str]
253
253
  state: DataStateEnum
254
- instance_masks: Optional[Dict[str, List[ElementInstance]]] = None
254
+ instance_masks: Optional[Dict[str, ElementInstance]] = None
255
255
 
@@ -8,7 +8,8 @@ import numpy.typing as npt
8
8
  from code_loader.contract.datasetclasses import CustomCallableInterfaceMultiArgs, \
9
9
  CustomMultipleReturnCallableInterfaceMultiArgs, ConfusionMatrixCallableInterfaceMultiArgs, CustomCallableInterface, \
10
10
  VisualizerCallableInterface, MetadataSectionCallableInterface, PreprocessResponse, SectionCallableInterface, \
11
- ConfusionMatrixElement, SamplePreprocessResponse, PredictionTypeHandler, InstanceCallableInterface, ElementInstance
11
+ ConfusionMatrixElement, SamplePreprocessResponse, PredictionTypeHandler, InstanceCallableInterface, ElementInstance, \
12
+ InstanceLengthCallableInterface
12
13
  from code_loader.contract.enums import MetricDirection, LeapDataType, DatasetMetadataType
13
14
  from code_loader import leap_binder
14
15
  from code_loader.contract.mapping import NodeMapping, NodeMappingType, NodeConnection
@@ -480,29 +481,24 @@ def tensorleap_preprocess():
480
481
 
481
482
 
482
483
  def tensorleap_element_instance_preprocess(
483
- instance_mask_encoder: Callable[[str, PreprocessResponse], List[ElementInstance]]):
484
+ instance_length_encoder: InstanceLengthCallableInterface):
484
485
  def decorating_function(user_function: Callable[[], List[PreprocessResponse]]):
485
486
  def user_function_instance() -> List[PreprocessResponse]:
486
487
  result = user_function()
487
488
  for preprocess_response in result:
488
489
  sample_ids_to_instance_mappings = {}
489
490
  instance_to_sample_ids_mappings = {}
490
- instance_ids_to_names = {}
491
491
  all_sample_ids = preprocess_response.sample_ids.copy()
492
492
  for sample_id in preprocess_response.sample_ids:
493
- instances_masks = instance_mask_encoder(sample_id, preprocess_response)
494
- instances_ids = [f'{sample_id}_{instance_id}' for instance_id in range(len(instances_masks))]
493
+ instances_length = instance_length_encoder(sample_id, preprocess_response)
494
+ instances_ids = [f'{sample_id}_{instance_id}' for instance_id in range(instances_length)]
495
495
  sample_ids_to_instance_mappings[sample_id] = instances_ids
496
496
  instance_to_sample_ids_mappings[sample_id] = sample_id
497
- instance_names = [instance.name for instance in instances_masks]
498
- instance_ids_to_names[sample_id] = 'none'
499
- for instance_id, instance_name in zip(instances_ids, instance_names):
497
+ for instance_id in instances_ids:
500
498
  instance_to_sample_ids_mappings[instance_id] = sample_id
501
- instance_ids_to_names[instance_id] = instance_name
502
499
  all_sample_ids.extend(instances_ids)
503
500
  preprocess_response.sample_ids_to_instance_mappings = sample_ids_to_instance_mappings
504
501
  preprocess_response.instance_to_sample_ids_mappings = instance_to_sample_ids_mappings
505
- preprocess_response.instance_ids_to_names = instance_ids_to_names
506
502
  preprocess_response.sample_ids = all_sample_ids
507
503
  return result
508
504
 
@@ -571,7 +567,7 @@ def tensorleap_unlabeled_preprocess():
571
567
 
572
568
  def tensorleap_instances_masks_encoder(name: str):
573
569
  def decorating_function(user_function: InstanceCallableInterface):
574
- def _validate_input_args(sample_id: str, preprocess_response: PreprocessResponse):
570
+ def _validate_input_args(sample_id: str, preprocess_response: PreprocessResponse, instance_id: str):
575
571
  assert isinstance(sample_id, str), \
576
572
  (f'tensorleap_instances_masks_encoder validation failed: '
577
573
  f'Argument sample_id should be str. Got {type(sample_id)}.')
@@ -588,6 +584,53 @@ def tensorleap_instances_masks_encoder(name: str):
588
584
  (f'tensorleap_instances_masks_encoder validation failed: '
589
585
  f'Unsupported return type. Should be a numpy array. Got {type(result)}.')
590
586
 
587
+ def inner_without_validate(sample_id, preprocess_response, instance_id):
588
+ global _called_from_inside_tl_decorator
589
+ _called_from_inside_tl_decorator += 1
590
+
591
+ try:
592
+ result = user_function(sample_id, preprocess_response, instance_id)
593
+ finally:
594
+ _called_from_inside_tl_decorator -= 1
595
+
596
+ return result
597
+
598
+ leap_binder.set_instance_masks(inner_without_validate, name)
599
+
600
+ def inner(sample_id, preprocess_response, instance_id):
601
+ if os.environ.get(mapping_runtime_mode_env_var_mame):
602
+ return None
603
+
604
+ _validate_input_args(sample_id, preprocess_response, instance_id)
605
+
606
+ result = inner_without_validate(sample_id, preprocess_response, instance_id)
607
+
608
+ _validate_result(result)
609
+ return result
610
+
611
+ return inner
612
+
613
+ return decorating_function
614
+
615
+ def tensorleap_instances_length_encoder(name: str):
616
+ def decorating_function(user_function: InstanceLengthCallableInterface):
617
+ def _validate_input_args(sample_id: str, preprocess_response: PreprocessResponse):
618
+ assert isinstance(sample_id, str), \
619
+ (f'tensorleap_instances_length_encoder validation failed: '
620
+ f'Argument sample_id should be str. Got {type(sample_id)}.')
621
+ assert isinstance(preprocess_response, PreprocessResponse), \
622
+ (f'tensorleap_instances_length_encoder validation failed: '
623
+ f'Argument preprocess_response should be a PreprocessResponse. Got {type(preprocess_response)}.')
624
+ assert type(sample_id) == preprocess_response.sample_id_type, \
625
+ (f'tensorleap_instances_length_encoder validation failed: '
626
+ f'Argument sample_id should be as the same type as defined in the preprocess response '
627
+ f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
628
+
629
+ def _validate_result(result):
630
+ assert isinstance(result, list), \
631
+ (f'tensorleap_instances_length_encoder validation failed: '
632
+ f'Unsupported return type. Should be a numpy array. Got {type(result)}.')
633
+
591
634
  def inner_without_validate(sample_id, preprocess_response):
592
635
  global _called_from_inside_tl_decorator
593
636
  _called_from_inside_tl_decorator += 1
@@ -599,7 +642,7 @@ def tensorleap_instances_masks_encoder(name: str):
599
642
 
600
643
  return result
601
644
 
602
- leap_binder.set_instance_masks(inner_without_validate, name)
645
+ # leap_binder.set_instance_masks(inner_without_validate, name). # TODO: do i need this?
603
646
 
604
647
  def inner(sample_id, preprocess_response):
605
648
  if os.environ.get(mapping_runtime_mode_env_var_mame):
@@ -616,7 +659,6 @@ def tensorleap_instances_masks_encoder(name: str):
616
659
 
617
660
  return decorating_function
618
661
 
619
-
620
662
  def tensorleap_input_encoder(name: str, channel_dim=-1, model_input_index=None):
621
663
  def decorating_function(user_function: SectionCallableInterface):
622
664
  for input_handler in leap_binder.setup_container.inputs:
@@ -160,7 +160,7 @@ class LeapLoader(LeapLoaderBase):
160
160
  state=state)
161
161
  return sample
162
162
 
163
- def get_sample_with_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> DatasetSample:
163
+ def get_sample_with_masks(self, state: DataStateEnum, sample_id: Union[int, str], instance_id: Union[int, str]) -> DatasetSample:
164
164
  self.exec_script()
165
165
  preprocess_result = self._preprocess_result()
166
166
  if state == DataStateEnum.unlabeled and sample_id not in preprocess_result[state].sample_ids:
@@ -173,7 +173,7 @@ class LeapLoader(LeapLoaderBase):
173
173
  metadata_is_none=metadata_is_none,
174
174
  index=sample_id,
175
175
  state=state,
176
- instance_masks=self._get_instances_masks(state, sample_id))
176
+ instance_masks=self._get_instances_masks(state, sample_id, instance_id))
177
177
  return sample
178
178
 
179
179
  def check_dataset(self) -> DatasetIntegParseResult:
@@ -466,12 +466,12 @@ class LeapLoader(LeapLoaderBase):
466
466
  def _get_inputs(self, state: DataStateEnum, sample_id: Union[int, str]) -> Dict[str, npt.NDArray[np.float32]]:
467
467
  return self._get_dataset_handlers(global_leap_binder.setup_container.inputs, state, sample_id)
468
468
 
469
- def _get_instances_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> Dict[str, List[ElementInstance]]:
469
+ def _get_instances_masks(self, state: DataStateEnum, sample_id: Union[int, str], instance_id: Union[int, str]) -> Dict[str, ElementInstance]:
470
470
  preprocess_result = self._preprocess_result()
471
471
  preprocess_state = preprocess_result[state]
472
472
  result_agg = {}
473
473
  for handler in global_leap_binder.setup_container.instance_masks:
474
- handler_result = handler.function(sample_id, preprocess_state)
474
+ handler_result = handler.function(sample_id, preprocess_state, instance_id)
475
475
  handler_name = handler.name
476
476
  result_agg[handler_name] = handler_result
477
477
  return result_agg
@@ -545,7 +545,7 @@ class LeapLoader(LeapLoaderBase):
545
545
 
546
546
  return id_type
547
547
 
548
- def get_instances_data(self, state: DataStateEnum) -> Tuple[Dict[str, List[str]], Dict[str, str], Dict[str, str]]:
548
+ def get_instances_data(self, state: DataStateEnum) -> Tuple[Dict[str, List[str]], Dict[str, str]]:
549
549
  """
550
550
  This Method get the data state and returns two dictionaries that holds the mapping of the sample ids to their
551
551
  instances and the other way around and the sample ids array.
@@ -558,4 +558,4 @@ class LeapLoader(LeapLoaderBase):
558
558
  """
559
559
  preprocess_result = self._preprocess_result()
560
560
  preprocess_state = preprocess_result[state]
561
- return preprocess_state.sample_ids_to_instance_mappings, preprocess_state.instance_to_sample_ids_mappings, preprocess_state.instance_ids_to_names
561
+ return preprocess_state.sample_ids_to_instance_mappings, preprocess_state.instance_to_sample_ids_mappings
@@ -65,7 +65,7 @@ class LeapLoaderBase:
65
65
  pass
66
66
 
67
67
  @abstractmethod
68
- def get_sample_with_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> DatasetSample:
68
+ def get_sample_with_masks(self, state: DataStateEnum, sample_id: Union[int, str], instance_id: Union[int, str]) -> DatasetSample:
69
69
  pass
70
70
 
71
71
  @abstractmethod
@@ -18,12 +18,10 @@ def to_numpy_return_wrapper(encoder_function: SectionCallableInterface) -> Secti
18
18
 
19
19
  return numpy_encoder_function
20
20
 
21
- def to_numpy_return_masks_wrapper(encoder_function: InstanceCallableInterface) -> Callable[
22
- [Union[int, str], PreprocessResponse], List[ElementInstance]]:
23
- def numpy_encoder_function(idx: Union[int, str], samples: PreprocessResponse) -> List[ElementInstance]:
24
- result = encoder_function(idx, samples)
25
- for res in result:
26
- res.mask = np.array(res.mask)
21
+ def to_numpy_return_masks_wrapper(encoder_function: InstanceCallableInterface) -> InstanceCallableInterface:
22
+ def numpy_encoder_function(idx: Union[int, str], samples: PreprocessResponse, element_idx: Union[int, str]) -> ElementInstance:
23
+ result = encoder_function(idx, samples, element_idx)
24
+ result.mask = np.array(result.mask)
27
25
  return result
28
26
  return numpy_encoder_function
29
27
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "code-loader"
3
- version = "1.0.111"
3
+ version = "1.0.112.dev0"
4
4
  description = ""
5
5
  authors = ["dorhar <doron.harnoy@tensorleap.ai>"]
6
6
  license = "MIT"
@@ -12,7 +12,7 @@ include = [
12
12
  ]
13
13
 
14
14
  [tool.poetry.dependencies]
15
- python = ">=3.8,<=3.12"
15
+ python = ">=3.8,<3.13"
16
16
  numpy = "^1.22.3"
17
17
  psutil = "^5.9.5"
18
18
  requests = "^2.32.3"