code-loader 1.0.121.dev2__py3-none-any.whl → 1.0.123__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.

Potentially problematic release.


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

@@ -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, int], Optional[ElementInstance]]
75
+ InstanceLengthCallableInterface = Callable[[Union[int, str], PreprocessResponse], int]
76
+
77
77
 
78
78
  MetadataSectionCallableInterface = Union[
79
79
  Callable[[Union[int, str], PreprocessResponse], int],
@@ -257,6 +257,6 @@ class DatasetSample:
257
257
  metadata_is_none: Dict[str, bool]
258
258
  index: Union[int, str]
259
259
  state: DataStateEnum
260
- instance_masks: Optional[Dict[str, List[ElementInstance]]] = None
261
260
  custom_latent_space: Optional[npt.NDArray[np.float32]] = None
261
+ instance_masks: Optional[Dict[str, ElementInstance]] = None
262
262
 
@@ -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
@@ -529,29 +530,24 @@ def tensorleap_preprocess():
529
530
 
530
531
 
531
532
  def tensorleap_element_instance_preprocess(
532
- instance_mask_encoder: Callable[[str, PreprocessResponse], List[ElementInstance]]):
533
+ instance_length_encoder: InstanceLengthCallableInterface):
533
534
  def decorating_function(user_function: Callable[[], List[PreprocessResponse]]):
534
535
  def user_function_instance() -> List[PreprocessResponse]:
535
536
  result = user_function()
536
537
  for preprocess_response in result:
537
538
  sample_ids_to_instance_mappings = {}
538
539
  instance_to_sample_ids_mappings = {}
539
- instance_ids_to_names = {}
540
540
  all_sample_ids = preprocess_response.sample_ids.copy()
541
541
  for sample_id in preprocess_response.sample_ids:
542
- instances_masks = instance_mask_encoder(sample_id, preprocess_response)
543
- instances_ids = [f'{sample_id}_{instance_id}' for instance_id in range(len(instances_masks))]
542
+ instances_length = instance_length_encoder(sample_id, preprocess_response)
543
+ instances_ids = [f'{sample_id}_{instance_id}' for instance_id in range(instances_length)]
544
544
  sample_ids_to_instance_mappings[sample_id] = instances_ids
545
545
  instance_to_sample_ids_mappings[sample_id] = sample_id
546
- instance_names = [instance.name for instance in instances_masks]
547
- instance_ids_to_names[sample_id] = 'none'
548
- for instance_id, instance_name in zip(instances_ids, instance_names):
546
+ for instance_id in instances_ids:
549
547
  instance_to_sample_ids_mappings[instance_id] = sample_id
550
- instance_ids_to_names[instance_id] = instance_name
551
548
  all_sample_ids.extend(instances_ids)
552
549
  preprocess_response.sample_ids_to_instance_mappings = sample_ids_to_instance_mappings
553
550
  preprocess_response.instance_to_sample_ids_mappings = instance_to_sample_ids_mappings
554
- preprocess_response.instance_ids_to_names = instance_ids_to_names
555
551
  preprocess_response.sample_ids = all_sample_ids
556
552
  return result
557
553
 
@@ -620,7 +616,7 @@ def tensorleap_unlabeled_preprocess():
620
616
 
621
617
  def tensorleap_instances_masks_encoder(name: str):
622
618
  def decorating_function(user_function: InstanceCallableInterface):
623
- def _validate_input_args(sample_id: str, preprocess_response: PreprocessResponse):
619
+ def _validate_input_args(sample_id: str, preprocess_response: PreprocessResponse, instance_id: int):
624
620
  assert isinstance(sample_id, str), \
625
621
  (f'tensorleap_instances_masks_encoder validation failed: '
626
622
  f'Argument sample_id should be str. Got {type(sample_id)}.')
@@ -631,18 +627,21 @@ def tensorleap_instances_masks_encoder(name: str):
631
627
  (f'tensorleap_instances_masks_encoder validation failed: '
632
628
  f'Argument sample_id should be as the same type as defined in the preprocess response '
633
629
  f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
630
+ assert isinstance(instance_id, int), \
631
+ (f'tensorleap_instances_masks_encoder validation failed: '
632
+ f'Argument instance_id should be int. Got {type(instance_id)}.')
634
633
 
635
634
  def _validate_result(result):
636
- assert isinstance(result, list), \
635
+ assert isinstance(result, ElementInstance) or (result is None), \
637
636
  (f'tensorleap_instances_masks_encoder validation failed: '
638
- f'Unsupported return type. Should be a numpy array. Got {type(result)}.')
637
+ f'Unsupported return type. Should be a ElementInstance or None. Got {type(result)}.')
639
638
 
640
- def inner_without_validate(sample_id, preprocess_response):
639
+ def inner_without_validate(sample_id, preprocess_response, instance_id):
641
640
  global _called_from_inside_tl_decorator
642
641
  _called_from_inside_tl_decorator += 1
643
642
 
644
643
  try:
645
- result = user_function(sample_id, preprocess_response)
644
+ result = user_function(sample_id, preprocess_response, instance_id)
646
645
  finally:
647
646
  _called_from_inside_tl_decorator -= 1
648
647
 
@@ -650,6 +649,51 @@ def tensorleap_instances_masks_encoder(name: str):
650
649
 
651
650
  leap_binder.set_instance_masks(inner_without_validate, name)
652
651
 
652
+ def inner(sample_id, preprocess_response, instance_id):
653
+ if os.environ.get(mapping_runtime_mode_env_var_mame):
654
+ return None
655
+
656
+ _validate_input_args(sample_id, preprocess_response, instance_id)
657
+
658
+ result = inner_without_validate(sample_id, preprocess_response, instance_id)
659
+
660
+ _validate_result(result)
661
+ return result
662
+
663
+ return inner
664
+
665
+ return decorating_function
666
+
667
+ def tensorleap_instances_length_encoder(name: str):
668
+ def decorating_function(user_function: InstanceLengthCallableInterface):
669
+ def _validate_input_args(sample_id: str, preprocess_response: PreprocessResponse):
670
+ assert isinstance(sample_id, str), \
671
+ (f'tensorleap_instances_length_encoder validation failed: '
672
+ f'Argument sample_id should be str. Got {type(sample_id)}.')
673
+ assert isinstance(preprocess_response, PreprocessResponse), \
674
+ (f'tensorleap_instances_length_encoder validation failed: '
675
+ f'Argument preprocess_response should be a PreprocessResponse. Got {type(preprocess_response)}.')
676
+ assert type(sample_id) == preprocess_response.sample_id_type, \
677
+ (f'tensorleap_instances_length_encoder validation failed: '
678
+ f'Argument sample_id should be as the same type as defined in the preprocess response '
679
+ f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
680
+
681
+ def _validate_result(result):
682
+ assert isinstance(result, int), \
683
+ (f'tensorleap_instances_length_encoder validation failed: '
684
+ f'Unsupported return type. Should be a int. Got {type(result)}.')
685
+
686
+ def inner_without_validate(sample_id, preprocess_response):
687
+ global _called_from_inside_tl_decorator
688
+ _called_from_inside_tl_decorator += 1
689
+
690
+ try:
691
+ result = user_function(sample_id, preprocess_response)
692
+ finally:
693
+ _called_from_inside_tl_decorator -= 1
694
+
695
+ return result
696
+
653
697
  def inner(sample_id, preprocess_response):
654
698
  if os.environ.get(mapping_runtime_mode_env_var_mame):
655
699
  return None
@@ -665,7 +709,6 @@ def tensorleap_instances_masks_encoder(name: str):
665
709
 
666
710
  return decorating_function
667
711
 
668
-
669
712
  def tensorleap_input_encoder(name: str, channel_dim=-1, model_input_index=None):
670
713
  def decorating_function(user_function: SectionCallableInterface):
671
714
  for input_handler in leap_binder.setup_container.inputs:
code_loader/leaploader.py CHANGED
@@ -157,7 +157,7 @@ class LeapLoader(LeapLoaderBase):
157
157
  for prediction_type in setup.prediction_types
158
158
  }
159
159
 
160
- def get_sample(self, state: DataStateEnum, sample_id: Union[int, str]) -> DatasetSample:
160
+ def get_sample(self, state: DataStateEnum, sample_id: Union[int, str], instance_id: int = None) -> DatasetSample:
161
161
  self.exec_script()
162
162
  preprocess_result = self._preprocess_result()
163
163
  if state == DataStateEnum.unlabeled and sample_id not in preprocess_result[state].sample_ids:
@@ -171,30 +171,17 @@ class LeapLoader(LeapLoaderBase):
171
171
  preprocess_result[
172
172
  state])
173
173
 
174
+ instance_mask = self._get_instances_masks(state, sample_id, instance_id)
174
175
  sample = DatasetSample(inputs=self._get_inputs(state, sample_id),
175
176
  gt=None if state == DataStateEnum.unlabeled else self._get_gt(state, sample_id),
176
177
  metadata=metadata,
177
178
  metadata_is_none=metadata_is_none,
178
179
  index=sample_id,
179
180
  state=state,
180
- custom_latent_space=custom_latent_space)
181
+ custom_latent_space=custom_latent_space,
182
+ instance_masks = instance_mask)
181
183
  return sample
182
184
 
183
- def get_sample_with_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> DatasetSample:
184
- self.exec_script()
185
- preprocess_result = self._preprocess_result()
186
- if state == DataStateEnum.unlabeled and sample_id not in preprocess_result[state].sample_ids:
187
- self._preprocess_result(update_unlabeled_preprocess=True)
188
-
189
- metadata, metadata_is_none = self._get_metadata(state, sample_id)
190
- sample = DatasetSample(inputs=self._get_inputs(state, sample_id),
191
- gt=None if state == DataStateEnum.unlabeled else self._get_gt(state, sample_id),
192
- metadata=metadata,
193
- metadata_is_none=metadata_is_none,
194
- index=sample_id,
195
- state=state,
196
- instance_masks=self._get_instances_masks(state, sample_id))
197
- return sample
198
185
 
199
186
  def check_dataset(self) -> DatasetIntegParseResult:
200
187
  test_payloads: List[DatasetTestResultPayload] = []
@@ -484,13 +471,14 @@ class LeapLoader(LeapLoaderBase):
484
471
  def _get_inputs(self, state: DataStateEnum, sample_id: Union[int, str]) -> Dict[str, npt.NDArray[np.float32]]:
485
472
  return self._get_dataset_handlers(global_leap_binder.setup_container.inputs, state, sample_id)
486
473
 
487
- def _get_instances_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> Dict[
488
- str, List[ElementInstance]]:
474
+ def _get_instances_masks(self, state: DataStateEnum, sample_id: Union[int, str], instance_id: int) -> Optional[Dict[str, ElementInstance]]:
475
+ if instance_id is None:
476
+ return None
489
477
  preprocess_result = self._preprocess_result()
490
478
  preprocess_state = preprocess_result[state]
491
479
  result_agg = {}
492
480
  for handler in global_leap_binder.setup_container.instance_masks:
493
- handler_result = handler.function(sample_id, preprocess_state)
481
+ handler_result = handler.function(sample_id, preprocess_state, instance_id)
494
482
  handler_name = handler.name
495
483
  result_agg[handler_name] = handler_result
496
484
  return result_agg
@@ -570,7 +558,7 @@ class LeapLoader(LeapLoaderBase):
570
558
  self.exec_script()
571
559
  return global_leap_binder.setup_container.custom_latent_space is not None
572
560
 
573
- def get_instances_data(self, state: DataStateEnum) -> Tuple[Dict[str, List[str]], Dict[str, str], Dict[str, str]]:
561
+ def get_instances_data(self, state: DataStateEnum) -> Tuple[Dict[str, List[str]], Dict[str, str]]:
574
562
  """
575
563
  This Method get the data state and returns two dictionaries that holds the mapping of the sample ids to their
576
564
  instances and the other way around and the sample ids array.
@@ -583,4 +571,4 @@ class LeapLoader(LeapLoaderBase):
583
571
  """
584
572
  preprocess_result = self._preprocess_result()
585
573
  preprocess_state = preprocess_result[state]
586
- return preprocess_state.sample_ids_to_instance_mappings, preprocess_state.instance_to_sample_ids_mappings, preprocess_state.instance_ids_to_names
574
+ return preprocess_state.sample_ids_to_instance_mappings, preprocess_state.instance_to_sample_ids_mappings
@@ -61,15 +61,11 @@ class LeapLoaderBase:
61
61
  pass
62
62
 
63
63
  @abstractmethod
64
- def get_sample(self, state: DataStateEnum, sample_id: Union[int, str]) -> DatasetSample:
64
+ def get_sample(self, state: DataStateEnum, sample_id: Union[int, str], instance_id: int = None) -> DatasetSample:
65
65
  pass
66
66
 
67
67
  @abstractmethod
68
- def get_sample_with_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> DatasetSample:
69
- pass
70
-
71
- @abstractmethod
72
- def get_instances_data(self, state: DataStateEnum) -> Tuple[Dict[str, List[str]], Dict[str, str], Dict[str, str]]:
68
+ def get_instances_data(self, state: DataStateEnum) -> Tuple[Dict[str, List[str]], Dict[str, str]]:
73
69
  pass
74
70
 
75
71
  @abstractmethod
@@ -94,10 +94,6 @@ class MixpanelTracker:
94
94
  Args:
95
95
  event_properties: Optional additional properties to include in the event
96
96
  """
97
- # Skip tracking if IS_TENSORLEAP_PLATFORM environment variable is set to 'true'
98
- if os.environ.get('IS_TENSORLEAP_PLATFORM') == 'true':
99
- return
100
-
101
97
  try:
102
98
  distinct_id = self._get_distinct_id()
103
99
 
@@ -110,7 +106,6 @@ class MixpanelTracker:
110
106
  '$device_id': device_id, # Always use device_id for $device_id
111
107
  'python_version': f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
112
108
  'platform': os.name,
113
- 'is_tensorleap_platform': os.environ.get('IS_TENSORLEAP_PLATFORM')
114
109
  }
115
110
 
116
111
  if tensorleap_user_id:
code_loader/utils.py CHANGED
@@ -18,12 +18,12 @@ 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: int) -> Union[ElementInstance, None]:
23
+ result = encoder_function(idx, samples, element_idx)
24
+ if result is None:
25
+ return None
26
+ result.mask = np.array(result.mask)
27
27
  return result
28
28
  return numpy_encoder_function
29
29
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.121.dev2
3
+ Version: 1.0.123
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=outxRQ0M-zMfV0QGVJmAed5qWfRmyD0TV6-goEGAzBw,406
3
3
  code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- code_loader/contract/datasetclasses.py,sha256=dzEzQY5F-uTNB28omGcdZp4cIXWn7NJhNyL0_Y04Yyo,9092
4
+ code_loader/contract/datasetclasses.py,sha256=u0gfDDy02skhFG3ejJOxqxCnykhAcBPGJfv8Bi4s9eQ,8966
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/mapping.py,sha256=e11h_sprwOyE32PcqgRq9JvyahQrPzwqgkhmbQLKLQY,1165
@@ -21,17 +21,17 @@ code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZ
21
21
  code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
22
22
  code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
23
23
  code_loader/inner_leap_binder/leapbinder.py,sha256=Q3D9yVM-GNEJfYRFvMV__BoZbcWOgnWKhrZXAv6Tu7o,33232
24
- code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=r9J_AzZnALJFcyd89Yx_bhsk10QeOfJW1oYp6WmJSIQ,43719
25
- code_loader/leaploader.py,sha256=hM8-7t8rnR5hQjceZqRzLFwUJkg4zEc2jjMlTzqBkc0,30495
26
- code_loader/leaploaderbase.py,sha256=-FAJUQlgDTI4QwJP8lwgwEFVOlnwCRi3-nSvPruCVGU,4587
27
- code_loader/mixpanel_tracker.py,sha256=BlfU3_4ooFJmHFOWdLndR00Kguea3BkWgU_1eIVGYgQ,4905
24
+ code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=39Qv4VZBQ-TP1ToOo_cVcecz5s9Qx3bwj8Y8As9Z3Mw,45723
25
+ code_loader/leaploader.py,sha256=e7oaxXuqNUWvon5h32pzzv7iHxpUbsVnQRWu9VgdTUc,29751
26
+ code_loader/leaploaderbase.py,sha256=LIFcC6xo6V_iiGN3BjibXETu_l84EWM_WIOKAvkfTiM,4458
27
+ code_loader/mixpanel_tracker.py,sha256=U20vQXH8G7XIVXxcpQcVEZSuIwwGnyH5RMHXWZZG8HI,4639
28
28
  code_loader/plot_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  code_loader/plot_functions/plot_functions.py,sha256=xg6Gi4myTN9crq6JtyrhYI38HLXjPVJcbnI7CIy8f7w,14625
30
30
  code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6LznoQIvi4vpo,657
31
- code_loader/utils.py,sha256=_j8b60pimoNAvWMRj7hEkkT6C76qES6cZoBFHpXHMxA,2698
31
+ code_loader/utils.py,sha256=gXENTYpjdidq2dx0gVbXlErPeHoNs-4TYAZbLRe0y2c,2712
32
32
  code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
33
  code_loader/visualizers/default_visualizers.py,sha256=onRnLE_TXfgLN4o52hQIOOhUcFexGlqJ3xSpQDVLuZM,2604
34
- code_loader-1.0.121.dev2.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
35
- code_loader-1.0.121.dev2.dist-info/METADATA,sha256=ohpvgNWxtLKb7_E9ZogY_P7WGwwb0YvU5ToEWxGGV7g,1095
36
- code_loader-1.0.121.dev2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
37
- code_loader-1.0.121.dev2.dist-info/RECORD,,
34
+ code_loader-1.0.123.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
35
+ code_loader-1.0.123.dist-info/METADATA,sha256=xQWMvlruMQ9zO0OVm1Wv26Y3tEXIQq9dEKHa8d6vD-o,1090
36
+ code_loader-1.0.123.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
37
+ code_loader-1.0.123.dist-info/RECORD,,