code-loader 1.0.94.dev0__py3-none-any.whl → 1.0.94.dev2__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,7 +40,7 @@ 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
-
43
+ instance_id_to_instance_name: Optional[Dict[str, str]] = None # in use only for element instance
44
44
 
45
45
  def __post_init__(self) -> None:
46
46
  def is_valid_string(s: str) -> bool:
@@ -48,6 +48,7 @@ class PreprocessResponse:
48
48
 
49
49
  assert self.sample_ids_to_instance_mappings is None, f"Keep sample_ids_to_instance_mappings None when initializing PreprocessResponse"
50
50
  assert self.instance_to_sample_ids_mappings is None, f"Keep instance_to_sample_ids_mappings None when initializing PreprocessResponse"
51
+ assert self.instance_id_to_instance_name is None, f"Keep instance_id_to_instance_name None when initializing PreprocessResponse"
51
52
 
52
53
  if self.length is not None and self.sample_ids is None:
53
54
  self.sample_ids = [i for i in range(self.length)]
@@ -75,7 +76,6 @@ class PreprocessResponse:
75
76
  class ElementInstance:
76
77
  name: str
77
78
  mask: npt.NDArray[np.float32]
78
- # instance_filling_type: InstanceFillingType # TODO: implement InstanceFillingType
79
79
 
80
80
  SectionCallableInterface = Callable[[Union[int, str], PreprocessResponse], npt.NDArray[np.float32]]
81
81
  InstanceCallableInterface = Callable[[Union[int, str], PreprocessResponse], List[ElementInstance]]
@@ -238,22 +238,14 @@ class LeapBinder:
238
238
 
239
239
  def set_instance_masks(self, function: InstanceCallableInterface, name: str) -> None:
240
240
  """
241
- Set the input handler function.
241
+ Set the instance mask handler function.
242
242
 
243
243
  Args:
244
244
  function (SectionCallableInterface): The input handler function.
245
- name (str): The name of the input section.
246
- channel_dim (int): The dimension of the channels axis
245
+ name (str): The name of the instance mask section.
247
246
 
248
247
  Example:
249
- def input_encoder(subset: PreprocessResponse, index: int) -> np.ndarray:
250
- # Return the processed input data for the given index and given subset response
251
- img_path = subset.`data["images"][idx]
252
- img = read_img(img_path)
253
- img = normalize(img)
254
- return img
255
-
256
- leap_binder.set_input(input_encoder, name='input_encoder', channel_dim=-1)
248
+ leap_binder.set_input(input_encoder, name='input_encoder')
257
249
  """
258
250
  function = to_numpy_return_masks_wrapper(function)
259
251
  self.setup_container.instance_masks.append(ElementInstanceMasksHandler(name, function))
@@ -8,7 +8,7 @@ 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, InstanceCallableInterface
11
+ ConfusionMatrixElement, SamplePreprocessResponse, InstanceCallableInterface, ElementInstance
12
12
  from code_loader.contract.enums import MetricDirection, LeapDataType, DatasetMetadataType
13
13
  from code_loader import leap_binder
14
14
  from code_loader.contract.mapping import NodeMapping, NodeMappingType, NodeConnection
@@ -270,48 +270,54 @@ def tensorleap_preprocess():
270
270
 
271
271
  return decorating_function
272
272
 
273
- def tensorleap_element_instance_preprocess(instance_mask_encoder: Callable[[int, PreprocessResponse], List[PreprocessResponse]]):
273
+ def tensorleap_element_instance_preprocess(instance_mask_encoder: Callable[[int, PreprocessResponse], List[ElementInstance]]):
274
274
  def decorating_function(user_function: Callable[[], List[PreprocessResponse]]):
275
275
  def user_function_instance() -> List[PreprocessResponse]:
276
276
  result = user_function()
277
277
  for preprocess_response in result:
278
278
  sample_ids_to_instance_mappings = {}
279
279
  instance_to_sample_ids_mappings = {}
280
+ instance_id_to_instance_name = {}
280
281
  all_sample_ids = preprocess_response.sample_ids.copy()
281
282
  for sample_id in preprocess_response.sample_ids:
282
283
  instances_masks = instance_mask_encoder(sample_id, preprocess_response)
284
+ instance_names = [instance.name for instance in instances_masks]
283
285
  instances_ids = [f'{sample_id}_{instance_id}' for instance_id in range(len(instances_masks))]
284
286
  sample_ids_to_instance_mappings[sample_id] = instances_ids
285
287
  instance_to_sample_ids_mappings[sample_id] = sample_id
286
- for instance_id in instances_ids:
288
+ instance_id_to_instance_name[sample_id] = None
289
+ for instance_id, instance_name in zip(instances_ids, instance_names):
287
290
  instance_to_sample_ids_mappings[instance_id] = sample_id
291
+ instance_id_to_instance_name[instance_id] = instance_name
288
292
  all_sample_ids.extend(instances_ids)
289
293
  preprocess_response.sample_ids_to_instance_mappings = sample_ids_to_instance_mappings
290
294
  preprocess_response.instance_to_sample_ids_mappings = instance_to_sample_ids_mappings
295
+ preprocess_response.instance_id_to_instance_name = instance_id_to_instance_name
291
296
  preprocess_response.sample_ids = all_sample_ids
292
297
  return result
293
298
 
294
-
295
- def metadata_is_instance(idx: str, preprocess: PreprocessResponse) -> str:
296
- return "0"
299
+ def metadata_is_instance(idx: str, preprocess: PreprocessResponse) -> Dict[str, str]:
300
+ return {'is_instance': '0',
301
+ 'orig_sample_id': preprocess.instance_to_sample_ids_mappings[idx],
302
+ 'instance_name': preprocess.instance_id_to_instance_name[idx]}
297
303
  leap_binder.set_preprocess(user_function_instance)
298
304
  leap_binder.set_metadata(metadata_is_instance, "metadata_is_instance")
299
305
 
300
306
  def _validate_input_args(*args, **kwargs):
301
307
  assert len(args) == 0 and len(kwargs) == 0, \
302
- (f'tensorleap_preprocess validation failed: '
308
+ (f'tensorleap_element_instance_preprocess validation failed: '
303
309
  f'The function should not take any arguments. Got {args} and {kwargs}.')
304
310
 
305
311
  def _validate_result(result):
306
312
  assert isinstance(result, list), \
307
- (f'tensorleap_preprocess validation failed: '
313
+ (f'tensorleap_element_instance_preprocess validation failed: '
308
314
  f'The return type should be a list. Got {type(result)}.')
309
315
  for i, response in enumerate(result):
310
316
  assert isinstance(response, PreprocessResponse), \
311
- (f'tensorleap_preprocess validation failed: '
317
+ (f'tensorleap_element_instance_preprocess validation failed: '
312
318
  f'Element #{i} in the return list should be a PreprocessResponse. Got {type(response)}.')
313
319
  assert len(set(result)) == len(result), \
314
- (f'tensorleap_preprocess validation failed: '
320
+ (f'tensorleap_element_instance_preprocess validation failed: '
315
321
  f'The return list should not contain duplicate PreprocessResponse objects.')
316
322
 
317
323
  def inner(*args, **kwargs):
@@ -354,21 +360,21 @@ def tensorleap_instances_masks_encoder(name: str):
354
360
  def decorating_function(user_function: InstanceCallableInterface):
355
361
  leap_binder.set_instance_masks(user_function, name)
356
362
 
357
- def _validate_input_args(sample_id: Union[int, str], preprocess_response: PreprocessResponse):
358
- assert isinstance(sample_id, (int, str)), \
359
- (f'tensorleap_input_encoder validation failed: '
360
- f'Argument sample_id should be either int or str. Got {type(sample_id)}.')
363
+ def _validate_input_args(sample_id: str, preprocess_response: PreprocessResponse):
364
+ assert isinstance(sample_id, str), \
365
+ (f'tensorleap_instances_masks_encoder validation failed: '
366
+ f'Argument sample_id should be str. Got {type(sample_id)}.')
361
367
  assert isinstance(preprocess_response, PreprocessResponse), \
362
- (f'tensorleap_input_encoder validation failed: '
368
+ (f'tensorleap_instances_masks_encoder validation failed: '
363
369
  f'Argument preprocess_response should be a PreprocessResponse. Got {type(preprocess_response)}.')
364
370
  assert type(sample_id) == preprocess_response.sample_id_type, \
365
- (f'tensorleap_input_encoder validation failed: '
371
+ (f'tensorleap_instances_masks_encoder validation failed: '
366
372
  f'Argument sample_id should be as the same type as defined in the preprocess response '
367
373
  f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
368
374
 
369
375
  def _validate_result(result):
370
376
  assert isinstance(result, list), \
371
- (f'tensorleap_input_encoder validation failed: '
377
+ (f'tensorleap_instances_masks_encoder validation failed: '
372
378
  f'Unsupported return type. Should be a numpy array. Got {type(result)}.')
373
379
 
374
380
  def inner(sample_id, preprocess_response):
code_loader/leaploader.py CHANGED
@@ -164,7 +164,7 @@ class LeapLoader(LeapLoaderBase):
164
164
  metadata_is_none=metadata_is_none,
165
165
  index=sample_id,
166
166
  state=state,
167
- instance_masks=self._get_masks(state, sample_id))
167
+ instance_masks=self._get_instances_masks(state, sample_id))
168
168
  return sample
169
169
 
170
170
  def check_dataset(self) -> DatasetIntegParseResult:
@@ -454,7 +454,7 @@ class LeapLoader(LeapLoaderBase):
454
454
  def _get_inputs(self, state: DataStateEnum, sample_id: Union[int, str]) -> Dict[str, npt.NDArray[np.float32]]:
455
455
  return self._get_dataset_handlers(global_leap_binder.setup_container.inputs, state, sample_id)
456
456
 
457
- def _get_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> Dict[str, List[ElementInstance]]:
457
+ def _get_instances_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> Dict[str, List[ElementInstance]]:
458
458
  preprocess_result = self._preprocess_result()
459
459
  preprocess_state = preprocess_result[state]
460
460
  result_agg = {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.94.dev0
3
+ Version: 1.0.94.dev2
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=vVVc3dmgZ80GLD81MswGIqGEY8KaLr-X60mO9n42RTs,8989
4
+ code_loader/contract/datasetclasses.py,sha256=PT1dMA0FxpzJ75rpc79d_oxn3zJmrdOihKTC46ZEZvI,9139
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
@@ -20,14 +20,14 @@ code_loader/experiment_api/types.py,sha256=MY8xFARHwdVA7p4dxyhD60ShmttgTvb4qdp1o
20
20
  code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZJEqBqc,3304
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
- code_loader/inner_leap_binder/leapbinder.py,sha256=eHnjPfJvYQDQsBM55sf63kI-NC2M-lOB4cwxjYHNTkk,32766
24
- code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=hfT2mdr6SB90vNu42ZxPjgRWaCFuqAqnwAzgb7cWvJI,28955
25
- code_loader/leaploader.py,sha256=K532J4Z8YUjyBpTagJPff4PD0dkuwT9szgBbwBiWwwY,28846
23
+ code_loader/inner_leap_binder/leapbinder.py,sha256=wmCOj_YKbRXqLL1k5Tw_FrcZgfmgnVQcjs2ok6wdlww,32362
24
+ code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=KNbfm8o7F-3ljys5fbVK8NP6mkPSD_itFceGFTWk4kw,29657
25
+ code_loader/leaploader.py,sha256=HPDZb10HPYh18_HjoIYT8ipB5pmVvL5tEI_KFKmHS7g,28866
26
26
  code_loader/leaploaderbase.py,sha256=tpMVEd97675b_var4hvesjN7EgQzoCbPEayNBut6AvI,4551
27
27
  code_loader/utils.py,sha256=_j8b60pimoNAvWMRj7hEkkT6C76qES6cZoBFHpXHMxA,2698
28
28
  code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  code_loader/visualizers/default_visualizers.py,sha256=669lBpLISLO6my5Qcgn1FLDDeZgHumPf252m4KHY4YM,2555
30
- code_loader-1.0.94.dev0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
31
- code_loader-1.0.94.dev0.dist-info/METADATA,sha256=lHGZ-hnVSRRKberKcyTn2it4RTB1QQUz6gdL6sJSNYk,854
32
- code_loader-1.0.94.dev0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
33
- code_loader-1.0.94.dev0.dist-info/RECORD,,
30
+ code_loader-1.0.94.dev2.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
31
+ code_loader-1.0.94.dev2.dist-info/METADATA,sha256=5rh-Eu9KRqvossEgh3kk7iSDstW5JYfVnuo6xAhFFCY,854
32
+ code_loader-1.0.94.dev2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
33
+ code_loader-1.0.94.dev2.dist-info/RECORD,,