code-loader 1.0.72__py3-none-any.whl → 1.0.72.dev1__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.
- code_loader/contract/datasetclasses.py +6 -1
- code_loader/inner_leap_binder/leapbinder.py +16 -10
- code_loader/inner_leap_binder/leapbinder_decorators.py +2 -16
- code_loader/leaploader.py +15 -4
- code_loader/leaploaderbase.py +4 -1
- {code_loader-1.0.72.dist-info → code_loader-1.0.72.dev1.dist-info}/METADATA +1 -1
- {code_loader-1.0.72.dist-info → code_loader-1.0.72.dev1.dist-info}/RECORD +9 -9
- {code_loader-1.0.72.dist-info → code_loader-1.0.72.dev1.dist-info}/LICENSE +0 -0
- {code_loader-1.0.72.dist-info → code_loader-1.0.72.dev1.dist-info}/WHEEL +0 -0
@@ -133,7 +133,6 @@ class MetricHandlerData:
|
|
133
133
|
name: str
|
134
134
|
arg_names: List[str]
|
135
135
|
direction: Union[None, MetricDirection, Dict[str, MetricDirection]] = MetricDirection.Downward
|
136
|
-
compute_insights: Union[bool, Dict[str, bool]] = True
|
137
136
|
|
138
137
|
|
139
138
|
@dataclass
|
@@ -147,6 +146,12 @@ class RawInputsForHeatmap:
|
|
147
146
|
raw_input_by_vizualizer_arg_name: Dict[str, npt.NDArray[np.float32]]
|
148
147
|
|
149
148
|
|
149
|
+
@dataclass
|
150
|
+
class SamplePreprocessResponse:
|
151
|
+
sample_ids: np.array
|
152
|
+
preprocess_response: PreprocessResponse
|
153
|
+
|
154
|
+
|
150
155
|
@dataclass
|
151
156
|
class VisualizerHandlerData:
|
152
157
|
name: str
|
@@ -10,7 +10,7 @@ from code_loader.contract.datasetclasses import SectionCallableInterface, InputH
|
|
10
10
|
MetadataSectionCallableInterface, UnlabeledDataPreprocessHandler, CustomLayerHandler, MetricHandler, \
|
11
11
|
CustomCallableInterfaceMultiArgs, ConfusionMatrixCallableInterfaceMultiArgs, LeapData, \
|
12
12
|
CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler, custom_latent_space_attribute, \
|
13
|
-
RawInputsForHeatmap, VisualizerHandlerData, MetricHandlerData, CustomLossHandlerData
|
13
|
+
RawInputsForHeatmap, VisualizerHandlerData, MetricHandlerData, CustomLossHandlerData, SamplePreprocessResponse
|
14
14
|
from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType, MetricDirection
|
15
15
|
from code_loader.contract.responsedataclasses import DatasetTestResultPayload
|
16
16
|
from code_loader.contract.visualizer_classes import map_leap_data_type_to_visualizer_class
|
@@ -239,9 +239,19 @@ class LeapBinder:
|
|
239
239
|
|
240
240
|
leap_binder.add_custom_loss(custom_loss_function, name='custom_loss')
|
241
241
|
"""
|
242
|
-
|
242
|
+
|
243
|
+
regular_arg_names = []
|
244
|
+
preprocess_response_arg_name = None
|
245
|
+
for arg_name, arg_type in inspect.getfullargspec(function).annotations.items():
|
246
|
+
if arg_type == SamplePreprocessResponse:
|
247
|
+
if preprocess_response_arg_name is not None:
|
248
|
+
raise Exception("only one argument can be of type SamplePreprocessResponse")
|
249
|
+
preprocess_response_arg_name = arg_name
|
250
|
+
else:
|
251
|
+
regular_arg_names.append(arg_name)
|
252
|
+
|
243
253
|
self.setup_container.custom_loss_handlers.append(
|
244
|
-
CustomLossHandler(CustomLossHandlerData(name,
|
254
|
+
CustomLossHandler(CustomLossHandlerData(name, regular_arg_names), function))
|
245
255
|
|
246
256
|
def add_custom_metric(self,
|
247
257
|
function: Union[CustomCallableInterfaceMultiArgs,
|
@@ -249,8 +259,7 @@ class LeapBinder:
|
|
249
259
|
ConfusionMatrixCallableInterfaceMultiArgs],
|
250
260
|
name: str,
|
251
261
|
direction: Optional[
|
252
|
-
Union[MetricDirection, Dict[str, MetricDirection]]] = MetricDirection.Downward
|
253
|
-
compute_insights: Union[bool, Dict[str, bool]] = True) -> None:
|
262
|
+
Union[MetricDirection, Dict[str, MetricDirection]]] = MetricDirection.Downward) -> None:
|
254
263
|
"""
|
255
264
|
Add a custom metric to the setup.
|
256
265
|
|
@@ -259,11 +268,9 @@ class LeapBinder:
|
|
259
268
|
name (str): The name of the custom metric.
|
260
269
|
direction (Optional[Union[MetricDirection, Dict[str, MetricDirection]]]): The direction of the metric, either
|
261
270
|
MetricDirection.Upward or MetricDirection.Downward, in case custom metric return a dictionary of metrics we can
|
262
|
-
supply a dictionary of directions correspondingly
|
271
|
+
supply a dictionary of directions correspondingly
|
263
272
|
- MetricDirection.Upward: Indicates that higher values of the metric are better and should be maximized.
|
264
273
|
- MetricDirection.Downward: Indicates that lower values of the metric are better and should be minimized.
|
265
|
-
compute_insights (Union[bool, Dict[str, bool]]): Whether to compute insights or not. in case custom metric
|
266
|
-
return a dictionary of metrics we can supply a dictionary of values correspondingly
|
267
274
|
|
268
275
|
|
269
276
|
|
@@ -274,8 +281,7 @@ class LeapBinder:
|
|
274
281
|
leap_binder.add_custom_metric(custom_metric_function, name='custom_metric', direction=MetricDirection.Downward)
|
275
282
|
"""
|
276
283
|
arg_names = inspect.getfullargspec(function)[0]
|
277
|
-
|
278
|
-
self.setup_container.metrics.append(MetricHandler(metric_handler_data, function))
|
284
|
+
self.setup_container.metrics.append(MetricHandler(MetricHandlerData(name, arg_names, direction), function))
|
279
285
|
|
280
286
|
def add_prediction(self, name: str, labels: List[str], channel_dim: int = -1) -> None:
|
281
287
|
"""
|
@@ -16,8 +16,7 @@ from code_loader.contract.visualizer_classes import LeapImage, LeapImageMask, Le
|
|
16
16
|
|
17
17
|
|
18
18
|
def tensorleap_custom_metric(name: str,
|
19
|
-
direction: Union[MetricDirection, Dict[str, MetricDirection]] = MetricDirection.Downward
|
20
|
-
compute_insights: Union[bool, Dict[str, bool]] = True):
|
19
|
+
direction: Union[MetricDirection, Dict[str, MetricDirection]] = MetricDirection.Downward):
|
21
20
|
def decorating_function(user_function: Union[CustomCallableInterfaceMultiArgs,
|
22
21
|
CustomMultipleReturnCallableInterfaceMultiArgs,
|
23
22
|
ConfusionMatrixCallableInterfaceMultiArgs]):
|
@@ -26,7 +25,7 @@ def tensorleap_custom_metric(name: str,
|
|
26
25
|
raise Exception(f'Metric with name {name} already exists. '
|
27
26
|
f'Please choose another')
|
28
27
|
|
29
|
-
leap_binder.add_custom_metric(user_function, name, direction
|
28
|
+
leap_binder.add_custom_metric(user_function, name, direction)
|
30
29
|
|
31
30
|
def _validate_input_args(*args, **kwargs) -> None:
|
32
31
|
for i, arg in enumerate(args):
|
@@ -76,19 +75,6 @@ def tensorleap_custom_metric(name: str,
|
|
76
75
|
(f'tensorleap_custom_metric validation failed: '
|
77
76
|
f'Keys in the return dict should be of type str. Got {type(key)}.')
|
78
77
|
_validate_single_metric(value)
|
79
|
-
|
80
|
-
if isinstance(direction, dict):
|
81
|
-
for direction_key in direction:
|
82
|
-
assert direction_key in result, \
|
83
|
-
(f'tensorleap_custom_metric validation failed: '
|
84
|
-
f'Keys in the direction mapping should be part of result keys. Got key {direction_key}.')
|
85
|
-
|
86
|
-
if isinstance(compute_insights, dict):
|
87
|
-
for ci_key in compute_insights:
|
88
|
-
assert ci_key in result, \
|
89
|
-
(f'tensorleap_custom_metric validation failed: '
|
90
|
-
f'Keys in the compute_insights mapping should be part of result keys. Got key {ci_key}.')
|
91
|
-
|
92
78
|
else:
|
93
79
|
_validate_single_metric(result)
|
94
80
|
|
code_loader/leaploader.py
CHANGED
@@ -14,7 +14,7 @@ import numpy.typing as npt
|
|
14
14
|
from code_loader.contract.datasetclasses import DatasetSample, DatasetBaseHandler, GroundTruthHandler, \
|
15
15
|
PreprocessResponse, VisualizerHandler, LeapData, \
|
16
16
|
PredictionTypeHandler, MetadataHandler, CustomLayerHandler, MetricHandler, VisualizerHandlerData, MetricHandlerData, \
|
17
|
-
MetricCallableReturnType, CustomLossHandlerData, CustomLossHandler, RawInputsForHeatmap
|
17
|
+
MetricCallableReturnType, CustomLossHandlerData, CustomLossHandler, RawInputsForHeatmap, SamplePreprocessResponse
|
18
18
|
from code_loader.contract.enums import DataStateEnum, TestingSectionEnum, DataStateType, DatasetMetadataType
|
19
19
|
from code_loader.contract.exceptions import DatasetScriptException
|
20
20
|
from code_loader.contract.responsedataclasses import DatasetIntegParseResult, DatasetTestResultPayload, \
|
@@ -233,9 +233,19 @@ class LeapLoader(LeapLoaderBase):
|
|
233
233
|
self._preprocess_result()
|
234
234
|
return self._metric_handler_by_name()[metric_name].function(**input_tensors_by_arg_name)
|
235
235
|
|
236
|
-
def run_custom_loss(self, custom_loss_name: str,
|
236
|
+
def run_custom_loss(self, custom_loss_name: str, sample_ids: np.array, state: DataStateEnum,
|
237
237
|
input_tensors_by_arg_name: Dict[str, npt.NDArray[np.float32]]):
|
238
|
-
|
238
|
+
|
239
|
+
custom_loss_handler = self._custom_loss_handler_by_name()[custom_loss_name]
|
240
|
+
preprocess_response_arg_name = None
|
241
|
+
for arg_name, arg_type in inspect.getfullargspec(custom_loss_handler.function).annotations.items():
|
242
|
+
if arg_type == SamplePreprocessResponse:
|
243
|
+
preprocess_response_arg_name = arg_name
|
244
|
+
break
|
245
|
+
|
246
|
+
if preprocess_response_arg_name is not None:
|
247
|
+
input_tensors_by_arg_name[preprocess_response_arg_name] = SamplePreprocessResponse(sample_ids, self._preprocess_result()[state])
|
248
|
+
return custom_loss_handler.function(**input_tensors_by_arg_name)
|
239
249
|
|
240
250
|
def run_visualizer(self, visualizer_name: str, input_tensors_by_arg_name: Dict[str, npt.NDArray[np.float32]]) -> LeapData:
|
241
251
|
# running preprocessing to sync preprocessing in main thread (can be valuable when preprocess is filling a
|
@@ -320,7 +330,8 @@ class LeapLoader(LeapLoaderBase):
|
|
320
330
|
for visualizer_handler in setup.visualizers]
|
321
331
|
|
322
332
|
custom_losses = [CustomLossInstance(custom_loss.custom_loss_handler_data.name,
|
323
|
-
custom_loss.custom_loss_handler_data.arg_names
|
333
|
+
custom_loss.custom_loss_handler_data.arg_names,
|
334
|
+
custom_loss.custom_loss_handler_data.preprocess_response_arg_name)
|
324
335
|
for custom_loss in setup.custom_loss_handlers]
|
325
336
|
|
326
337
|
prediction_types = []
|
code_loader/leaploaderbase.py
CHANGED
@@ -20,6 +20,9 @@ class LeapLoaderBase:
|
|
20
20
|
self.code_entry_name = code_entry_name
|
21
21
|
self.code_path = code_path
|
22
22
|
|
23
|
+
self.current_working_sample_ids: Optional[np.array] = None
|
24
|
+
self.current_working_state: Optional[DataStateEnum] = None
|
25
|
+
|
23
26
|
@abstractmethod
|
24
27
|
def metric_by_name(self) -> Dict[str, MetricHandlerData]:
|
25
28
|
pass
|
@@ -58,7 +61,7 @@ class LeapLoaderBase:
|
|
58
61
|
pass
|
59
62
|
|
60
63
|
@abstractmethod
|
61
|
-
def run_custom_loss(self, custom_loss_name: str,
|
64
|
+
def run_custom_loss(self, custom_loss_name: str, sample_ids: np.array, state: DataStateEnum,
|
62
65
|
input_tensors_by_arg_name: Dict[str, npt.NDArray[np.float32]]):
|
63
66
|
pass
|
64
67
|
|
@@ -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=
|
4
|
+
code_loader/contract/datasetclasses.py,sha256=2m9wyF_SO_q3kfrrAELS8rseMX-veeaP-Aof0ZhG_7g,7119
|
5
5
|
code_loader/contract/enums.py,sha256=6Lo7p5CUog68Fd31bCozIuOgIp_IhSiPqWWph2k3OGU,1602
|
6
6
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
7
7
|
code_loader/contract/responsedataclasses.py,sha256=RSx9m_R3LawhK5o1nAcO3hfp2F9oJYtxZr_bpP3bTmw,4005
|
@@ -19,14 +19,14 @@ code_loader/experiment_api/types.py,sha256=MY8xFARHwdVA7p4dxyhD60ShmttgTvb4qdp1o
|
|
19
19
|
code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZJEqBqc,3304
|
20
20
|
code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
|
21
21
|
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
22
|
-
code_loader/inner_leap_binder/leapbinder.py,sha256=
|
23
|
-
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=
|
24
|
-
code_loader/leaploader.py,sha256=
|
25
|
-
code_loader/leaploaderbase.py,sha256=
|
22
|
+
code_loader/inner_leap_binder/leapbinder.py,sha256=una-6k_nnSeqrLNjCy3beXdje_MWXbCRLoCalKdNYbg,26693
|
23
|
+
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=ebMxknpKMW-dE8Erq0fFq4RrE5E_Jfx9IvmRRZSdhlc,20813
|
24
|
+
code_loader/leaploader.py,sha256=DCrSS2789dkkePROJSwhAhgzQvR4_27YAR__PxCcLNc,23025
|
25
|
+
code_loader/leaploaderbase.py,sha256=FDXjTFBjnpfUyZ2tS3wLo7y2j82Qb_VKHI1BMB5gFww,3269
|
26
26
|
code_loader/utils.py,sha256=aw2i_fqW_ADjLB66FWZd9DfpCQ7mPdMyauROC5Nd51I,2197
|
27
27
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
28
28
|
code_loader/visualizers/default_visualizers.py,sha256=Ffx5VHVOe5ujBOsjBSxN_aIEVwFSQ6gbhTMG5aUS-po,2305
|
29
|
-
code_loader-1.0.72.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
30
|
-
code_loader-1.0.72.dist-info/METADATA,sha256=
|
31
|
-
code_loader-1.0.72.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
32
|
-
code_loader-1.0.72.dist-info/RECORD,,
|
29
|
+
code_loader-1.0.72.dev1.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
30
|
+
code_loader-1.0.72.dev1.dist-info/METADATA,sha256=WBFziucTTs-QHppp3QzdoSp_j9KXh1W9njNsHAGxxSo,854
|
31
|
+
code_loader-1.0.72.dev1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
32
|
+
code_loader-1.0.72.dev1.dist-info/RECORD,,
|
File without changes
|
File without changes
|