train
¶
Functions:
-
get_datasets–Build TensorFlow datasets for training and validation.
-
main–Command-line interface for training an equilibrium profile reconstruction model.
-
parse_yaml_config–Parse a YAML run configuration file with custom tags.
-
train–Train a Keras model using the provided configuration and datasets.
get_datasets
¶
get_datasets(train_radial_res: int, val_radial_res: int, batch_size: int, rfp_only: bool) -> tuple[Dataset, Dataset]
Build TensorFlow datasets for training and validation.
This function instantiates :class:fpga_profile_reco.data.dataset.EQDataset
objects for the train and val splits under :data:cfg.DATA_DIR,
converts them into tf.data.Dataset pipelines and applies caching,
shuffling (train only), batching and prefetching.
Parameters:
-
(train_radial_res¶int) –Radial resolution used when loading the training split.
-
(val_radial_res¶int) –Radial resolution used when loading the validation split.
-
(batch_size¶int) –Batch size used for both training and validation pipelines.
-
(rfp_only¶bool) –If True, restrict the dataset to samples in the RFP regime (as defined by the dataset implementation).
Returns:
-
train_ds(Dataset) –Prepared training dataset producing batched samples.
-
val_ds(Dataset) –Prepared validation dataset producing batched samples.
Source code in src/fpga_profile_reco/core/train.py
13 14 15 16 17 18 19 20 21 22 23 24 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 | |
main
¶
main()
Command-line interface for training an equilibrium profile reconstruction model.
This function parses command-line arguments, loads a YAML run configuration, builds the training/validation datasets, instantiates the model, and runs training while writing logs and checkpoints to the configured output directories.
Command Line Parameters
config: pathlib.Path Path to the YAML run configuration file.
Source code in src/fpga_profile_reco/core/train.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
parse_yaml_config
¶
parse_yaml_config(yaml_config_path: Path) -> dict
Parse a YAML run configuration file with custom tags.
In addition to standard YAML types, this parser registers constructors on
:class:yaml.SafeLoader for a few custom tags used by this project:
!tuple: build Python tuples!CosineAnnealingScheduler: instantiate :class:fpga_profile_reco.utils.schedulers.CosineAnnealingScheduler!ReduceLROnPlateau: instantiate :class:keras.callbacks.ReduceLROnPlateau!EarlyStopping: instantiate :class:keras.callbacks.EarlyStopping
Parameters:
-
(yaml_config_path¶Path) –Path to the YAML configuration file.
Returns:
-
config(dict) –Parsed configuration dictionary.
Notes
This function registers YAML constructors globally via
:func:yaml.add_constructor (for yaml.SafeLoader).
Source code in src/fpga_profile_reco/core/train.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 102 103 104 105 106 107 108 109 110 111 112 | |
train
¶
Train a Keras model using the provided configuration and datasets.
The model is compiled with an Adam optimizer using training.initial_lr.
Training behavior is controlled by callback objects specified in the config,
including optional learning-rate scheduling and early stopping, plus
TensorBoard logging, CSV history logging, and best-checkpoint saving.
Parameters:
-
(model¶Model) –Model to train.
-
(config¶dict) –Run configuration dictionary as returned by :func:
parse_yaml_config. Expected keys includerun_configandtraining. -
(train_ds¶Dataset) –Training dataset.
-
(val_ds¶Dataset) –Validation dataset.
Returns:
-
history(dict) –History dictionary (i.e.,
history.history) returned by :meth:keras.Model.fit, mapping metric names to lists of epoch values.
Source code in src/fpga_profile_reco/core/train.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |