code-loader 1.0.49.dev101__tar.gz → 1.0.51__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 (29) hide show
  1. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/PKG-INFO +1 -1
  2. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/inner_leap_binder/leapbinder.py +0 -7
  3. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/pyproject.toml +1 -1
  4. code_loader-1.0.49.dev101/code_loader/inner_leap_binder/leapbinder_decorators.py +0 -372
  5. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/LICENSE +0 -0
  6. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/README.md +0 -0
  7. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/__init__.py +0 -0
  8. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/code_inegration_processes_manager.py +0 -0
  9. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/contract/__init__.py +0 -0
  10. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/contract/datasetclasses.py +0 -0
  11. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/contract/enums.py +0 -0
  12. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/contract/exceptions.py +0 -0
  13. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/contract/responsedataclasses.py +0 -0
  14. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/contract/visualizer_classes.py +0 -0
  15. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/__init__.py +0 -0
  16. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/api.py +0 -0
  17. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/cli_config_utils.py +0 -0
  18. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/client.py +0 -0
  19. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/epoch.py +0 -0
  20. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/experiment.py +0 -0
  21. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/experiment_context.py +0 -0
  22. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/types.py +0 -0
  23. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/utils.py +0 -0
  24. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
  25. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/inner_leap_binder/__init__.py +0 -0
  26. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/leaploader.py +0 -0
  27. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/utils.py +0 -0
  28. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/code_loader/visualizers/__init__.py +0 -0
  29. {code_loader-1.0.49.dev101 → code_loader-1.0.51}/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.49.dev101
3
+ Version: 1.0.51
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -37,8 +37,6 @@ class LeapBinder:
37
37
  self._encoder_names: List[str] = list()
38
38
  self._extend_with_default_visualizers()
39
39
 
40
- self.batch_size_to_validate: Optional[int] = None
41
-
42
40
  def _extend_with_default_visualizers(self) -> None:
43
41
  self.set_visualizer(function=default_image_visualizer, name=DefaultVisualizer.Image.value,
44
42
  visualizer_type=LeapDataType.Image)
@@ -474,9 +472,4 @@ class LeapBinder:
474
472
  self.check_handlers(preprocess_result)
475
473
  print("Successful!")
476
474
 
477
- def set_batch_size_to_validate(self, batch_size: int):
478
- self.batch_size_to_validate = batch_size
479
-
480
-
481
-
482
475
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "code-loader"
3
- version = "1.0.49.dev101"
3
+ version = "1.0.51"
4
4
  description = ""
5
5
  authors = ["dorhar <doron.harnoy@tensorleap.ai>"]
6
6
  license = "MIT"
@@ -1,372 +0,0 @@
1
- from typing import Optional, Union, Callable, List
2
-
3
- import numpy as np
4
- import numpy.typing as npt
5
-
6
- from code_loader.contract.datasetclasses import CustomCallableInterfaceMultiArgs, \
7
- CustomMultipleReturnCallableInterfaceMultiArgs, ConfusionMatrixCallableInterfaceMultiArgs, CustomCallableInterface, \
8
- VisualizerCallableInterface, MetadataSectionCallableInterface, PreprocessResponse, SectionCallableInterface
9
- from code_loader.contract.enums import MetricDirection, LeapDataType
10
- from code_loader import leap_binder
11
- from code_loader.contract.visualizer_classes import LeapImage, LeapImageMask, LeapTextMask, LeapText, LeapGraph, \
12
- LeapHorizontalBar, LeapImageWithBBox, LeapImageWithHeatmap
13
-
14
-
15
- def tensorleap_custom_metric(name: str, direction: Optional[MetricDirection] = MetricDirection.Downward):
16
- def decorating_function(
17
- user_function: Union[CustomCallableInterfaceMultiArgs,
18
- CustomMultipleReturnCallableInterfaceMultiArgs,
19
- ConfusionMatrixCallableInterfaceMultiArgs]
20
- ):
21
- for metric_handler in leap_binder.setup_container.metrics:
22
- if metric_handler.name == name:
23
- raise Exception(f'Metric with name {name} already exists. '
24
- f'Please choose another')
25
-
26
- leap_binder.add_custom_metric(user_function, name, direction)
27
-
28
- def _validate_input_args(*args, **kwargs):
29
- for i, arg in enumerate(args):
30
- assert isinstance(arg, np.ndarray), (f'tensorleap_custom_metric validation failed: '
31
- f'Argument #{i} should be a numpy array. Got {type(arg)}.')
32
- if leap_binder.batch_size_to_validate:
33
- assert arg.shape[0] == leap_binder.batch_size_to_validate, \
34
- (f'tensorleap_custom_metric validation failed: Argument #{i} '
35
- f'first dim should be as the batch size. Got {arg.shape[0]} '
36
- f'instead of {leap_binder.batch_size_to_validate}')
37
-
38
- for _arg_name, arg in kwargs.items():
39
- assert isinstance(arg, np.ndarray), (f'tensorleap_custom_metric validation failed: '
40
- f'Argument {_arg_name} should be a numpy array. Got {type(arg)}.')
41
- if leap_binder.batch_size_to_validate:
42
- assert arg.shape[0] == leap_binder.batch_size_to_validate, \
43
- (f'tensorleap_custom_metric validation failed: Argument {_arg_name} '
44
- f'first dim should be as the batch size. Got {arg.shape[0]} '
45
- f'instead of {leap_binder.batch_size_to_validate}')
46
-
47
- def _validate_result(result):
48
- assert isinstance(result, np.ndarray), (f'tensorleap_custom_metric validation failed: '
49
- f'The return type should be a numpy array. Got {type(result)}.')
50
- assert len(result.shape) == 1, (f'tensorleap_custom_metric validation failed: '
51
- f'The return shape should be 1D. Got {len(result.shape)}D.')
52
- if leap_binder.batch_size_to_validate:
53
- assert result.shape[0] == leap_binder.batch_size_to_validate, \
54
- f'tensorleap_custom_metric validation failed: The return len should be as the batch size.'
55
-
56
- def inner(*args, **kwargs):
57
- _validate_input_args(*args, **kwargs)
58
- result = user_function(*args, **kwargs)
59
- _validate_result(result)
60
- return result
61
-
62
- return inner
63
-
64
- return decorating_function
65
-
66
-
67
- def tensorleap_custom_visualizer(name: str, visualizer_type: LeapDataType,
68
- heatmap_function: Optional[Callable[..., npt.NDArray[np.float32]]] = None):
69
- def decorating_function(user_function: VisualizerCallableInterface):
70
- for viz_handler in leap_binder.setup_container.visualizers:
71
- if viz_handler.name == name:
72
- raise Exception(f'Visualizer with name {name} already exists. '
73
- f'Please choose another')
74
-
75
- leap_binder.set_visualizer(user_function, name, visualizer_type, heatmap_function)
76
-
77
- def _validate_input_args(*args, **kwargs):
78
- for i, arg in enumerate(args):
79
- assert isinstance(arg, np.ndarray), (f'tensorleap_custom_visualizer validation failed: '
80
- f'Argument #{i} should be a numpy array. Got {type(arg)}.')
81
- if leap_binder.batch_size_to_validate:
82
- assert arg.shape[0] == leap_binder.batch_size_to_validate, \
83
- (f'tensorleap_custom_visualizer validation failed: Argument #{i} '
84
- f'first dim should be 1. The visualizers will always run with batch size 1. Got {arg.shape[0]}')
85
-
86
- for _arg_name, arg in kwargs.items():
87
- assert isinstance(arg, np.ndarray), (f'tensorleap_custom_visualizer validation failed: '
88
- f'Argument {_arg_name} should be a numpy array. Got {type(arg)}.')
89
- if leap_binder.batch_size_to_validate:
90
- assert arg.shape[0] == leap_binder.batch_size_to_validate, \
91
- (f'tensorleap_custom_visualizer validation failed: Argument {_arg_name} '
92
- f'first dim should be 1. The visualizers will always run with batch size 1. Got {arg.shape[0]}')
93
-
94
- def _validate_result(result):
95
- result_type_map = {
96
- LeapDataType.Image: LeapImage,
97
- LeapDataType.ImageMask: LeapImageMask,
98
- LeapDataType.TextMask: LeapTextMask,
99
- LeapDataType.Text: LeapText,
100
- LeapDataType.Graph: LeapGraph,
101
- LeapDataType.HorizontalBar: LeapHorizontalBar,
102
- LeapDataType.ImageWithBBox: LeapImageWithBBox,
103
- LeapDataType.ImageWithHeatmap: LeapImageWithHeatmap
104
- }
105
- assert isinstance(result, result_type_map[visualizer_type]), \
106
- (f'tensorleap_custom_visualizer validation failed: '
107
- f'The return type should be {result_type_map[visualizer_type]}. Got {type(result)}.')
108
-
109
- def inner(*args, **kwargs):
110
- _validate_input_args(*args, **kwargs)
111
- result = user_function(*args, **kwargs)
112
- _validate_result(result)
113
- return result
114
-
115
- return inner
116
-
117
- return decorating_function
118
-
119
-
120
- def tensorleap_metadata(name: str):
121
- def decorating_function(user_function: MetadataSectionCallableInterface):
122
- for metadata_handler in leap_binder.setup_container.metadata:
123
- if metadata_handler.name == name:
124
- raise Exception(f'Metadata with name {name} already exists. '
125
- f'Please choose another')
126
-
127
- leap_binder.set_metadata(user_function, name)
128
-
129
- def _validate_input_args(sample_id: Union[int, str], preprocess_response: PreprocessResponse):
130
- assert isinstance(sample_id, (int, str)), \
131
- (f'tensorleap_metadata validation failed: '
132
- f'Argument sample_id should be either int or str. Got {type(sample_id)}.')
133
- assert isinstance(preprocess_response, PreprocessResponse), \
134
- (f'tensorleap_metadata validation failed: '
135
- f'Argument preprocess_response should be a PreprocessResponse. Got {type(preprocess_response)}.')
136
- assert type(sample_id) == preprocess_response.sample_id_type, \
137
- (f'tensorleap_metadata validation failed: '
138
- f'Argument sample_id should be as the same type as defined in the preprocess response '
139
- f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
140
-
141
- def _validate_result(result):
142
- supported_result_types = (int, str, bool, float, dict, np.floating,
143
- np.bool_, np.unsignedinteger, np.signedinteger, np.integer)
144
- assert isinstance(result, supported_result_types), \
145
- (f'tensorleap_metadata validation failed: '
146
- f'Unsupported return type. Got {type(result)}. should be any of {str(supported_result_types)}')
147
- if isinstance(result, dict):
148
- for key, value in result.items():
149
- assert isinstance(key, str), \
150
- (f'tensorleap_metadata validation failed: '
151
- f'Keys in the return dict should be of type str. Got {type(key)}.')
152
- assert isinstance(value, supported_result_types), \
153
- (f'tensorleap_metadata validation failed: '
154
- f'Values in the return dict should be of type {str(supported_result_types)}. Got {type(value)}.')
155
-
156
- def inner(sample_id, preprocess_response):
157
- _validate_input_args(sample_id, preprocess_response)
158
- result = user_function(sample_id, preprocess_response)
159
- _validate_result(result)
160
- return result
161
-
162
- return inner
163
-
164
- return decorating_function
165
-
166
-
167
- def tensorleap_preprocess():
168
- def decorating_function(user_function: Callable[[], List[PreprocessResponse]]):
169
- leap_binder.set_preprocess(user_function)
170
-
171
- def _validate_input_args(*args, **kwargs):
172
- assert len(args) == 0 and len(kwargs) == 0, \
173
- (f'tensorleap_preprocess validation failed: '
174
- f'The function should not take any arguments. Got {args} and {kwargs}.')
175
-
176
- def _validate_result(result):
177
- assert isinstance(result, list), \
178
- (f'tensorleap_preprocess validation failed: '
179
- f'The return type should be a list. Got {type(result)}.')
180
- for i, response in enumerate(result):
181
- assert isinstance(response, PreprocessResponse), \
182
- (f'tensorleap_preprocess validation failed: '
183
- f'Element #{i} in the return list should be a PreprocessResponse. Got {type(response)}.')
184
- assert len(set(result)) == len(result), \
185
- (f'tensorleap_preprocess validation failed: '
186
- f'The return list should not contain duplicate PreprocessResponse objects.')
187
-
188
- def inner(*args, **kwargs):
189
- _validate_input_args(*args, **kwargs)
190
- result = user_function()
191
- _validate_result(result)
192
- return result
193
-
194
- return inner
195
-
196
- return decorating_function
197
-
198
-
199
- def tensorleap_unlabeled_preprocess():
200
- def decorating_function(user_function: Callable[[], PreprocessResponse]):
201
- leap_binder.set_unlabeled_data_preprocess(user_function)
202
-
203
- def _validate_input_args(*args, **kwargs):
204
- assert len(args) == 0 and len(kwargs) == 0, \
205
- (f'tensorleap_unlabeled_preprocess validation failed: '
206
- f'The function should not take any arguments. Got {args} and {kwargs}.')
207
-
208
- def _validate_result(result):
209
- assert isinstance(result, PreprocessResponse), \
210
- (f'tensorleap_unlabeled_preprocess validation failed: '
211
- f'The return type should be a PreprocessResponse. Got {type(result)}.')
212
-
213
- def inner(*args, **kwargs):
214
- _validate_input_args(*args, **kwargs)
215
- result = user_function()
216
- _validate_result(result)
217
- return result
218
-
219
- return inner
220
-
221
- return decorating_function
222
-
223
-
224
- def tensorleap_input_encoder(name: str):
225
- def decorating_function(user_function: SectionCallableInterface):
226
- for input_handler in leap_binder.setup_container.inputs:
227
- if input_handler.name == name:
228
- raise Exception(f'Input with name {name} already exists. '
229
- f'Please choose another')
230
-
231
- leap_binder.set_input(user_function, name)
232
-
233
- def _validate_input_args(sample_id: Union[int, str], preprocess_response: PreprocessResponse):
234
- assert isinstance(sample_id, (int, str)), \
235
- (f'tensorleap_input_encoder validation failed: '
236
- f'Argument sample_id should be either int or str. Got {type(sample_id)}.')
237
- assert isinstance(preprocess_response, PreprocessResponse), \
238
- (f'tensorleap_input_encoder validation failed: '
239
- f'Argument preprocess_response should be a PreprocessResponse. Got {type(preprocess_response)}.')
240
- assert type(sample_id) == preprocess_response.sample_id_type, \
241
- (f'tensorleap_input_encoder validation failed: '
242
- f'Argument sample_id should be as the same type as defined in the preprocess response '
243
- f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
244
-
245
- def _validate_result(result):
246
- assert isinstance(result, np.ndarray), \
247
- (f'tensorleap_input_encoder validation failed: '
248
- f'Unsupported return type. Should be a numpy array. Got {type(result)}.')
249
- assert result.dtype == np.float32, \
250
- (f'tensorleap_input_encoder validation failed: '
251
- f'The return type should be a numpy array of type float32. Got {result.dtype}.')
252
-
253
- def inner(sample_id, preprocess_response):
254
- _validate_input_args(sample_id, preprocess_response)
255
- result = user_function(sample_id, preprocess_response)
256
- _validate_result(result)
257
- return result
258
-
259
- return inner
260
-
261
- return decorating_function
262
-
263
-
264
- def tensorleap_gt_encoder(name: str):
265
- def decorating_function(user_function: SectionCallableInterface):
266
- for gt_handler in leap_binder.setup_container.ground_truths:
267
- if gt_handler.name == name:
268
- raise Exception(f'Input with name {name} already exists. '
269
- f'Please choose another')
270
-
271
- leap_binder.set_ground_truth(user_function, name)
272
-
273
- def _validate_input_args(sample_id: Union[int, str], preprocess_response: PreprocessResponse):
274
- assert isinstance(sample_id, (int, str)), \
275
- (f'tensorleap_gt_encoder validation failed: '
276
- f'Argument sample_id should be either int or str. Got {type(sample_id)}.')
277
- assert isinstance(preprocess_response, PreprocessResponse), \
278
- (f'tensorleap_gt_encoder validation failed: '
279
- f'Argument preprocess_response should be a PreprocessResponse. Got {type(preprocess_response)}.')
280
- assert type(sample_id) == preprocess_response.sample_id_type, \
281
- (f'tensorleap_gt_encoder validation failed: '
282
- f'Argument sample_id should be as the same type as defined in the preprocess response '
283
- f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
284
-
285
- def _validate_result(result):
286
- assert isinstance(result, np.ndarray), \
287
- (f'tensorleap_gt_encoder validation failed: '
288
- f'Unsupported return type. Should be a numpy array. Got {type(result)}.')
289
- assert result.dtype == np.float32, \
290
- (f'tensorleap_gt_encoder validation failed: '
291
- f'The return type should be a numpy array of type float32. Got {result.dtype}.')
292
-
293
- def inner(sample_id, preprocess_response):
294
- _validate_input_args(sample_id, preprocess_response)
295
- result = user_function(sample_id, preprocess_response)
296
- _validate_result(result)
297
- return result
298
-
299
- return inner
300
-
301
- return decorating_function
302
-
303
-
304
- def tensorleap_custom_loss(name: str):
305
- def decorating_function(user_function: CustomCallableInterface):
306
- for loss_handler in leap_binder.setup_container.custom_loss_handlers:
307
- if loss_handler.name == name:
308
- raise Exception(f'Input with name {name} already exists. '
309
- f'Please choose another')
310
-
311
- leap_binder.add_custom_loss(user_function, name)
312
-
313
- def _validate_input_args(*args, **kwargs):
314
- try:
315
- import tensorflow as tf
316
- except ImportError:
317
- raise Exception('the input arguments of the custom loss function should be tensorflow tensors')
318
-
319
- for i, arg in enumerate(args):
320
- assert isinstance(arg, tf.Tensor), (f'tensorleap_custom_loss validation failed: '
321
- f'Argument #{i} should be a tensorflow tensor. Got {type(arg)}.')
322
- for _arg_name, arg in kwargs.items():
323
- assert isinstance(arg, tf.Tensor), (f'tensorleap_custom_loss validation failed: '
324
- f'Argument {_arg_name} should be a tensorflow tensor. Got {type(arg)}.')
325
-
326
- def _validate_result(result):
327
- try:
328
- import tensorflow as tf
329
- except ImportError:
330
- raise Exception('the input arguments of the custom loss function should be tensorflow tensors')
331
-
332
- assert isinstance(result, (np.ndarray, tf.Tensor)), \
333
- (f'tensorleap_custom_loss validation failed: '
334
- f'The return type should be a numpy array or a tensorflow tensor. Got {type(result)}.')
335
-
336
- def inner(sample_id, preprocess_response):
337
- _validate_input_args(sample_id, preprocess_response)
338
- result = user_function(sample_id, preprocess_response)
339
- _validate_result(result)
340
- return result
341
-
342
- return inner
343
-
344
- return decorating_function
345
-
346
-
347
- def tensorleap_custom_layer(name: str):
348
- def decorating_function(custom_layer):
349
- for custom_layer_handler in leap_binder.setup_container.custom_layers:
350
- if custom_layer_handler.name == name:
351
- raise Exception(f'Custom Layer with name {name} already exists. '
352
- f'Please choose another')
353
-
354
- try:
355
- import tensorflow as tf
356
- except ImportError:
357
- raise Exception('The custom layer should be inherited from tf.keras.layers.Layer')
358
-
359
- if not issubclass(custom_layer, tf.keras.layers.Layer):
360
- raise Exception('The custom layer should be inherited from tf.keras.layers.Layer')
361
-
362
- leap_binder.set_custom_layer(custom_layer, name)
363
-
364
- return custom_layer
365
-
366
- return decorating_function
367
-
368
-
369
-
370
-
371
-
372
-