code-loader 1.0.109__py3-none-any.whl → 1.0.110__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.

@@ -16,12 +16,18 @@ from code_loader.contract.visualizer_classes import LeapImage, LeapImageMask, Le
16
16
  LeapHorizontalBar, LeapImageWithBBox, LeapImageWithHeatmap
17
17
  from code_loader.inner_leap_binder.leapbinder import mapping_runtime_mode_env_var_mame
18
18
 
19
-
19
+ import inspect
20
+ import functools
20
21
 
21
22
  _called_from_inside_tl_decorator = 0
22
23
 
24
+
23
25
  def _add_mapping_connection(user_unique_name, connection_destinations, arg_names, name, node_mapping_type):
26
+ connection_destinations = [connection_destination for connection_destination in connection_destinations
27
+ if not isinstance(connection_destination, SamplePreprocessResponse)]
28
+
24
29
  main_node_mapping = NodeMapping(name, node_mapping_type, user_unique_name, arg_names=arg_names)
30
+
25
31
  node_inputs = {}
26
32
  for arg_name, destination in zip(arg_names, connection_destinations):
27
33
  node_inputs[arg_name] = destination.node_mapping
@@ -34,12 +40,10 @@ def _add_mapping_connections(connects_to, arg_names, node_mapping_type, name):
34
40
  _add_mapping_connection(user_unique_name, connection_destinations, arg_names, name, node_mapping_type)
35
41
 
36
42
 
37
-
38
43
  def integration_test():
39
44
  def decorating_function(integration_test_function: Callable):
40
45
  leap_binder.integration_test_func = integration_test_function
41
46
 
42
-
43
47
  def inner(*args, **kwargs):
44
48
  ret = integration_test_function(*args, **kwargs)
45
49
 
@@ -53,17 +57,11 @@ def integration_test():
53
57
  if mapping_runtime_mode_env_var_mame in os.environ:
54
58
  del os.environ[mapping_runtime_mode_env_var_mame]
55
59
 
56
-
57
60
  return inner
58
61
 
59
62
  return decorating_function
60
63
 
61
64
 
62
-
63
-
64
-
65
-
66
-
67
65
  def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]] = None):
68
66
  for i, prediction_type in enumerate(prediction_types):
69
67
  leap_binder.add_prediction(prediction_type.name, prediction_type.labels, prediction_type.channel_dim, i)
@@ -76,7 +74,8 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
76
74
  class ModelPlaceholder:
77
75
  def __init__(self):
78
76
  self.model = load_model_func()
79
- #keras interface
77
+
78
+ # keras interface
80
79
  def __call__(self, arg):
81
80
  ret = self.model(arg)
82
81
  return ret.numpy()
@@ -85,10 +84,8 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
85
84
  def run(self, output_names, input_dict):
86
85
  return self.model.run(output_names, input_dict)
87
86
 
88
-
89
87
  return ModelPlaceholder()
90
88
 
91
-
92
89
  def mapping_inner():
93
90
  class ModelOutputPlaceholder:
94
91
  def __init__(self):
@@ -103,7 +100,7 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
103
100
  return ret
104
101
 
105
102
  class ModelPlaceholder:
106
- #keras interface
103
+ # keras interface
107
104
  def __call__(self, arg):
108
105
  if isinstance(arg, list):
109
106
  for i, elem in enumerate(arg):
@@ -125,9 +122,6 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
125
122
 
126
123
  return ModelPlaceholder()
127
124
 
128
-
129
-
130
-
131
125
  def final_inner():
132
126
  if os.environ.get(mapping_runtime_mode_env_var_mame):
133
127
  return mapping_inner()
@@ -139,14 +133,13 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
139
133
  return decorating_function
140
134
 
141
135
 
142
-
143
136
  def tensorleap_custom_metric(name: str,
144
137
  direction: Union[MetricDirection, Dict[str, MetricDirection]] = MetricDirection.Downward,
145
138
  compute_insights: Optional[Union[bool, Dict[str, bool]]] = None,
146
139
  connects_to=None):
147
140
  def decorating_function(user_function: Union[CustomCallableInterfaceMultiArgs,
148
- CustomMultipleReturnCallableInterfaceMultiArgs,
149
- ConfusionMatrixCallableInterfaceMultiArgs]):
141
+ CustomMultipleReturnCallableInterfaceMultiArgs,
142
+ ConfusionMatrixCallableInterfaceMultiArgs]):
150
143
  for metric_handler in leap_binder.setup_container.metrics:
151
144
  if metric_handler.metric_handler_data.name == name:
152
145
  raise Exception(f'Metric with name {name} already exists. '
@@ -185,7 +178,8 @@ def tensorleap_custom_metric(name: str,
185
178
  f'{supported_types_message}Got List[List[{type(single_metric_result[0][0])}]].'
186
179
  else:
187
180
  assert isinstance(single_metric_result[0], (
188
- float, int, type(None))), f'{supported_types_message}Got List[{type(single_metric_result[0])}].'
181
+ float, int,
182
+ type(None))), f'{supported_types_message}Got List[{type(single_metric_result[0])}].'
189
183
  else:
190
184
  assert isinstance(single_metric_result,
191
185
  np.ndarray), f'{supported_types_message}Got {type(single_metric_result)}.'
@@ -227,6 +221,7 @@ def tensorleap_custom_metric(name: str,
227
221
  (f'tensorleap_custom_metric validation failed: '
228
222
  f'compute_insights should be boolean. Got {type(compute_insights)}.')
229
223
 
224
+ @functools.wraps(user_function)
230
225
  def inner_without_validate(*args, **kwargs):
231
226
  global _called_from_inside_tl_decorator
232
227
  _called_from_inside_tl_decorator += 1
@@ -238,6 +233,11 @@ def tensorleap_custom_metric(name: str,
238
233
 
239
234
  return result
240
235
 
236
+ try:
237
+ inner_without_validate.__signature__ = inspect.signature(user_function)
238
+ except (TypeError, ValueError):
239
+ pass
240
+
241
241
  leap_binder.add_custom_metric(inner_without_validate, name, direction, compute_insights)
242
242
 
243
243
  if connects_to is not None:
@@ -260,7 +260,7 @@ def tensorleap_custom_metric(name: str,
260
260
  ordered_connections = [kwargs[n] for n in mapping_inner.arg_names if n in kwargs]
261
261
  ordered_connections = list(args) + ordered_connections
262
262
  _add_mapping_connection(user_unique_name, ordered_connections, mapping_inner.arg_names,
263
- mapping_inner.name, NodeMappingType.Metric)
263
+ mapping_inner.name, NodeMappingType.Metric)
264
264
 
265
265
  return None
266
266
 
@@ -273,8 +273,6 @@ def tensorleap_custom_metric(name: str,
273
273
  else:
274
274
  return inner(*args, **kwargs)
275
275
 
276
-
277
-
278
276
  return final_inner
279
277
 
280
278
  return decorating_function
@@ -323,7 +321,7 @@ def tensorleap_custom_visualizer(name: str, visualizer_type: LeapDataType,
323
321
  (f'tensorleap_custom_visualizer validation failed: '
324
322
  f'The return type should be {result_type_map[visualizer_type]}. Got {type(result)}.')
325
323
 
326
-
324
+ @functools.wraps(user_function)
327
325
  def inner_without_validate(*args, **kwargs):
328
326
  global _called_from_inside_tl_decorator
329
327
  _called_from_inside_tl_decorator += 1
@@ -335,6 +333,11 @@ def tensorleap_custom_visualizer(name: str, visualizer_type: LeapDataType,
335
333
 
336
334
  return result
337
335
 
336
+ try:
337
+ inner_without_validate.__signature__ = inspect.signature(user_function)
338
+ except (TypeError, ValueError):
339
+ pass
340
+
338
341
  leap_binder.set_visualizer(inner_without_validate, name, visualizer_type, heatmap_function)
339
342
 
340
343
  if connects_to is not None:
@@ -349,7 +352,6 @@ def tensorleap_custom_visualizer(name: str, visualizer_type: LeapDataType,
349
352
  _validate_result(result)
350
353
  return result
351
354
 
352
-
353
355
  def mapping_inner(*args, **kwargs):
354
356
  user_unique_name = mapping_inner.name
355
357
  if 'user_unique_name' in kwargs:
@@ -423,7 +425,6 @@ def tensorleap_metadata(
423
425
 
424
426
  return result
425
427
 
426
-
427
428
  leap_binder.set_metadata(inner_without_validate, name, metadata_type)
428
429
 
429
430
  def inner(sample_id, preprocess_response):
@@ -477,7 +478,9 @@ def tensorleap_preprocess():
477
478
 
478
479
  return decorating_function
479
480
 
480
- def tensorleap_element_instance_preprocess(instance_mask_encoder: Callable[[str, PreprocessResponse], List[ElementInstance]]):
481
+
482
+ def tensorleap_element_instance_preprocess(
483
+ instance_mask_encoder: Callable[[str, PreprocessResponse], List[ElementInstance]]):
481
484
  def decorating_function(user_function: Callable[[], List[PreprocessResponse]]):
482
485
  def user_function_instance() -> List[PreprocessResponse]:
483
486
  result = user_function()
@@ -505,6 +508,7 @@ def tensorleap_element_instance_preprocess(instance_mask_encoder: Callable[[str,
505
508
 
506
509
  def builtin_instance_metadata(idx: str, preprocess: PreprocessResponse) -> Dict[str, str]:
507
510
  return {'is_instance': '0', 'original_sample_id': idx, 'instance_name': 'none'}
511
+
508
512
  leap_binder.set_preprocess(user_function_instance)
509
513
  leap_binder.set_metadata(builtin_instance_metadata, "builtin_instance_metadata")
510
514
 
@@ -525,7 +529,6 @@ def tensorleap_element_instance_preprocess(instance_mask_encoder: Callable[[str,
525
529
  (f'tensorleap_element_instance_preprocess validation failed: '
526
530
  f'The return list should not contain duplicate PreprocessResponse objects.')
527
531
 
528
-
529
532
  def inner(*args, **kwargs):
530
533
  if os.environ.get(mapping_runtime_mode_env_var_mame):
531
534
  return [None, None, None, None]
@@ -598,7 +601,6 @@ def tensorleap_instances_masks_encoder(name: str):
598
601
 
599
602
  leap_binder.set_instance_masks(inner_without_validate, name)
600
603
 
601
-
602
604
  def inner(sample_id, preprocess_response):
603
605
  if os.environ.get(mapping_runtime_mode_env_var_mame):
604
606
  return None
@@ -612,7 +614,6 @@ def tensorleap_instances_masks_encoder(name: str):
612
614
 
613
615
  return inner
614
616
 
615
-
616
617
  return decorating_function
617
618
 
618
619
 
@@ -663,10 +664,10 @@ def tensorleap_input_encoder(name: str, channel_dim=-1, model_input_index=None):
663
664
  node_mapping_type = NodeMappingType(f'Input{str(model_input_index)}')
664
665
  inner.node_mapping = NodeMapping(name, node_mapping_type)
665
666
 
666
-
667
667
  def mapping_inner(sample_id, preprocess_response):
668
668
  class TempMapping:
669
669
  pass
670
+
670
671
  ret = TempMapping()
671
672
  ret.node_mapping = mapping_inner.node_mapping
672
673
 
@@ -730,6 +731,7 @@ def tensorleap_gt_encoder(name: str):
730
731
  def mapping_inner(sample_id, preprocess_response):
731
732
  class TempMapping:
732
733
  pass
734
+
733
735
  ret = TempMapping()
734
736
  ret.node_mapping = mapping_inner.node_mapping
735
737
 
@@ -757,7 +759,6 @@ def tensorleap_custom_loss(name: str, connects_to=None):
757
759
  raise Exception(f'Custom loss with name {name} already exists. '
758
760
  f'Please choose another')
759
761
 
760
-
761
762
  valid_types = (np.ndarray, SamplePreprocessResponse)
762
763
  try:
763
764
  import tensorflow as tf
@@ -789,6 +790,7 @@ def tensorleap_custom_loss(name: str, connects_to=None):
789
790
  (f'tensorleap_custom_loss validation failed: '
790
791
  f'The return type should be a numpy array. Got {type(result)}.')
791
792
 
793
+ @functools.wraps(user_function)
792
794
  def inner_without_validate(*args, **kwargs):
793
795
  global _called_from_inside_tl_decorator
794
796
  _called_from_inside_tl_decorator += 1
@@ -800,6 +802,11 @@ def tensorleap_custom_loss(name: str, connects_to=None):
800
802
 
801
803
  return result
802
804
 
805
+ try:
806
+ inner_without_validate.__signature__ = inspect.signature(user_function)
807
+ except (TypeError, ValueError):
808
+ pass
809
+
803
810
  leap_binder.add_custom_loss(inner_without_validate, name)
804
811
 
805
812
  if connects_to is not None:
@@ -826,7 +833,8 @@ def tensorleap_custom_loss(name: str, connects_to=None):
826
833
 
827
834
  return None
828
835
 
829
- mapping_inner.arg_names = leap_binder.setup_container.custom_loss_handlers[-1].custom_loss_handler_data.arg_names
836
+ mapping_inner.arg_names = leap_binder.setup_container.custom_loss_handlers[
837
+ -1].custom_loss_handler_data.arg_names
830
838
  mapping_inner.name = name
831
839
 
832
840
  def final_inner(*args, **kwargs):
@@ -838,7 +846,6 @@ def tensorleap_custom_loss(name: str, connects_to=None):
838
846
  final_inner.arg_names = leap_binder.setup_container.custom_loss_handlers[-1].custom_loss_handler_data.arg_names
839
847
  final_inner.name = name
840
848
 
841
-
842
849
  return final_inner
843
850
 
844
851
  return decorating_function
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.109
3
+ Version: 1.0.110
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -21,7 +21,7 @@ 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=0iHVHxC2NjfH7F0vQFVGy1e0llgKEyUHUHh3DdtqL70,32602
24
- code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=DOIKYxB_hdnSYq1sgh9dyoNtJA9VJEfECh1UBpNY4io,40175
24
+ code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=wjtk3TflrjJ8Y-OeuedVBD-09ZuOjIKGUjL7sMBU0fQ,41017
25
25
  code_loader/leaploader.py,sha256=fxf2CrWPeWfJYVoNg-Lue7RSvosuZO35FjRrDfrny5I,29363
26
26
  code_loader/leaploaderbase.py,sha256=lKdw2pd6H9hFsxVmc7jJMoZd_vlG5He1ooqT-cR_yq8,4496
27
27
  code_loader/plot_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -30,7 +30,7 @@ code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6Lz
30
30
  code_loader/utils.py,sha256=_j8b60pimoNAvWMRj7hEkkT6C76qES6cZoBFHpXHMxA,2698
31
31
  code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
32
  code_loader/visualizers/default_visualizers.py,sha256=onRnLE_TXfgLN4o52hQIOOhUcFexGlqJ3xSpQDVLuZM,2604
33
- code_loader-1.0.109.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
34
- code_loader-1.0.109.dist-info/METADATA,sha256=L-sEWDMx-JKWTgwNSxY2MH4MSbe6PRZIPWnEUuwPrzY,850
35
- code_loader-1.0.109.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
36
- code_loader-1.0.109.dist-info/RECORD,,
33
+ code_loader-1.0.110.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
34
+ code_loader-1.0.110.dist-info/METADATA,sha256=7tcurDDWQrnd7D7H6DHn3JlqqEQzPcNV6YJ7dhX4BrE,850
35
+ code_loader-1.0.110.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
36
+ code_loader-1.0.110.dist-info/RECORD,,