dragon-ml-toolbox 14.3.1__py3-none-any.whl → 16.0.0__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 dragon-ml-toolbox might be problematic. Click here for more details.
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-16.0.0.dist-info}/METADATA +10 -5
- dragon_ml_toolbox-16.0.0.dist-info/RECORD +51 -0
- ml_tools/ETL_cleaning.py +20 -20
- ml_tools/ETL_engineering.py +23 -25
- ml_tools/GUI_tools.py +20 -20
- ml_tools/MICE_imputation.py +3 -3
- ml_tools/ML_callbacks.py +43 -26
- ml_tools/ML_configuration.py +309 -0
- ml_tools/ML_datasetmaster.py +220 -260
- ml_tools/ML_evaluation.py +317 -81
- ml_tools/ML_evaluation_multi.py +127 -36
- ml_tools/ML_inference.py +249 -207
- ml_tools/ML_models.py +13 -102
- ml_tools/ML_models_advanced.py +1 -1
- ml_tools/ML_optimization.py +12 -12
- ml_tools/ML_scaler.py +11 -11
- ml_tools/ML_sequence_datasetmaster.py +341 -0
- ml_tools/ML_sequence_evaluation.py +215 -0
- ml_tools/ML_sequence_inference.py +391 -0
- ml_tools/ML_sequence_models.py +139 -0
- ml_tools/ML_trainer.py +1247 -338
- ml_tools/ML_utilities.py +51 -2
- ml_tools/ML_vision_datasetmaster.py +262 -118
- ml_tools/ML_vision_evaluation.py +26 -6
- ml_tools/ML_vision_inference.py +117 -140
- ml_tools/ML_vision_models.py +15 -1
- ml_tools/ML_vision_transformers.py +233 -7
- ml_tools/PSO_optimization.py +6 -6
- ml_tools/SQL.py +4 -4
- ml_tools/{keys.py → _keys.py} +45 -1
- ml_tools/_schema.py +1 -1
- ml_tools/ensemble_evaluation.py +54 -11
- ml_tools/ensemble_inference.py +7 -33
- ml_tools/ensemble_learning.py +1 -1
- ml_tools/optimization_tools.py +2 -2
- ml_tools/path_manager.py +5 -5
- ml_tools/utilities.py +1 -2
- dragon_ml_toolbox-14.3.1.dist-info/RECORD +0 -48
- ml_tools/RNN_forecast.py +0 -56
- ml_tools/_ML_vision_recipe.py +0 -88
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-16.0.0.dist-info}/WHEEL +0 -0
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-16.0.0.dist-info}/licenses/LICENSE +0 -0
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-16.0.0.dist-info}/licenses/LICENSE-THIRD-PARTY.md +0 -0
- {dragon_ml_toolbox-14.3.1.dist-info → dragon_ml_toolbox-16.0.0.dist-info}/top_level.txt +0 -0
ml_tools/ML_utilities.py
CHANGED
|
@@ -7,9 +7,10 @@ from torch import nn
|
|
|
7
7
|
from .path_manager import make_fullpath, list_subdirectories, list_files_by_extension
|
|
8
8
|
from ._script_info import _script_info
|
|
9
9
|
from ._logger import _LOGGER
|
|
10
|
-
from .
|
|
10
|
+
from ._keys import DatasetKeys, PytorchModelArchitectureKeys, PytorchArtifactPathKeys, SHAPKeys, UtilityKeys, PyTorchCheckpointKeys
|
|
11
11
|
from .utilities import load_dataframe
|
|
12
12
|
from .custom_logger import save_list_strings, custom_logger
|
|
13
|
+
from .serde import serialize_object_filename
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
__all__ = [
|
|
@@ -18,7 +19,8 @@ __all__ = [
|
|
|
18
19
|
"get_model_parameters",
|
|
19
20
|
"inspect_model_architecture",
|
|
20
21
|
"inspect_pth_file",
|
|
21
|
-
"set_parameter_requires_grad"
|
|
22
|
+
"set_parameter_requires_grad",
|
|
23
|
+
"save_pretrained_transforms"
|
|
22
24
|
]
|
|
23
25
|
|
|
24
26
|
|
|
@@ -524,5 +526,52 @@ def _set_params_grad(
|
|
|
524
526
|
return params_changed
|
|
525
527
|
|
|
526
528
|
|
|
529
|
+
def save_pretrained_transforms(model: nn.Module, output_dir: Union[str, Path]):
|
|
530
|
+
"""
|
|
531
|
+
Checks a model for the 'self._pretrained_default_transforms' attribute, if found,
|
|
532
|
+
serializes the returned transform object as a .joblib file.
|
|
533
|
+
|
|
534
|
+
This saves the callable transform object itself for
|
|
535
|
+
later use, such as passing it directly to the 'transform_source'
|
|
536
|
+
argument of the PyTorchVisionInferenceHandler.
|
|
537
|
+
|
|
538
|
+
Args:
|
|
539
|
+
model (nn.Module): The model instance to check.
|
|
540
|
+
output_dir (str | Path): The directory where the transform file will be saved.
|
|
541
|
+
"""
|
|
542
|
+
output_filename = "pretrained_model_transformations"
|
|
543
|
+
|
|
544
|
+
# 1. Check for the "secret attribute"
|
|
545
|
+
if not hasattr(model, '_pretrained_default_transforms'):
|
|
546
|
+
_LOGGER.warning(f"Model of type {type(model).__name__} does not have the required attribute. No transformations saved.")
|
|
547
|
+
return
|
|
548
|
+
|
|
549
|
+
# 2. Get the transform object
|
|
550
|
+
try:
|
|
551
|
+
transform_obj = model._pretrained_default_transforms
|
|
552
|
+
except Exception as e:
|
|
553
|
+
_LOGGER.error(f"Error calling the required attribute on model: {e}")
|
|
554
|
+
return
|
|
555
|
+
|
|
556
|
+
# 3. Check if the object is actually there
|
|
557
|
+
if transform_obj is None:
|
|
558
|
+
_LOGGER.warning(f"Model {type(model).__name__} has the required attribute but returned None. No transforms saved.")
|
|
559
|
+
return
|
|
560
|
+
|
|
561
|
+
# 4. Serialize and save using serde
|
|
562
|
+
try:
|
|
563
|
+
serialize_object_filename(
|
|
564
|
+
obj=transform_obj,
|
|
565
|
+
save_dir=output_dir,
|
|
566
|
+
filename=output_filename,
|
|
567
|
+
verbose=True,
|
|
568
|
+
raise_on_error=True
|
|
569
|
+
)
|
|
570
|
+
# _LOGGER.info(f"Successfully saved pretrained transforms to '{output_dir}'.")
|
|
571
|
+
except Exception as e:
|
|
572
|
+
_LOGGER.error(f"Failed to serialize transformations: {e}")
|
|
573
|
+
raise
|
|
574
|
+
|
|
575
|
+
|
|
527
576
|
def info():
|
|
528
577
|
_script_info(__all__)
|