sage.exec.director
Filename : director.py Description : Short description of the file
Created on 2021-11-21 15:30:43
__author__ = Narenraju Nagarajan __copyright__ = Copyright 2025, Sage __license__ = MIT Licence __version__ = 0.0.1 __maintainer__ = Narenraju Nagarajan __affiliation__ = University of Glasgow __email__ = N/A __status__ = [‘inProgress’, ‘Archived’, ‘inUsage’, ‘Debugging’]
GitHub Repository: https://github.com/nnarenraju/sage
Documentation: NULL
Attributes
Classes
Top-level orchestrator for the Sage pipeline (legacy DataLoader mode). |
Functions
Argument parser for directors |
Module Contents
- parse_args()[source]
Argument parser for directors
- Returns:
populated namespace object
- Return type:
opts (namespace object)
- class SageDirector(opts)[source]
Top-level orchestrator for the Sage pipeline (legacy DataLoader mode).
Provides a step-by-step API to configure, build, train, and evaluate a Sage detection network. Each major concern is handled by a dedicated
prepare_*method that can be called individually or viarun()for a full end-to-end execution.This class wraps the legacy
sage.factory.legacytraining loop that uses PyTorchDataLoaderobjects. For the modern on-the-fly (OTF) training loop, seesage.factory.training.- Parameters:
opts (argparse.Namespace) – Parsed command-line options from
parse_args().
- optimiser, scheduler, loss_function
Configured PyTorch training objects.
- train_loader, val_loader, aux_loader
Data loaders for training, validation, and auxiliary data.
- Type:
DataLoader
- checkpoint[source]
Loaded checkpoint state for resuming, or
Nonefor a fresh run.- Type:
dict or None
- prepare_data(train_fold=None, val_fold=None, balance_params=None)[source]
Prepare dataset objects and DataLoader instances.
Creates the export directory, optionally generates the dataset, and builds training / validation / auxiliary DataLoader objects.
- initialise_model()[source]
Instantiate the neural network and optionally load pretrained weights.
If
cfg.pretrainedisTrueandcfg.weights_pathis set, loads a weights snapshot and optionally freezes layers for transfer learning.- Raises:
ValueError – If
cfg.pretrainedisTruebut no validweights_pathis configured, or if the checkpoint file does not exist.
- prepare_model_summary()[source]
Optionally print a model summary and write a TensorBoard graph.
Triggered only when
opts.summaryisTrue. Usestorchsummary.summary()for a parameter-count table andSummaryWriterto emit a computation graph viewable in TensorBoard.
- prepare_optimiser()[source]
Instantiate the optimiser from
cfg.optimiserandcfg.optimiser_params.Sets
optimisertoNonewhen no optimiser is configured.
- prepare_scheduler()[source]
Instantiate the learning-rate scheduler from
cfg.schedulerandcfg.scheduler_params.- Returns:
The configured scheduler, or
Noneif not used.- Return type:
scheduler or None
- prepare_loss_function()[source]
Assign
cfg.loss_functiontoloss_function.
- prepare_checkpoint()[source]
Load a checkpoint to resume training.
When
cfg.resume_from_checkpointisTrue, loads the model and optimiser state dictionaries fromcfg.checkpoint_pathso that training resumes from the saved epoch.
- train_model()[source]
Launch the legacy DataLoader-based training loop.
Delegates to
sage.factory.legacy.train()with all prepared components (model, optimiser, scheduler, loss, loaders, checkpoint). UpdatesNetworkwith the best weights returned after training.
- test_model()[source]
Run inference over foreground and background test datasets.
Produces trigger files for both jobs (foreground / background) under
<export_dir>/TESTING/. Activated only whenopts.inferenceisTrue.
- evaluate_model()[source]
Run the MLGWSC-1 evaluator on the trigger files produced by
test_model().Builds the raw-argument list expected by
sage.benchmark.mlgwsc1.evaluator.main()and invokes it to produce clustered triggers and efficiency statistics written to the TESTING sub-directory.