code-loader 1.0.190__tar.gz → 1.0.191.dev0__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.
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/PKG-INFO +1 -1
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/contract/datasetclasses.py +2 -2
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/inner_leap_binder/leapbinder.py +21 -5
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/inner_leap_binder/leapbinder_decorators.py +5 -4
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/leaploader.py +24 -13
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/leaploaderbase.py +4 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/pyproject.toml +1 -1
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/LICENSE +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/README.md +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/__init__.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/contract/__init__.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/contract/enums.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/contract/exceptions.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/contract/mapping.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/contract/responsedataclasses.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/contract/sim_config.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/contract/visualizer_classes.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/default_losses.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/default_metrics.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/__init__.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/api.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/cli_config_utils.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/client.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/epoch.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/experiment.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/experiment_context.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/types.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/utils.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/inner_leap_binder/__init__.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/mixpanel_tracker.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/plot_functions/__init__.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/plot_functions/plot_functions.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/plot_functions/visualize.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/utils.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/visualizers/__init__.py +0 -0
- {code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/visualizers/default_visualizers.py +0 -0
|
@@ -277,7 +277,7 @@ class DatasetIntegrationSetup:
|
|
|
277
277
|
metrics: List[MetricHandler] = field(default_factory=list)
|
|
278
278
|
instance_metrics: List[InstanceMetricHandler] = field(default_factory=list)
|
|
279
279
|
custom_layers: Dict[str, CustomLayerHandler] = field(default_factory=dict)
|
|
280
|
-
|
|
280
|
+
custom_latent_spaces: Dict[str, CustomLatentSpaceHandler] = field(default_factory=dict)
|
|
281
281
|
simulations: List[SimulationHandler] = field(default_factory=list)
|
|
282
282
|
|
|
283
283
|
|
|
@@ -289,6 +289,6 @@ class DatasetSample:
|
|
|
289
289
|
metadata_is_none: Dict[str, bool]
|
|
290
290
|
index: Union[int, str]
|
|
291
291
|
state: DataStateEnum
|
|
292
|
-
|
|
292
|
+
custom_latent_spaces: Optional[Dict[str, npt.NDArray[np.float32]]] = None
|
|
293
293
|
instance_masks: Optional[Dict[str, ElementInstance]] = None
|
|
294
294
|
|
{code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/inner_leap_binder/leapbinder.py
RENAMED
|
@@ -511,18 +511,34 @@ class LeapBinder:
|
|
|
511
511
|
"""
|
|
512
512
|
self.setup_container.metadata.append(MetadataHandler(name, function, metadata_type))
|
|
513
513
|
|
|
514
|
-
def set_custom_latent_space(self, function: SectionCallableInterface
|
|
514
|
+
def set_custom_latent_space(self, function: SectionCallableInterface,
|
|
515
|
+
name: Optional[str] = None) -> None:
|
|
515
516
|
"""
|
|
516
|
-
|
|
517
|
+
Register a custom latent space function.
|
|
518
|
+
|
|
519
|
+
Multiple custom latent spaces may be registered as long as each has a
|
|
520
|
+
unique name. They are stored name-keyed (insertion order preserved), so a
|
|
521
|
+
later registration no longer overrides an earlier one.
|
|
517
522
|
|
|
518
523
|
Args:
|
|
519
|
-
function (SectionCallableInterface): The
|
|
524
|
+
function (SectionCallableInterface): The latent-space handler function.
|
|
520
525
|
This function receives:
|
|
521
526
|
subset (PreprocessResponse): The subset of the data.
|
|
522
527
|
index (int): The index of the sample within the subset.
|
|
523
|
-
This function should numpy float32 array
|
|
528
|
+
This function should return a numpy float32 array containing the latent
|
|
529
|
+
space vec of the sample.
|
|
530
|
+
name (Optional[str]): Unique name for this custom latent space. Defaults to
|
|
531
|
+
the reserved single-LS name for backward compatibility.
|
|
524
532
|
"""
|
|
525
|
-
|
|
533
|
+
if name is None:
|
|
534
|
+
name = custom_latent_space_attribute
|
|
535
|
+
if name in self.setup_container.custom_latent_spaces:
|
|
536
|
+
raise Exception(
|
|
537
|
+
f"A custom latent space named '{name}' is already registered. Each "
|
|
538
|
+
f"@tensorleap_custom_latent_space must have a unique name "
|
|
539
|
+
f"(pass name='...' to distinguish them)."
|
|
540
|
+
)
|
|
541
|
+
self.setup_container.custom_latent_spaces[name] = CustomLatentSpaceHandler(function, name)
|
|
526
542
|
|
|
527
543
|
def set_custom_layer(self, custom_layer: Type[Any], name: str, inspect_layer: bool = False,
|
|
528
544
|
kernel_index: Optional[int] = None, use_custom_latent_space: bool = False) -> None:
|
|
@@ -1568,8 +1568,9 @@ def tensorleap_metadata(
|
|
|
1568
1568
|
return decorating_function
|
|
1569
1569
|
|
|
1570
1570
|
|
|
1571
|
-
def tensorleap_custom_latent_space():
|
|
1571
|
+
def tensorleap_custom_latent_space(name: Optional[str] = None):
|
|
1572
1572
|
def decorating_function(user_function: SectionCallableInterface):
|
|
1573
|
+
ls_name = name if name is not None else user_function.__name__
|
|
1573
1574
|
def _validate_input_args(sample_id: Union[int, str], preprocess_response: PreprocessResponse):
|
|
1574
1575
|
assert isinstance(sample_id, (int, str)), \
|
|
1575
1576
|
(f'tensorleap_custom_latent_space validation failed: '
|
|
@@ -1589,9 +1590,9 @@ def tensorleap_custom_latent_space():
|
|
|
1589
1590
|
if result.ndim > 1:
|
|
1590
1591
|
flat_dim = int(np.prod(result.shape))
|
|
1591
1592
|
store_general_warning(
|
|
1592
|
-
key=("tensorleap_custom_latent_space_flatten", tuple(result.shape)),
|
|
1593
|
+
key=("tensorleap_custom_latent_space_flatten", ls_name, tuple(result.shape)),
|
|
1593
1594
|
message=(
|
|
1594
|
-
f"tensorleap_custom_latent_space returned per-sample shape {tuple(result.shape)} "
|
|
1595
|
+
f"tensorleap_custom_latent_space '{ls_name}' returned per-sample shape {tuple(result.shape)} "
|
|
1595
1596
|
f"(ndim={result.ndim}). Tensorleap assumes per-sample shape (d, ...) and will "
|
|
1596
1597
|
f"flatten to ({flat_dim},) before downstream visualization and clustering. "
|
|
1597
1598
|
f"If you want a different aggregation (e.g. global average pooling), do it "
|
|
@@ -1610,7 +1611,7 @@ def tensorleap_custom_latent_space():
|
|
|
1610
1611
|
|
|
1611
1612
|
return result
|
|
1612
1613
|
|
|
1613
|
-
leap_binder.set_custom_latent_space(inner_without_validate)
|
|
1614
|
+
leap_binder.set_custom_latent_space(inner_without_validate, ls_name)
|
|
1614
1615
|
|
|
1615
1616
|
def inner(sample_id, preprocess_response):
|
|
1616
1617
|
if os.environ.get(mapping_runtime_mode_env_var_mame):
|
|
@@ -251,11 +251,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
251
251
|
|
|
252
252
|
metadata, metadata_is_none = self.get_metadata(state, sample_id)
|
|
253
253
|
|
|
254
|
-
|
|
255
|
-
if global_leap_binder.setup_container.custom_latent_space is not None:
|
|
256
|
-
custom_latent_space = global_leap_binder.setup_container.custom_latent_space.function(sample_id,
|
|
257
|
-
preprocess_result[
|
|
258
|
-
state])
|
|
254
|
+
custom_latent_spaces = self._get_custom_latent_spaces(sample_id, preprocess_result[state])
|
|
259
255
|
instance_mask = self._get_instances_masks(state, sample_id, instance_id)
|
|
260
256
|
sample = DatasetSample(inputs=self._get_inputs(state, sample_id),
|
|
261
257
|
gt=None if state == DataStateEnum.unlabeled else self._get_gt(state, sample_id),
|
|
@@ -263,7 +259,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
263
259
|
metadata_is_none=metadata_is_none,
|
|
264
260
|
index=sample_id,
|
|
265
261
|
state=state,
|
|
266
|
-
|
|
262
|
+
custom_latent_spaces=custom_latent_spaces,
|
|
267
263
|
instance_masks=instance_mask)
|
|
268
264
|
return sample
|
|
269
265
|
|
|
@@ -294,11 +290,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
294
290
|
handler.name, handler_result
|
|
295
291
|
)
|
|
296
292
|
|
|
297
|
-
|
|
298
|
-
if global_leap_binder.setup_container.custom_latent_space is not None:
|
|
299
|
-
custom_latent_space = global_leap_binder.setup_container.custom_latent_space.function(
|
|
300
|
-
original_sample_id, preprocess
|
|
301
|
-
)
|
|
293
|
+
custom_latent_spaces = self._get_custom_latent_spaces(original_sample_id, preprocess)
|
|
302
294
|
|
|
303
295
|
return DatasetSample(
|
|
304
296
|
inputs=inputs,
|
|
@@ -307,7 +299,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
307
299
|
metadata_is_none=metadata_is_none,
|
|
308
300
|
index=synthetic_index,
|
|
309
301
|
state=DataStateEnum.additional,
|
|
310
|
-
|
|
302
|
+
custom_latent_spaces=custom_latent_spaces,
|
|
311
303
|
instance_masks=None,
|
|
312
304
|
)
|
|
313
305
|
|
|
@@ -874,10 +866,29 @@ class LeapLoader(LeapLoaderBase):
|
|
|
874
866
|
|
|
875
867
|
return id_type
|
|
876
868
|
|
|
869
|
+
@staticmethod
|
|
870
|
+
def _get_custom_latent_spaces(
|
|
871
|
+
sample_id: Union[int, str],
|
|
872
|
+
preprocess: "PreprocessResponse") -> Optional[Dict[str, npt.NDArray[np.float32]]]:
|
|
873
|
+
handlers = global_leap_binder.setup_container.custom_latent_spaces
|
|
874
|
+
if not handlers:
|
|
875
|
+
return None
|
|
876
|
+
return {name: handler.function(sample_id, preprocess) for name, handler in handlers.items()}
|
|
877
|
+
|
|
877
878
|
@lru_cache()
|
|
878
879
|
def has_custom_latent_space_decorator(self) -> bool:
|
|
879
880
|
self.exec_script()
|
|
880
|
-
return global_leap_binder.setup_container.
|
|
881
|
+
return len(global_leap_binder.setup_container.custom_latent_spaces) > 0
|
|
882
|
+
|
|
883
|
+
@lru_cache()
|
|
884
|
+
def get_custom_latent_space_names(self) -> Tuple[str, ...]:
|
|
885
|
+
"""Ordered names of all registered custom latent spaces.
|
|
886
|
+
|
|
887
|
+
Registration order is the canonical index mapping consumed by the engine
|
|
888
|
+
(name i -> user_custom_i). Returns a tuple so the lru_cache value is hashable.
|
|
889
|
+
"""
|
|
890
|
+
self.exec_script()
|
|
891
|
+
return tuple(global_leap_binder.setup_container.custom_latent_spaces.keys())
|
|
881
892
|
|
|
882
893
|
def get_instances_data(self, state: DataStateEnum) -> Tuple[Dict[str, List[str]], Dict[str, str]]:
|
|
883
894
|
preprocess_result = self._preprocess_result()
|
|
@@ -149,6 +149,10 @@ class LeapLoaderBase:
|
|
|
149
149
|
def has_custom_latent_space_decorator(self) -> bool:
|
|
150
150
|
pass
|
|
151
151
|
|
|
152
|
+
@abstractmethod
|
|
153
|
+
def get_custom_latent_space_names(self) -> Tuple[str, ...]:
|
|
154
|
+
pass
|
|
155
|
+
|
|
152
156
|
@abstractmethod
|
|
153
157
|
def get_heatmap_visualizer_raw_vis_input_arg_name(self, visualizer_name: str) -> Optional[str]:
|
|
154
158
|
pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/contract/responsedataclasses.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/cli_config_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/experiment_api/experiment_context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/plot_functions/plot_functions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.190 → code_loader-1.0.191.dev0}/code_loader/visualizers/default_visualizers.py
RENAMED
|
File without changes
|