stouputils 1.12.2__py3-none-any.whl → 1.13.1__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.
- stouputils/__main__.py +11 -6
- stouputils/continuous_delivery/pypi.py +39 -1
- stouputils/continuous_delivery/pypi.pyi +9 -0
- stouputils/ctx.py +408 -408
- stouputils/data_science/config/set.py +125 -125
- stouputils/data_science/models/keras_utils/callbacks/model_checkpoint_v2.py +31 -31
- stouputils/data_science/utils.py +285 -285
- stouputils/installer/__init__.py +18 -18
- stouputils/installer/linux.py +144 -144
- stouputils/installer/main.py +223 -223
- stouputils/installer/windows.py +136 -136
- stouputils/py.typed +1 -1
- stouputils/stouputils/__init__.pyi +15 -0
- stouputils/stouputils/_deprecated.pyi +12 -0
- stouputils/stouputils/all_doctests.pyi +46 -0
- stouputils/stouputils/applications/__init__.pyi +2 -0
- stouputils/stouputils/applications/automatic_docs.pyi +106 -0
- stouputils/stouputils/applications/upscaler/__init__.pyi +3 -0
- stouputils/stouputils/applications/upscaler/config.pyi +18 -0
- stouputils/stouputils/applications/upscaler/image.pyi +109 -0
- stouputils/stouputils/applications/upscaler/video.pyi +60 -0
- stouputils/stouputils/archive.pyi +67 -0
- stouputils/stouputils/backup.pyi +109 -0
- stouputils/stouputils/collections.pyi +86 -0
- stouputils/stouputils/continuous_delivery/__init__.pyi +5 -0
- stouputils/stouputils/continuous_delivery/cd_utils.pyi +129 -0
- stouputils/stouputils/continuous_delivery/github.pyi +162 -0
- stouputils/stouputils/continuous_delivery/pypi.pyi +53 -0
- stouputils/stouputils/continuous_delivery/pyproject.pyi +67 -0
- stouputils/stouputils/continuous_delivery/stubs.pyi +39 -0
- stouputils/stouputils/ctx.pyi +211 -0
- stouputils/stouputils/decorators.pyi +242 -0
- stouputils/stouputils/image.pyi +172 -0
- stouputils/stouputils/installer/__init__.pyi +5 -0
- stouputils/stouputils/installer/common.pyi +39 -0
- stouputils/stouputils/installer/downloader.pyi +24 -0
- stouputils/stouputils/installer/linux.pyi +39 -0
- stouputils/stouputils/installer/main.pyi +57 -0
- stouputils/stouputils/installer/windows.pyi +31 -0
- stouputils/stouputils/io.pyi +213 -0
- stouputils/stouputils/parallel.pyi +211 -0
- stouputils/stouputils/print.pyi +136 -0
- stouputils/stouputils/version_pkg.pyi +15 -0
- {stouputils-1.12.2.dist-info → stouputils-1.13.1.dist-info}/METADATA +2 -2
- {stouputils-1.12.2.dist-info → stouputils-1.13.1.dist-info}/RECORD +47 -16
- {stouputils-1.12.2.dist-info → stouputils-1.13.1.dist-info}/WHEEL +0 -0
- {stouputils-1.12.2.dist-info → stouputils-1.13.1.dist-info}/entry_points.txt +0 -0
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
""" Configuration file for the project. """
|
|
2
|
-
|
|
3
|
-
# Imports
|
|
4
|
-
import os
|
|
5
|
-
from typing import Literal
|
|
6
|
-
|
|
7
|
-
from stouputils.decorators import LogLevels
|
|
8
|
-
from stouputils.io import get_root_path
|
|
9
|
-
|
|
10
|
-
# Environment variables
|
|
11
|
-
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "9" # Suppress TensorFlow logging
|
|
12
|
-
os.environ["GRPC_VERBOSITY"] = "ERROR" # Suppress gRPC logging
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# Configuration class
|
|
16
|
-
class DataScienceConfig:
|
|
17
|
-
""" Configuration class for the project. """
|
|
18
|
-
|
|
19
|
-
# Common
|
|
20
|
-
SEED: int = 42
|
|
21
|
-
""" Seed for the random number generator. """
|
|
22
|
-
|
|
23
|
-
ERROR_LOG: LogLevels = LogLevels.WARNING_TRACEBACK
|
|
24
|
-
""" Log level for errors for all functions. """
|
|
25
|
-
|
|
26
|
-
AUGMENTED_FILE_SUFFIX: str = "_aug_"
|
|
27
|
-
""" Suffix for augmented files, e.g. 'image_008_aug_1.png'. """
|
|
28
|
-
|
|
29
|
-
AUGMENTED_DIRECTORY_PREFIX: str = "aug_"
|
|
30
|
-
""" Prefix for augmented directories, e.g. 'data/hip_implant' -> 'data/aug_hip_implant'. """
|
|
31
|
-
|
|
32
|
-
PREPROCESSED_DIRECTORY_SUFFIX: str = "_preprocessed"
|
|
33
|
-
""" Suffix for preprocessed directories, e.g. 'data/hip_implant' -> 'data/hip_implant_preprocessed'. """
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# Directories
|
|
37
|
-
ROOT: str = get_root_path(__file__, go_up=3)
|
|
38
|
-
""" Root directory of the project. """
|
|
39
|
-
|
|
40
|
-
MLFLOW_FOLDER: str = f"{ROOT}/mlruns"
|
|
41
|
-
""" Folder containing the mlflow data. """
|
|
42
|
-
MLFLOW_URI: str = f"file://{MLFLOW_FOLDER}"
|
|
43
|
-
""" URI to the mlflow data. """
|
|
44
|
-
|
|
45
|
-
DATA_FOLDER: str = f"{ROOT}/data"
|
|
46
|
-
""" Folder containing all the data (e.g. subfolders containing images). """
|
|
47
|
-
|
|
48
|
-
TEMP_FOLDER: str = f"{ROOT}/temp"
|
|
49
|
-
""" Folder containing temporary files (e.g. models checkpoints, plots, etc.). """
|
|
50
|
-
|
|
51
|
-
LOGS_FOLDER: str = f"{ROOT}/logs"
|
|
52
|
-
""" Folder containing the logs. """
|
|
53
|
-
|
|
54
|
-
TENSORBOARD_FOLDER: str = f"{ROOT}/tensorboard"
|
|
55
|
-
""" Folder containing the tensorboard logs. """
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
# Behaviours
|
|
59
|
-
TEST_SIZE: float = 0.2
|
|
60
|
-
""" Size of the test set by default (0.2 means 80% training, 20% test). """
|
|
61
|
-
|
|
62
|
-
VALIDATION_SIZE: float = 0.2
|
|
63
|
-
""" Size of the validation set by default (0.2 means 80% training, 20% validation). """
|
|
64
|
-
|
|
65
|
-
# Machine learning
|
|
66
|
-
SAVE_MODEL: bool = False
|
|
67
|
-
""" If the model should be saved in the mlflow folder using mlflow.*.save_model. """
|
|
68
|
-
|
|
69
|
-
DO_SALIENCY_AND_GRADCAM: bool = True
|
|
70
|
-
""" If the saliency and gradcam should be done during the run. """
|
|
71
|
-
|
|
72
|
-
DO_LEARNING_RATE_FINDER: Literal[0, 1, 2] = 1
|
|
73
|
-
""" If the learning rate finder should be done during the run.
|
|
74
|
-
0: no, 1: only plot, 2: plot and use value for the remaining run
|
|
75
|
-
"""
|
|
76
|
-
|
|
77
|
-
DO_UNFREEZE_FINDER: Literal[0, 1, 2] = 0
|
|
78
|
-
""" If the unfreeze finder should be done during the run.
|
|
79
|
-
0: no, 1: only plot, 2: plot and use value for the remaining run
|
|
80
|
-
"""
|
|
81
|
-
|
|
82
|
-
DO_FIT_IN_SUBPROCESS: bool = True
|
|
83
|
-
""" If the model should be fitted in a subprocess.
|
|
84
|
-
Is memory efficient, and more stable. Turn it off only if you are having issues.
|
|
85
|
-
|
|
86
|
-
Note: This allow a program to make lots of runs without getting killed by the OS for using too much resources.
|
|
87
|
-
(e.g. LeaveOneOut Cross Validation, Grid Search, etc.)
|
|
88
|
-
"""
|
|
89
|
-
|
|
90
|
-
MIXED_PRECISION_POLICY: Literal["mixed_float16", "mixed_bfloat16", "float32"] = "mixed_float16"
|
|
91
|
-
""" Mixed precision policy to use. Turn back to "float32" if you are having issues with a specific model or metrics.
|
|
92
|
-
See: https://www.tensorflow.org/guide/mixed_precision
|
|
93
|
-
"""
|
|
94
|
-
|
|
95
|
-
TENSORFLOW_DEVICE: str = "/gpu:1"
|
|
96
|
-
""" TensorFlow device to use. """
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
@classmethod
|
|
101
|
-
def update_root(cls, new_root: str) -> None:
|
|
102
|
-
""" Update the root directory and recalculate all dependent paths.
|
|
103
|
-
|
|
104
|
-
Args:
|
|
105
|
-
new_root: The new root directory path.
|
|
106
|
-
"""
|
|
107
|
-
cls.ROOT = new_root
|
|
108
|
-
|
|
109
|
-
# Update all paths that depend on ROOT
|
|
110
|
-
cls.MLFLOW_FOLDER = f"{cls.ROOT}/mlruns"
|
|
111
|
-
cls.MLFLOW_URI = f"file://{cls.MLFLOW_FOLDER}"
|
|
112
|
-
cls.DATA_FOLDER = f"{cls.ROOT}/data"
|
|
113
|
-
cls.TEMP_FOLDER = f"{cls.ROOT}/temp"
|
|
114
|
-
cls.LOGS_FOLDER = f"{cls.ROOT}/logs"
|
|
115
|
-
cls.TENSORBOARD_FOLDER = f"{cls.ROOT}/tensorboard"
|
|
116
|
-
|
|
117
|
-
# Fix MLFLOW_URI for Windows by adding a missing slash
|
|
118
|
-
if os.name == "nt":
|
|
119
|
-
cls.MLFLOW_URI = cls.MLFLOW_URI.replace("file:", "file:/")
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
# Fix MLFLOW_URI for Windows by adding a missing slash
|
|
123
|
-
if os.name == "nt":
|
|
124
|
-
DataScienceConfig.MLFLOW_URI = DataScienceConfig.MLFLOW_URI.replace("file:", "file:/")
|
|
125
|
-
|
|
1
|
+
""" Configuration file for the project. """
|
|
2
|
+
|
|
3
|
+
# Imports
|
|
4
|
+
import os
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
from stouputils.decorators import LogLevels
|
|
8
|
+
from stouputils.io import get_root_path
|
|
9
|
+
|
|
10
|
+
# Environment variables
|
|
11
|
+
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "9" # Suppress TensorFlow logging
|
|
12
|
+
os.environ["GRPC_VERBOSITY"] = "ERROR" # Suppress gRPC logging
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Configuration class
|
|
16
|
+
class DataScienceConfig:
|
|
17
|
+
""" Configuration class for the project. """
|
|
18
|
+
|
|
19
|
+
# Common
|
|
20
|
+
SEED: int = 42
|
|
21
|
+
""" Seed for the random number generator. """
|
|
22
|
+
|
|
23
|
+
ERROR_LOG: LogLevels = LogLevels.WARNING_TRACEBACK
|
|
24
|
+
""" Log level for errors for all functions. """
|
|
25
|
+
|
|
26
|
+
AUGMENTED_FILE_SUFFIX: str = "_aug_"
|
|
27
|
+
""" Suffix for augmented files, e.g. 'image_008_aug_1.png'. """
|
|
28
|
+
|
|
29
|
+
AUGMENTED_DIRECTORY_PREFIX: str = "aug_"
|
|
30
|
+
""" Prefix for augmented directories, e.g. 'data/hip_implant' -> 'data/aug_hip_implant'. """
|
|
31
|
+
|
|
32
|
+
PREPROCESSED_DIRECTORY_SUFFIX: str = "_preprocessed"
|
|
33
|
+
""" Suffix for preprocessed directories, e.g. 'data/hip_implant' -> 'data/hip_implant_preprocessed'. """
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Directories
|
|
37
|
+
ROOT: str = get_root_path(__file__, go_up=3)
|
|
38
|
+
""" Root directory of the project. """
|
|
39
|
+
|
|
40
|
+
MLFLOW_FOLDER: str = f"{ROOT}/mlruns"
|
|
41
|
+
""" Folder containing the mlflow data. """
|
|
42
|
+
MLFLOW_URI: str = f"file://{MLFLOW_FOLDER}"
|
|
43
|
+
""" URI to the mlflow data. """
|
|
44
|
+
|
|
45
|
+
DATA_FOLDER: str = f"{ROOT}/data"
|
|
46
|
+
""" Folder containing all the data (e.g. subfolders containing images). """
|
|
47
|
+
|
|
48
|
+
TEMP_FOLDER: str = f"{ROOT}/temp"
|
|
49
|
+
""" Folder containing temporary files (e.g. models checkpoints, plots, etc.). """
|
|
50
|
+
|
|
51
|
+
LOGS_FOLDER: str = f"{ROOT}/logs"
|
|
52
|
+
""" Folder containing the logs. """
|
|
53
|
+
|
|
54
|
+
TENSORBOARD_FOLDER: str = f"{ROOT}/tensorboard"
|
|
55
|
+
""" Folder containing the tensorboard logs. """
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# Behaviours
|
|
59
|
+
TEST_SIZE: float = 0.2
|
|
60
|
+
""" Size of the test set by default (0.2 means 80% training, 20% test). """
|
|
61
|
+
|
|
62
|
+
VALIDATION_SIZE: float = 0.2
|
|
63
|
+
""" Size of the validation set by default (0.2 means 80% training, 20% validation). """
|
|
64
|
+
|
|
65
|
+
# Machine learning
|
|
66
|
+
SAVE_MODEL: bool = False
|
|
67
|
+
""" If the model should be saved in the mlflow folder using mlflow.*.save_model. """
|
|
68
|
+
|
|
69
|
+
DO_SALIENCY_AND_GRADCAM: bool = True
|
|
70
|
+
""" If the saliency and gradcam should be done during the run. """
|
|
71
|
+
|
|
72
|
+
DO_LEARNING_RATE_FINDER: Literal[0, 1, 2] = 1
|
|
73
|
+
""" If the learning rate finder should be done during the run.
|
|
74
|
+
0: no, 1: only plot, 2: plot and use value for the remaining run
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
DO_UNFREEZE_FINDER: Literal[0, 1, 2] = 0
|
|
78
|
+
""" If the unfreeze finder should be done during the run.
|
|
79
|
+
0: no, 1: only plot, 2: plot and use value for the remaining run
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
DO_FIT_IN_SUBPROCESS: bool = True
|
|
83
|
+
""" If the model should be fitted in a subprocess.
|
|
84
|
+
Is memory efficient, and more stable. Turn it off only if you are having issues.
|
|
85
|
+
|
|
86
|
+
Note: This allow a program to make lots of runs without getting killed by the OS for using too much resources.
|
|
87
|
+
(e.g. LeaveOneOut Cross Validation, Grid Search, etc.)
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
MIXED_PRECISION_POLICY: Literal["mixed_float16", "mixed_bfloat16", "float32"] = "mixed_float16"
|
|
91
|
+
""" Mixed precision policy to use. Turn back to "float32" if you are having issues with a specific model or metrics.
|
|
92
|
+
See: https://www.tensorflow.org/guide/mixed_precision
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
TENSORFLOW_DEVICE: str = "/gpu:1"
|
|
96
|
+
""" TensorFlow device to use. """
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@classmethod
|
|
101
|
+
def update_root(cls, new_root: str) -> None:
|
|
102
|
+
""" Update the root directory and recalculate all dependent paths.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
new_root: The new root directory path.
|
|
106
|
+
"""
|
|
107
|
+
cls.ROOT = new_root
|
|
108
|
+
|
|
109
|
+
# Update all paths that depend on ROOT
|
|
110
|
+
cls.MLFLOW_FOLDER = f"{cls.ROOT}/mlruns"
|
|
111
|
+
cls.MLFLOW_URI = f"file://{cls.MLFLOW_FOLDER}"
|
|
112
|
+
cls.DATA_FOLDER = f"{cls.ROOT}/data"
|
|
113
|
+
cls.TEMP_FOLDER = f"{cls.ROOT}/temp"
|
|
114
|
+
cls.LOGS_FOLDER = f"{cls.ROOT}/logs"
|
|
115
|
+
cls.TENSORBOARD_FOLDER = f"{cls.ROOT}/tensorboard"
|
|
116
|
+
|
|
117
|
+
# Fix MLFLOW_URI for Windows by adding a missing slash
|
|
118
|
+
if os.name == "nt":
|
|
119
|
+
cls.MLFLOW_URI = cls.MLFLOW_URI.replace("file:", "file:/")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# Fix MLFLOW_URI for Windows by adding a missing slash
|
|
123
|
+
if os.name == "nt":
|
|
124
|
+
DataScienceConfig.MLFLOW_URI = DataScienceConfig.MLFLOW_URI.replace("file:", "file:/")
|
|
125
|
+
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
# pyright: reportMissingTypeStubs=false
|
|
3
|
-
# pyright: reportUnknownMemberType=false
|
|
4
|
-
|
|
5
|
-
# Imports
|
|
6
|
-
from typing import Any
|
|
7
|
-
|
|
8
|
-
from keras.callbacks import ModelCheckpoint
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class ModelCheckpointV2(ModelCheckpoint):
|
|
12
|
-
""" Model checkpoint callback but only starts after a given number of epochs.
|
|
13
|
-
|
|
14
|
-
Args:
|
|
15
|
-
epochs_before_start (int): Number of epochs before starting the checkpointing
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
def __init__(self, epochs_before_start: int = 3, *args: Any, **kwargs: Any) -> None:
|
|
19
|
-
super().__init__(*args, **kwargs)
|
|
20
|
-
self.epochs_before_start = epochs_before_start
|
|
21
|
-
self.current_epoch = 0
|
|
22
|
-
|
|
23
|
-
def on_batch_end(self, batch: int, logs: dict[str, Any] | None = None) -> None:
|
|
24
|
-
if self.current_epoch >= self.epochs_before_start:
|
|
25
|
-
super().on_batch_end(batch, logs)
|
|
26
|
-
|
|
27
|
-
def on_epoch_end(self, epoch: int, logs: dict[str, Any] | None = None) -> None:
|
|
28
|
-
self.current_epoch = epoch
|
|
29
|
-
if epoch >= self.epochs_before_start:
|
|
30
|
-
super().on_epoch_end(epoch, logs)
|
|
31
|
-
|
|
1
|
+
|
|
2
|
+
# pyright: reportMissingTypeStubs=false
|
|
3
|
+
# pyright: reportUnknownMemberType=false
|
|
4
|
+
|
|
5
|
+
# Imports
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from keras.callbacks import ModelCheckpoint
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ModelCheckpointV2(ModelCheckpoint):
|
|
12
|
+
""" Model checkpoint callback but only starts after a given number of epochs.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
epochs_before_start (int): Number of epochs before starting the checkpointing
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, epochs_before_start: int = 3, *args: Any, **kwargs: Any) -> None:
|
|
19
|
+
super().__init__(*args, **kwargs)
|
|
20
|
+
self.epochs_before_start = epochs_before_start
|
|
21
|
+
self.current_epoch = 0
|
|
22
|
+
|
|
23
|
+
def on_batch_end(self, batch: int, logs: dict[str, Any] | None = None) -> None:
|
|
24
|
+
if self.current_epoch >= self.epochs_before_start:
|
|
25
|
+
super().on_batch_end(batch, logs)
|
|
26
|
+
|
|
27
|
+
def on_epoch_end(self, epoch: int, logs: dict[str, Any] | None = None) -> None:
|
|
28
|
+
self.current_epoch = epoch
|
|
29
|
+
if epoch >= self.epochs_before_start:
|
|
30
|
+
super().on_epoch_end(epoch, logs)
|
|
31
|
+
|