|
3 | 3 | A module which defines the classes and methods |
4 | 4 | to manage training of the psf model. |
5 | 5 |
|
6 | | -:Author: Jennifer Pollack <jennifer.pollack@cea.fr> |
| 6 | +:Authors: Jennifer Pollack <jennifer.pollack@cea.fr>, Tobias Liaudat <tobias.liaudat@cea.fr>, Ezequiel Centofanti <ezequiel.centofanti@cea.fr> |
7 | 7 |
|
8 | 8 | """ |
9 | 9 |
|
|
18 | 18 | logger = logging.getLogger(__name__) |
19 | 19 |
|
20 | 20 |
|
| 21 | +def get_gpu_info(): |
| 22 | + """Get GPU Information. |
| 23 | +
|
| 24 | + A function to return GPU |
| 25 | + device name. |
| 26 | +
|
| 27 | + Returns |
| 28 | + ------- |
| 29 | + device_name: str |
| 30 | + Name of GPU device |
| 31 | +
|
| 32 | + """ |
| 33 | + device_name = tf.test.gpu_device_name() |
| 34 | + return device_name |
| 35 | + |
21 | 36 | def setup_training(): |
22 | 37 | """Set up Training. |
23 | 38 |
|
24 | 39 | A function to setup training. |
25 | 40 |
|
26 | | -
|
27 | 41 | """ |
28 | 42 | device_name = get_gpu_info() |
29 | 43 | logger.info(f"Found GPU at: {device_name}") |
@@ -257,23 +271,32 @@ def _prepare_callbacks( |
257 | 271 | ) |
258 | 272 |
|
259 | 273 |
|
260 | | -def get_gpu_info(): |
261 | | - """Get GPU Information. |
262 | | -
|
263 | | - A function to return GPU |
264 | | - device name. |
| 274 | +def get_loss_metrics_monitor_and_outputs(training_handler, data_conf): |
| 275 | + """Factory to return fresh loss, metrics (param & non-param), monitor, and outputs for the current cycle. |
| 276 | + |
| 277 | + Parameters |
| 278 | + ---------- |
| 279 | + training_handler: TrainingParamsHandler |
| 280 | + TrainingParamsHandler object containing training parameters |
| 281 | + data_conf: object |
| 282 | + Data configuration object containing training and test data |
265 | 283 |
|
266 | 284 | Returns |
267 | 285 | ------- |
268 | | - device_name: str |
269 | | - Name of GPU device |
270 | | -
|
| 286 | + loss: tf.keras.losses.Loss |
| 287 | + Loss function to be used for training |
| 288 | + param_metrics: list |
| 289 | + List of metrics for the parametric model |
| 290 | + non_param_metrics: list |
| 291 | + List of metrics for the non-parametric model |
| 292 | + monitor: str |
| 293 | + Metric to monitor for saving the model |
| 294 | + outputs: tf.Tensor |
| 295 | + Tensor containing the outputs for training |
| 296 | + output_val: tf.Tensor |
| 297 | + Tensor containing the outputs for validation |
| 298 | + |
271 | 299 | """ |
272 | | - device_name = tf.test.gpu_device_name() |
273 | | - return device_name |
274 | | - |
275 | | -def get_loss_metrics_monitor_and_outputs(training_handler, data_conf): |
276 | | - """Factory to return fresh loss, metrics (param & non-param), monitor, and outputs for the current cycle.""" |
277 | 300 |
|
278 | 301 | if training_handler.training_hparams.loss == "mask_mse": |
279 | 302 | loss = train_utils.MaskedMeanSquaredError() |
@@ -304,25 +327,46 @@ def train( |
304 | 327 | optimizer_dir, |
305 | 328 | psf_model_dir, |
306 | 329 | ): |
307 | | - """Train. |
| 330 | + """ |
| 331 | + Train the PSF model over one or more parametric and non-parametric training cycles. |
308 | 332 |
|
309 | | - A function to train the psf model. |
| 333 | + This function manages multi-cycle training of a parametric + non-parametric PSF model, |
| 334 | + including initialization, loss/metric configuration, optimizer setup, model checkpointing, |
| 335 | + and optional projection or resetting of non-parametric features. Each cycle can include |
| 336 | + both parametric and non-parametric training stages, and training history is saved for each. |
310 | 337 |
|
311 | 338 | Parameters |
312 | 339 | ---------- |
313 | | - training_params: Recursive Namespace object |
314 | | - Recursive Namespace object containing the training parameters |
315 | | - training_data: obj |
316 | | - TrainingDataHandler object containing the training data parameters |
317 | | - test_data: object |
318 | | - TestDataHandler object containing the test data parameters |
319 | | - checkpoint_dir: str |
320 | | - Absolute path to checkpoint directory |
321 | | - optimizer_dir: str |
322 | | - Absolute path to optimizer history directory |
323 | | - psf_model_dir: str |
324 | | - Absolute path to psf model directory |
| 340 | + training_params : RecursiveNamespace |
| 341 | + Contains all training configuration parameters, including: |
| 342 | + - learning rates per cycle |
| 343 | + - number of epochs per component per cycle |
| 344 | + - model type and training behavior flags |
| 345 | + - multi-cycle definitions and callbacks |
| 346 | +
|
| 347 | + data_conf : object |
| 348 | + Contains training and validation datasets via attributes: |
| 349 | + - data_conf.training_data: TrainingDataHandler instance with SEDs and positions |
| 350 | + - data_conf.test_data: TestDataHandler instance with validation SEDs and positions |
| 351 | +
|
| 352 | + checkpoint_dir : str |
| 353 | + Directory where model checkpoints will be saved during training. |
| 354 | +
|
| 355 | + optimizer_dir : str |
| 356 | + Directory where the optimizer history (as a NumPy .npy file) will be stored. |
| 357 | +
|
| 358 | + psf_model_dir : str |
| 359 | + Directory where the final trained PSF model weights will be saved per cycle. |
| 360 | +
|
| 361 | + Returns |
| 362 | + ------- |
| 363 | + None |
325 | 364 |
|
| 365 | + Side Effects |
| 366 | + ------------ |
| 367 | + - Saves model weights to `psf_model_dir` per training cycle (or final one if not all saved) |
| 368 | + - Saves optimizer histories to `optimizer_dir` |
| 369 | + - Logs cycle information and time durations |
326 | 370 | """ |
327 | 371 | # Start measuring elapsed time |
328 | 372 | starting_time = time.time() |
|
0 commit comments