code-loader 1.0.117__py3-none-any.whl → 1.0.153.dev4__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 +30 -7
- code_loader/contract/mapping.py +11 -0
- code_loader/inner_leap_binder/leapbinder.py +14 -1
- code_loader/inner_leap_binder/leapbinder_decorators.py +1046 -146
- code_loader/leaploader.py +47 -29
- code_loader/leaploaderbase.py +30 -5
- code_loader/mixpanel_tracker.py +106 -10
- code_loader/plot_functions/plot_functions.py +1 -2
- code_loader/utils.py +6 -6
- code_loader-1.0.153.dev4.dist-info/LICENSE +21 -0
- {code_loader-1.0.117.dist-info → code_loader-1.0.153.dev4.dist-info}/METADATA +3 -3
- {code_loader-1.0.117.dist-info → code_loader-1.0.153.dev4.dist-info}/RECORD +14 -13
- {code_loader-1.0.117.dist-info → code_loader-1.0.153.dev4.dist-info}/WHEEL +1 -1
- /code_loader-1.0.117.dist-info/LICENSE → /LICENSE +0 -0
code_loader/leaploader.py
CHANGED
|
@@ -16,7 +16,7 @@ from code_loader.contract.datasetclasses import DatasetSample, DatasetBaseHandle
|
|
|
16
16
|
PreprocessResponse, VisualizerHandler, LeapData, \
|
|
17
17
|
PredictionTypeHandler, MetadataHandler, CustomLayerHandler, MetricHandler, VisualizerHandlerData, MetricHandlerData, \
|
|
18
18
|
MetricCallableReturnType, CustomLossHandlerData, CustomLossHandler, RawInputsForHeatmap, SamplePreprocessResponse, \
|
|
19
|
-
ElementInstance
|
|
19
|
+
ElementInstance, custom_latent_space_attribute
|
|
20
20
|
from code_loader.contract.enums import DataStateEnum, TestingSectionEnum, DataStateType, DatasetMetadataType
|
|
21
21
|
from code_loader.contract.exceptions import DatasetScriptException
|
|
22
22
|
from code_loader.contract.responsedataclasses import DatasetIntegParseResult, DatasetTestResultPayload, \
|
|
@@ -34,7 +34,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
34
34
|
super().__init__(code_path, code_entry_name)
|
|
35
35
|
|
|
36
36
|
self._preprocess_result_cached = None
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
try:
|
|
39
39
|
from code_loader.mixpanel_tracker import track_code_loader_loaded
|
|
40
40
|
track_code_loader_loaded({
|
|
@@ -51,7 +51,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
51
51
|
os.environ[mapping_runtime_mode_env_var_mame] = 'TRUE'
|
|
52
52
|
self.evaluate_module()
|
|
53
53
|
if global_leap_binder.integration_test_func is not None:
|
|
54
|
-
global_leap_binder.integration_test_func(None,
|
|
54
|
+
global_leap_binder.integration_test_func(None, PreprocessResponse(state=DataStateType.training, length=0))
|
|
55
55
|
except TypeError as e:
|
|
56
56
|
import traceback
|
|
57
57
|
if "leap_binder.set_metadata(" in traceback.format_exc(5):
|
|
@@ -77,13 +77,15 @@ class LeapLoader(LeapLoaderBase):
|
|
|
77
77
|
file_path = Path(self.code_path, self.code_entry_name)
|
|
78
78
|
append_path_recursively(str(file_path))
|
|
79
79
|
|
|
80
|
+
importlib.invalidate_caches()
|
|
81
|
+
|
|
80
82
|
spec = importlib.util.spec_from_file_location(self.code_path, file_path)
|
|
81
83
|
if spec is None or spec.loader is None:
|
|
82
|
-
raise DatasetScriptException(f'Something
|
|
84
|
+
raise DatasetScriptException(f'Something went wrong with spec file from: {file_path}')
|
|
83
85
|
|
|
84
86
|
file = importlib.util.module_from_spec(spec)
|
|
85
87
|
if file is None:
|
|
86
|
-
raise DatasetScriptException(f'Something
|
|
88
|
+
raise DatasetScriptException(f'Something went wrong with import module from: {file_path}')
|
|
87
89
|
|
|
88
90
|
spec.loader.exec_module(file)
|
|
89
91
|
|
|
@@ -155,35 +157,28 @@ class LeapLoader(LeapLoaderBase):
|
|
|
155
157
|
for prediction_type in setup.prediction_types
|
|
156
158
|
}
|
|
157
159
|
|
|
158
|
-
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:
|
|
159
161
|
self.exec_script()
|
|
160
162
|
preprocess_result = self._preprocess_result()
|
|
161
163
|
if state == DataStateEnum.unlabeled and sample_id not in preprocess_result[state].sample_ids:
|
|
162
164
|
self._preprocess_result(update_unlabeled_preprocess=True)
|
|
163
165
|
|
|
164
|
-
metadata, metadata_is_none = self.
|
|
165
|
-
sample = DatasetSample(inputs=self._get_inputs(state, sample_id),
|
|
166
|
-
gt=None if state == DataStateEnum.unlabeled else self._get_gt(state, sample_id),
|
|
167
|
-
metadata=metadata,
|
|
168
|
-
metadata_is_none=metadata_is_none,
|
|
169
|
-
index=sample_id,
|
|
170
|
-
state=state)
|
|
171
|
-
return sample
|
|
172
|
-
|
|
173
|
-
def get_sample_with_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> DatasetSample:
|
|
174
|
-
self.exec_script()
|
|
175
|
-
preprocess_result = self._preprocess_result()
|
|
176
|
-
if state == DataStateEnum.unlabeled and sample_id not in preprocess_result[state].sample_ids:
|
|
177
|
-
self._preprocess_result(update_unlabeled_preprocess=True)
|
|
166
|
+
metadata, metadata_is_none = self.get_metadata(state, sample_id)
|
|
178
167
|
|
|
179
|
-
|
|
168
|
+
custom_latent_space = None
|
|
169
|
+
if global_leap_binder.setup_container.custom_latent_space is not None:
|
|
170
|
+
custom_latent_space = global_leap_binder.setup_container.custom_latent_space.function(sample_id,
|
|
171
|
+
preprocess_result[
|
|
172
|
+
state])
|
|
173
|
+
instance_mask = self._get_instances_masks(state, sample_id, instance_id)
|
|
180
174
|
sample = DatasetSample(inputs=self._get_inputs(state, sample_id),
|
|
181
175
|
gt=None if state == DataStateEnum.unlabeled else self._get_gt(state, sample_id),
|
|
182
176
|
metadata=metadata,
|
|
183
177
|
metadata_is_none=metadata_is_none,
|
|
184
178
|
index=sample_id,
|
|
185
179
|
state=state,
|
|
186
|
-
|
|
180
|
+
custom_latent_space=custom_latent_space,
|
|
181
|
+
instance_masks=instance_mask)
|
|
187
182
|
return sample
|
|
188
183
|
|
|
189
184
|
def check_dataset(self) -> DatasetIntegParseResult:
|
|
@@ -210,8 +205,6 @@ class LeapLoader(LeapLoaderBase):
|
|
|
210
205
|
general_error = f"Something went wrong. {repr(e.__cause__)} in file {file_name}, line_number: {line_number}\nStacktrace:\n{stacktrace}"
|
|
211
206
|
is_valid = False
|
|
212
207
|
|
|
213
|
-
|
|
214
|
-
|
|
215
208
|
print_log = stdout_steam.getvalue()
|
|
216
209
|
is_valid_for_model = bool(global_leap_binder.setup_container.custom_layers)
|
|
217
210
|
model_setup = self.get_model_setup_response()
|
|
@@ -476,12 +469,14 @@ class LeapLoader(LeapLoaderBase):
|
|
|
476
469
|
def _get_inputs(self, state: DataStateEnum, sample_id: Union[int, str]) -> Dict[str, npt.NDArray[np.float32]]:
|
|
477
470
|
return self._get_dataset_handlers(global_leap_binder.setup_container.inputs, state, sample_id)
|
|
478
471
|
|
|
479
|
-
def _get_instances_masks(self, state: DataStateEnum, sample_id: Union[int, str]) -> Dict[str,
|
|
472
|
+
def _get_instances_masks(self, state: DataStateEnum, sample_id: Union[int, str], instance_id: int) -> Optional[Dict[str, ElementInstance]]:
|
|
473
|
+
if instance_id is None:
|
|
474
|
+
return None
|
|
480
475
|
preprocess_result = self._preprocess_result()
|
|
481
476
|
preprocess_state = preprocess_result[state]
|
|
482
477
|
result_agg = {}
|
|
483
478
|
for handler in global_leap_binder.setup_container.instance_masks:
|
|
484
|
-
handler_result = handler.function(sample_id, preprocess_state)
|
|
479
|
+
handler_result = handler.function(sample_id, preprocess_state, instance_id)
|
|
485
480
|
handler_name = handler.name
|
|
486
481
|
result_agg[handler_name] = handler_result
|
|
487
482
|
return result_agg
|
|
@@ -526,20 +521,38 @@ class LeapLoader(LeapLoaderBase):
|
|
|
526
521
|
|
|
527
522
|
return converted_value, is_none
|
|
528
523
|
|
|
529
|
-
def
|
|
524
|
+
def get_metadata(self, state: DataStateEnum, sample_id: Union[int, str], requested_metadata_names: Optional[List[str]] = None) -> Tuple[
|
|
525
|
+
Dict[str, Union[str, int, bool, float]], Dict[str, bool]]:
|
|
526
|
+
|
|
527
|
+
def is_metadata_name_starts_with_handler_name(_handler):
|
|
528
|
+
for metadata_name in requested_metadata_names:
|
|
529
|
+
if metadata_name.startswith(_handler.name + '_') or metadata_name == _handler.name:
|
|
530
|
+
return True
|
|
531
|
+
return False
|
|
532
|
+
|
|
530
533
|
result_agg = {}
|
|
531
534
|
is_none = {}
|
|
532
535
|
preprocess_result = self._preprocess_result()
|
|
533
536
|
preprocess_state = preprocess_result[state]
|
|
534
537
|
for handler in global_leap_binder.setup_container.metadata:
|
|
538
|
+
if requested_metadata_names:
|
|
539
|
+
if not is_metadata_name_starts_with_handler_name(handler):
|
|
540
|
+
continue
|
|
541
|
+
|
|
535
542
|
handler_result = handler.function(sample_id, preprocess_state)
|
|
536
543
|
if isinstance(handler_result, dict):
|
|
537
544
|
for single_metadata_name, single_metadata_result in handler_result.items():
|
|
538
545
|
handler_name = f'{handler.name}_{single_metadata_name}'
|
|
546
|
+
if requested_metadata_names:
|
|
547
|
+
if handler_name not in requested_metadata_names:
|
|
548
|
+
continue
|
|
539
549
|
result_agg[handler_name], is_none[handler_name] = self._convert_metadata_to_correct_type(
|
|
540
550
|
handler_name, single_metadata_result)
|
|
541
551
|
else:
|
|
542
552
|
handler_name = handler.name
|
|
553
|
+
if requested_metadata_names:
|
|
554
|
+
if handler_name not in requested_metadata_names:
|
|
555
|
+
continue
|
|
543
556
|
result_agg[handler_name], is_none[handler_name] = self._convert_metadata_to_correct_type(
|
|
544
557
|
handler_name, handler_result)
|
|
545
558
|
|
|
@@ -555,7 +568,12 @@ class LeapLoader(LeapLoaderBase):
|
|
|
555
568
|
|
|
556
569
|
return id_type
|
|
557
570
|
|
|
558
|
-
|
|
571
|
+
@lru_cache()
|
|
572
|
+
def has_custom_latent_space_decorator(self) -> bool:
|
|
573
|
+
self.exec_script()
|
|
574
|
+
return global_leap_binder.setup_container.custom_latent_space is not None
|
|
575
|
+
|
|
576
|
+
def get_instances_data(self, state: DataStateEnum) -> Tuple[Dict[str, List[str]], Dict[str, str]]:
|
|
559
577
|
"""
|
|
560
578
|
This Method get the data state and returns two dictionaries that holds the mapping of the sample ids to their
|
|
561
579
|
instances and the other way around and the sample ids array.
|
|
@@ -568,4 +586,4 @@ class LeapLoader(LeapLoaderBase):
|
|
|
568
586
|
"""
|
|
569
587
|
preprocess_result = self._preprocess_result()
|
|
570
588
|
preprocess_state = preprocess_result[state]
|
|
571
|
-
return preprocess_state.sample_ids_to_instance_mappings, preprocess_state.instance_to_sample_ids_mappings
|
|
589
|
+
return preprocess_state.sample_ids_to_instance_mappings, preprocess_state.instance_to_sample_ids_mappings
|
code_loader/leaploaderbase.py
CHANGED
|
@@ -61,16 +61,30 @@ 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
|
|
68
|
+
def get_instances_data(self, state: DataStateEnum) -> Tuple[Dict[str, List[str]], Dict[str, str]]:
|
|
69
69
|
pass
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
def get_metadata_multiple_samples(self, state: DataStateEnum, sample_ids: Union[List[int], List[str]],
|
|
72
|
+
requested_metadata_names: Optional[List[str]] = None
|
|
73
|
+
) -> Tuple[Dict[str, Union[List[str], List[int], List[bool],
|
|
74
|
+
List[float]]], Dict[str, List[bool]]]:
|
|
75
|
+
aggregated_results: Dict[str, List[Union[str, int, bool, float]]] = {}
|
|
76
|
+
aggregated_is_none: Dict[str, List[bool]] = {}
|
|
77
|
+
sample_id_type = self.get_sample_id_type()
|
|
78
|
+
for sample_id in sample_ids:
|
|
79
|
+
sample_id = sample_id_type(sample_id)
|
|
80
|
+
metadata_result, is_none_result = self.get_metadata(state, sample_id, requested_metadata_names)
|
|
81
|
+
for metadata_name, metadata_value in metadata_result.items():
|
|
82
|
+
if metadata_name not in aggregated_results:
|
|
83
|
+
aggregated_results[metadata_name] = []
|
|
84
|
+
aggregated_is_none[metadata_name] = []
|
|
85
|
+
aggregated_results[metadata_name].append(metadata_value)
|
|
86
|
+
aggregated_is_none[metadata_name].append(is_none_result[metadata_name])
|
|
87
|
+
return aggregated_results, aggregated_is_none
|
|
74
88
|
|
|
75
89
|
@abstractmethod
|
|
76
90
|
def check_dataset(self) -> DatasetIntegParseResult:
|
|
@@ -91,6 +105,13 @@ class LeapLoaderBase:
|
|
|
91
105
|
input_tensors_by_arg_name: Dict[str, npt.NDArray[np.float32]]):
|
|
92
106
|
pass
|
|
93
107
|
|
|
108
|
+
@abstractmethod
|
|
109
|
+
def get_metadata(
|
|
110
|
+
self, state: DataStateEnum, sample_id: Union[int, str],
|
|
111
|
+
requested_metadata_names: Optional[List[str]] = None
|
|
112
|
+
) -> Tuple[Dict[str, Union[str, int, bool, float]], Dict[str, bool]]:
|
|
113
|
+
pass
|
|
114
|
+
|
|
94
115
|
@abstractmethod
|
|
95
116
|
def run_heatmap_visualizer(self, visualizer_name: str, sample_ids: np.array, state: DataStateEnum,
|
|
96
117
|
input_tensors_by_arg_name: Dict[str, npt.NDArray[np.float32]]
|
|
@@ -114,6 +135,10 @@ class LeapLoaderBase:
|
|
|
114
135
|
def get_sample_id_type(self) -> Type:
|
|
115
136
|
pass
|
|
116
137
|
|
|
138
|
+
@abstractmethod
|
|
139
|
+
def has_custom_latent_space_decorator(self) -> bool:
|
|
140
|
+
pass
|
|
141
|
+
|
|
117
142
|
@abstractmethod
|
|
118
143
|
def get_heatmap_visualizer_raw_vis_input_arg_name(self, visualizer_name: str) -> Optional[str]:
|
|
119
144
|
pass
|
code_loader/mixpanel_tracker.py
CHANGED
|
@@ -5,14 +5,57 @@ import os
|
|
|
5
5
|
import sys
|
|
6
6
|
import getpass
|
|
7
7
|
import uuid
|
|
8
|
-
|
|
8
|
+
import logging
|
|
9
|
+
from enum import Enum
|
|
10
|
+
from typing import Optional, Dict, Any, Set, Union, TypedDict
|
|
9
11
|
import mixpanel # type: ignore[import]
|
|
10
12
|
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
TRACKING_VERSION = '1'
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AnalyticsEvent(str, Enum):
|
|
19
|
+
"""Enumeration of all tracked analytics events."""
|
|
20
|
+
CODE_LOADER_LOADED = "code_loader_loaded"
|
|
21
|
+
LOAD_MODEL_INTEGRATION_TEST = "load_model_integration_test"
|
|
22
|
+
PREPROCESS_INTEGRATION_TEST = "preprocess_integration_test"
|
|
23
|
+
INPUT_ENCODER_INTEGRATION_TEST = "input_encoder_integration_test"
|
|
24
|
+
GT_ENCODER_INTEGRATION_TEST = "gt_encoder_integration_test"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class CodeLoaderLoadedProps(TypedDict, total=False):
|
|
28
|
+
"""Properties for code_loader_loaded event."""
|
|
29
|
+
event_type: str
|
|
30
|
+
code_path: str
|
|
31
|
+
code_entry_name: str
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class LoadModelEventProps(TypedDict, total=False):
|
|
35
|
+
"""Properties for load_model_integration_test event."""
|
|
36
|
+
prediction_types_count: int
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class PreprocessEventProps(TypedDict, total=False):
|
|
40
|
+
"""Properties for preprocess_integration_test event."""
|
|
41
|
+
preprocess_responses_count: int
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class InputEncoderEventProps(TypedDict, total=False):
|
|
45
|
+
"""Properties for input_encoder_integration_test event."""
|
|
46
|
+
encoder_name: str
|
|
47
|
+
channel_dim: int
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class GtEncoderEventProps(TypedDict, total=False):
|
|
51
|
+
"""Properties for gt_encoder_integration_test event."""
|
|
52
|
+
encoder_name: str
|
|
53
|
+
|
|
11
54
|
|
|
12
55
|
class MixpanelTracker:
|
|
13
56
|
"""Handles Mixpanel event tracking for code-loader."""
|
|
14
57
|
|
|
15
|
-
def __init__(self, token: str = "
|
|
58
|
+
def __init__(self, token: str = "0c1710c9656bbfb1056bb46093e23ca1"):
|
|
16
59
|
self.token = token
|
|
17
60
|
self.mp = mixpanel.Mixpanel(token)
|
|
18
61
|
self._user_id: Optional[str] = None
|
|
@@ -26,7 +69,8 @@ class MixpanelTracker:
|
|
|
26
69
|
if self._user_id is None:
|
|
27
70
|
try:
|
|
28
71
|
self._user_id = getpass.getuser()
|
|
29
|
-
except Exception:
|
|
72
|
+
except Exception as e:
|
|
73
|
+
logger.debug(f"Failed to get username via getpass: {e}")
|
|
30
74
|
# Fallback to environment variables or default
|
|
31
75
|
self._user_id = os.environ.get('USER', os.environ.get('USERNAME', 'unknown'))
|
|
32
76
|
return self._user_id or 'unknown'
|
|
@@ -41,8 +85,8 @@ class MixpanelTracker:
|
|
|
41
85
|
user_id = f.read().strip()
|
|
42
86
|
if user_id:
|
|
43
87
|
return user_id
|
|
44
|
-
except Exception:
|
|
45
|
-
|
|
88
|
+
except Exception as e:
|
|
89
|
+
logger.debug(f"Failed to read TensorLeap user ID: {e}")
|
|
46
90
|
return None
|
|
47
91
|
|
|
48
92
|
def _get_or_create_device_id(self) -> str:
|
|
@@ -71,7 +115,8 @@ class MixpanelTracker:
|
|
|
71
115
|
f.write(device_id)
|
|
72
116
|
|
|
73
117
|
return device_id
|
|
74
|
-
except Exception:
|
|
118
|
+
except Exception as e:
|
|
119
|
+
logger.debug(f"Failed to read/write device ID file: {e}")
|
|
75
120
|
# Fallback to generating a new UUID if file operations fail
|
|
76
121
|
return str(uuid.uuid4())
|
|
77
122
|
|
|
@@ -88,12 +133,17 @@ class MixpanelTracker:
|
|
|
88
133
|
|
|
89
134
|
return self._get_or_create_device_id()
|
|
90
135
|
|
|
91
|
-
def
|
|
92
|
-
"""
|
|
136
|
+
def _track_event(self, event_name: Union[str, AnalyticsEvent], event_properties: Optional[Dict[str, Any]] = None) -> None:
|
|
137
|
+
"""Internal method to track any event with device identification.
|
|
93
138
|
|
|
94
139
|
Args:
|
|
140
|
+
event_name: The name of the event to track (string or AnalyticsEvent enum)
|
|
95
141
|
event_properties: Optional additional properties to include in the event
|
|
96
142
|
"""
|
|
143
|
+
# Skip tracking if IS_TENSORLEAP_PLATFORM environment variable is set to 'true'
|
|
144
|
+
if os.environ.get('IS_TENSORLEAP_PLATFORM') == 'true':
|
|
145
|
+
return
|
|
146
|
+
|
|
97
147
|
try:
|
|
98
148
|
distinct_id = self._get_distinct_id()
|
|
99
149
|
|
|
@@ -102,6 +152,8 @@ class MixpanelTracker:
|
|
|
102
152
|
device_id = self._get_or_create_device_id()
|
|
103
153
|
|
|
104
154
|
properties = {
|
|
155
|
+
'tracking_version': TRACKING_VERSION,
|
|
156
|
+
'service': 'code-loader',
|
|
105
157
|
'whoami': whoami,
|
|
106
158
|
'$device_id': device_id, # Always use device_id for $device_id
|
|
107
159
|
'python_version': f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
|
|
@@ -114,9 +166,26 @@ class MixpanelTracker:
|
|
|
114
166
|
if event_properties:
|
|
115
167
|
properties.update(event_properties)
|
|
116
168
|
|
|
117
|
-
self.mp.track(distinct_id,
|
|
169
|
+
self.mp.track(distinct_id, str(event_name), properties)
|
|
118
170
|
except Exception as e:
|
|
119
|
-
|
|
171
|
+
logger.debug(f"Failed to track event '{event_name}': {e}")
|
|
172
|
+
|
|
173
|
+
def track_code_loader_loaded(self, event_properties: Optional[Dict[str, Any]] = None) -> None:
|
|
174
|
+
"""Track code loader loaded event with device identification.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
event_properties: Optional additional properties to include in the event
|
|
178
|
+
"""
|
|
179
|
+
self._track_event(AnalyticsEvent.CODE_LOADER_LOADED, event_properties)
|
|
180
|
+
|
|
181
|
+
def track_integration_test_event(self, event_name: Union[str, AnalyticsEvent], event_properties: Optional[Dict[str, Any]] = None) -> None:
|
|
182
|
+
"""Track an integration test event with device identification.
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
event_name: The name of the event to track (string or AnalyticsEvent enum)
|
|
186
|
+
event_properties: Optional additional properties to include in the event
|
|
187
|
+
"""
|
|
188
|
+
self._track_event(event_name, event_properties)
|
|
120
189
|
|
|
121
190
|
|
|
122
191
|
# Global tracker instance
|
|
@@ -132,3 +201,30 @@ def get_tracker() -> MixpanelTracker:
|
|
|
132
201
|
|
|
133
202
|
def track_code_loader_loaded(event_properties: Optional[Dict[str, Any]] = None) -> None:
|
|
134
203
|
get_tracker().track_code_loader_loaded(event_properties)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def track_integration_test_event(event_name: Union[str, AnalyticsEvent], event_properties: Optional[Dict[str, Any]] = None) -> None:
|
|
207
|
+
get_tracker().track_integration_test_event(event_name, event_properties)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
# Module-level set to track which integration test events have been emitted
|
|
211
|
+
_integration_events_emitted: Set[str] = set()
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def emit_integration_event_once(event_name: Union[str, AnalyticsEvent], props: Dict[str, Any]) -> None:
|
|
215
|
+
"""Emit an integration test event only once per test run."""
|
|
216
|
+
event_name_str = str(event_name)
|
|
217
|
+
if event_name_str in _integration_events_emitted:
|
|
218
|
+
return
|
|
219
|
+
|
|
220
|
+
try:
|
|
221
|
+
track_integration_test_event(event_name, props)
|
|
222
|
+
_integration_events_emitted.add(event_name_str)
|
|
223
|
+
except Exception as e:
|
|
224
|
+
logger.debug(f"Failed to emit integration event once '{event_name}': {e}")
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def clear_integration_events() -> None:
|
|
228
|
+
"""Clear the integration events set for a new test run."""
|
|
229
|
+
global _integration_events_emitted
|
|
230
|
+
_integration_events_emitted.clear()
|
|
@@ -29,7 +29,6 @@ def run_only_on_non_mapping_mode():
|
|
|
29
29
|
def decorator(func):
|
|
30
30
|
def wrapper(*args, **kwargs):
|
|
31
31
|
if os.environ.get(mapping_runtime_mode_env_var_mame):
|
|
32
|
-
print(f"Skipping {func.__name__} in mapping mode.")
|
|
33
32
|
return
|
|
34
33
|
return func(*args, **kwargs)
|
|
35
34
|
return wrapper
|
|
@@ -325,7 +324,7 @@ def plot_image_mask(leap_data: LeapImageMask, title: str) -> None:
|
|
|
325
324
|
|
|
326
325
|
# fill the instance mask with a translucent color
|
|
327
326
|
overlayed_image[instance_mask] = (
|
|
328
|
-
overlayed_image[instance_mask] * (1 - 0.5) + np.array(colors[i][:image.shape[-1]], dtype=
|
|
327
|
+
overlayed_image[instance_mask] * (1 - 0.5) + np.array(colors[i][:image.shape[-1]], dtype=image.dtype) * 0.5)
|
|
329
328
|
|
|
330
329
|
# Display the result using matplotlib
|
|
331
330
|
fig, ax = plt.subplots(1)
|
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) ->
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
result
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 TensorLeap
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: code-loader
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.153.dev4
|
|
4
4
|
Summary:
|
|
5
|
+
Home-page: https://github.com/tensorleap/code-loader
|
|
5
6
|
License: MIT
|
|
6
7
|
Author: dorhar
|
|
7
8
|
Author-email: doron.harnoy@tensorleap.ai
|
|
@@ -19,7 +20,6 @@ Requires-Dist: numpy (>=2.3.2,<3.0.0) ; python_version >= "3.11" and python_vers
|
|
|
19
20
|
Requires-Dist: psutil (>=5.9.5,<6.0.0)
|
|
20
21
|
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
|
21
22
|
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
22
|
-
Project-URL: Homepage, https://github.com/tensorleap/code-loader
|
|
23
23
|
Project-URL: Repository, https://github.com/tensorleap/code-loader
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
|
1
2
|
code_loader/__init__.py,sha256=outxRQ0M-zMfV0QGVJmAed5qWfRmyD0TV6-goEGAzBw,406
|
|
2
3
|
code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
code_loader/contract/datasetclasses.py,sha256=
|
|
4
|
+
code_loader/contract/datasetclasses.py,sha256=IyUwwvu1c53KfUeTiVOYN20ak7aCo-26HYhm5seO6v8,9799
|
|
4
5
|
code_loader/contract/enums.py,sha256=GEFkvUMXnCNt-GOoz7NJ9ecQZ2PPDettJNOsxsiM0wk,1622
|
|
5
6
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
|
6
|
-
code_loader/contract/mapping.py,sha256=
|
|
7
|
+
code_loader/contract/mapping.py,sha256=sWJhpng-IkOzQnWQdMT5w2ZZ3X1Z_OOzSwCLXIS7oxE,1446
|
|
7
8
|
code_loader/contract/responsedataclasses.py,sha256=6-5DJkYBdXb3UB1eNidTTPPBIYxMjEoMdYDkp9VhH8o,4223
|
|
8
9
|
code_loader/contract/visualizer_classes.py,sha256=Wz9eItmoRaKEHa3p0aW0Ypxx4_xUmaZyLBznnTuxwi0,15425
|
|
9
10
|
code_loader/default_losses.py,sha256=NoOQym1106bDN5dcIk56Elr7ZG5quUHArqfP5-Nyxyo,1139
|
|
@@ -19,18 +20,18 @@ code_loader/experiment_api/types.py,sha256=MY8xFARHwdVA7p4dxyhD60ShmttgTvb4qdp1o
|
|
|
19
20
|
code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZJEqBqc,3304
|
|
20
21
|
code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
|
|
21
22
|
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=
|
|
26
|
-
code_loader/mixpanel_tracker.py,sha256=
|
|
23
|
+
code_loader/inner_leap_binder/leapbinder.py,sha256=Q3D9yVM-GNEJfYRFvMV__BoZbcWOgnWKhrZXAv6Tu7o,33232
|
|
24
|
+
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=aVMVjZjRmJy8-3_qyQ42RAcVfvajUZ-SupwcmNwhdaI,82000
|
|
25
|
+
code_loader/leaploader.py,sha256=oxtlf7NhWuiUPeIwAO699JaD-mK_7fGM55okKLyKaJg,30582
|
|
26
|
+
code_loader/leaploaderbase.py,sha256=NXCDIIF7-ziGJccKIE9NszMSYKEE-3bn4Z4Xa3oYYOc,5909
|
|
27
|
+
code_loader/mixpanel_tracker.py,sha256=eKvymkw7X2Ht6iw-a0V9VQm6OnB9kW7hYy35YtwRAvU,8457
|
|
27
28
|
code_loader/plot_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
|
-
code_loader/plot_functions/plot_functions.py,sha256=
|
|
29
|
+
code_loader/plot_functions/plot_functions.py,sha256=OGFLfbL31N2wuwcXIxxQ14f0Kuuvv1BZkAuFi2c0ma4,14560
|
|
29
30
|
code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6LznoQIvi4vpo,657
|
|
30
|
-
code_loader/utils.py,sha256=
|
|
31
|
+
code_loader/utils.py,sha256=gXENTYpjdidq2dx0gVbXlErPeHoNs-4TYAZbLRe0y2c,2712
|
|
31
32
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
33
|
code_loader/visualizers/default_visualizers.py,sha256=onRnLE_TXfgLN4o52hQIOOhUcFexGlqJ3xSpQDVLuZM,2604
|
|
33
|
-
code_loader-1.0.
|
|
34
|
-
code_loader-1.0.
|
|
35
|
-
code_loader-1.0.
|
|
36
|
-
code_loader-1.0.
|
|
34
|
+
code_loader-1.0.153.dev4.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
|
35
|
+
code_loader-1.0.153.dev4.dist-info/METADATA,sha256=B4nPV_w3AFdba4SVtC-d03HSfaw_-MobZquctbpytbM,1095
|
|
36
|
+
code_loader-1.0.153.dev4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
37
|
+
code_loader-1.0.153.dev4.dist-info/RECORD,,
|
|
File without changes
|