viberl.utils.experiment_manager
Experiment management utilities.
This module provides utilities for managing experiment directories, tensorboard logging, and model checkpoints.
Classes:
Name | Description |
---|---|
ExperimentManager |
Manages experiment directories with automatic naming and organization. |
Functions:
Name | Description |
---|---|
create_experiment |
Convenience function to create a new experiment. |
ExperimentManager
ExperimentManager(
experiment_name: str, base_dir: str = 'experiments', timestamp_format: str = '%Y%m%d_%H%M%S'
)
Manages experiment directories with automatic naming and organization.
Creates experiment directories in the format: experiments/{experiment_name}_{timestamp}/ ├── tb_logs/ # TensorBoard logs ├── models/ # Saved model checkpoints └── training.log # Training log file
Initialize experiment manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
experiment_name
|
str
|
Name of the experiment |
required |
base_dir
|
str
|
Base directory for experiments |
'experiments'
|
timestamp_format
|
str
|
Format for timestamp in directory name |
'%Y%m%d_%H%M%S'
|
Methods:
Name | Description |
---|---|
get_tb_logs_path |
Get path to TensorBoard logs directory. |
get_models_path |
Get path to models directory. |
get_training_log_path |
Get path to training log file. |
configure_file_logging |
Configure loguru to log to training.log file. |
log_command_line_args |
Log command line arguments to training.log. |
get_experiment_path |
Get path to experiment directory. |
get_exp_dir |
Get path to experiment directory (alias for get_experiment_path). |
save_model |
Get full path for saving a model. |
list_experiments |
List all existing experiments. |
get_latest_experiment |
Get the latest experiment directory. |
print_experiment_info |
Print information about the current experiment. |
create_from_existing |
Create ExperimentManager from existing experiment directory. |
Attributes:
Name | Type | Description |
---|---|---|
experiment_name |
|
|
base_dir |
|
|
timestamp_format |
|
|
experiment_dir |
|
|
exp_dir |
|
|
tb_logs_dir |
|
|
models_dir |
|
Source code in viberl/utils/experiment_manager.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
experiment_name
instance-attribute
experiment_name = experiment_name
base_dir
instance-attribute
base_dir = Path(base_dir)
timestamp_format
instance-attribute
timestamp_format = timestamp_format
experiment_dir
instance-attribute
experiment_dir = base_dir / f'{experiment_name}_{timestamp}'
exp_dir
instance-attribute
exp_dir = experiment_dir
tb_logs_dir
instance-attribute
tb_logs_dir = exp_dir / 'tb_logs'
models_dir
instance-attribute
models_dir = exp_dir / 'models'
get_tb_logs_path
get_tb_logs_path() -> Path
Get path to TensorBoard logs directory.
Source code in viberl/utils/experiment_manager.py
63 64 65 |
|
get_models_path
get_models_path() -> Path
Get path to models directory.
Source code in viberl/utils/experiment_manager.py
67 68 69 |
|
get_training_log_path
get_training_log_path() -> Path
Get path to training log file.
Source code in viberl/utils/experiment_manager.py
71 72 73 |
|
configure_file_logging
configure_file_logging(log_level: str = 'INFO') -> None
Configure loguru to log to training.log file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log_level
|
str
|
Logging level (DEBUG, INFO, WARNING, ERROR) |
'INFO'
|
Source code in viberl/utils/experiment_manager.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
log_command_line_args
log_command_line_args(args: object) -> None
Log command line arguments to training.log.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
object
|
Parsed argparse arguments object |
required |
Source code in viberl/utils/experiment_manager.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
get_experiment_path
get_experiment_path() -> Path
Get path to experiment directory.
Source code in viberl/utils/experiment_manager.py
123 124 125 |
|
get_exp_dir
get_exp_dir() -> Path
Get path to experiment directory (alias for get_experiment_path).
Source code in viberl/utils/experiment_manager.py
127 128 129 |
|
save_model
save_model(model_name: str) -> Path
Get full path for saving a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str
|
Name of the model file (without extension) |
required |
Returns:
Type | Description |
---|---|
Path
|
Full path for model file |
Source code in viberl/utils/experiment_manager.py
131 132 133 134 135 136 137 138 139 140 141 |
|
list_experiments
list_experiments() -> list[Path]
List all existing experiments.
Source code in viberl/utils/experiment_manager.py
143 144 145 146 147 148 149 150 151 152 153 154 |
|
get_latest_experiment
get_latest_experiment() -> Path | None
Get the latest experiment directory.
Source code in viberl/utils/experiment_manager.py
156 157 158 159 |
|
print_experiment_info
print_experiment_info() -> None
Print information about the current experiment.
Source code in viberl/utils/experiment_manager.py
161 162 163 164 165 166 167 |
|
create_from_existing
staticmethod
create_from_existing(experiment_path: str | Path) -> ExperimentManager
Create ExperimentManager from existing experiment directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
experiment_path
|
str | Path
|
Path to existing experiment directory |
required |
Returns:
Type | Description |
---|---|
ExperimentManager
|
ExperimentManager instance |
Source code in viberl/utils/experiment_manager.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
create_experiment
create_experiment(
experiment_name: str, base_dir: str = 'experiments', print_info: bool = True
) -> ExperimentManager
Convenience function to create a new experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
experiment_name
|
str
|
Name of the experiment |
required |
base_dir
|
str
|
Base directory for experiments |
'experiments'
|
print_info
|
bool
|
Whether to print experiment info |
True
|
Returns:
Type | Description |
---|---|
ExperimentManager
|
ExperimentManager instance |
Source code in viberl/utils/experiment_manager.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|