backbones.models package
Submodules
backbones.models.pyodModel module
- class backbones.models.pyodModel.PyodModel(config)
Bases:
objectTemplate class for outlier detection models
- Parameters:
config (dict) – configuration file
- forward(dataset, mode, step_samples=1)
Forward pass to get the model outputs
- Parameters:
dataset (numpy.ndarray) – dataset variables
mode (str) – type of step: train, val or test
step_samples (int, optional) – sampling interval to subset the dataset, defaults to 1
- Returns:
results of the model
- Return type:
dict
- get_model()
Calls for the handler of the model
- Returns:
Pyod model
- Return type:
pyod.models
backbones.models.pytorchModel module
- class backbones.models.pytorchModel.PytorchModel(config, num_data_train=None)
Bases:
LightningModuleTemplate class for deep learning architectures
- Parameters:
config (dict) – configuration file
- adapt_variables_for_metric(metric_name, outputs, labels, masks=None)
Adapts the sizes of the outputs and masks to the task
- Parameters:
metric_name (str) – name of the metric to fetch for
outputs (torch.Tensor) – outputs of the model
labels (torch.Tensor) – target variables
masks (torch.Tensor, optional) – mask indicating where we have valid values in the input variables and where to compute the metrics, defaults to None
- Returns:
computed metric
- Return type:
torch.Tensor
- configure_optimizers()
Configures the optimizer for the training stage
- Returns:
optimitzer object with the definition of the training hyperparameters
- Return type:
torch.optim.Optimizer
- define_model()
Builds the model from an external file (user defined) or from the libraries of deep learning. Creates the auxiliary parameters according to the user specifications and modifies the architecture to fit the required task
- epoch_metrics(mode)
Computes and logs average metrics. Resets each epoch.
- Parameters:
mode (str) – type of step: train, val or test
- forward(x, train=False)
Forward pass to get the model outputs
- Parameters:
x (torch.Tensor) – input variables
- Returns:
predictions of the model
- Return type:
torch.Tensor
- log_metric(metric, mode, metric_name, prog_bar=True)
Logs the metric
- Parameters:
metric (torch.Tensor) – computed metric
mode (str) – type of step: train, val or test
metric_name (str) – name of the metric
prog_bar (bool, optional) – bolean to activate the progress bar, defaults to True
- on_test_epoch_end()
Calls the computation of the epoch metrics
- on_train_epoch_end()
Calls the computation of the metrics for each epoch
- on_validation_epoch_end()
Calls the computation of the epoch metrics and its logging
Adapts the variables for the iteration, calls the forward step, computes the loss and metrics and logs their value to the logger.
- Parameters:
batch (dict) – batch of variables given by the Dataloader in the current iteration
mode (str) – type of step: train, val or test
- Returns:
results of the iteration and reference variables. This includes the loss and the ouput and labels for the iteration.
- Return type:
dict
- step_metrics(outputs, labels, mode, masks=None)
Adapts, computes and logs evaluation metrics
- Parameters:
outputs (torch.Tensor) – outputs of the model
labels (torch.Tensor) – target variables
mode (str) – type of step: train, val or test
masks (torch.Tensor, optional) – mask indicating where we have valid values in the input variables and where to compute the metrics, defaults to None
- test_step(batch, batch_idx)
Testing step
- Parameters:
batch (dict) – batch of variables given by the Pytorch Dataloader
batch_idx (int) – index of the batch
- Returns:
results of the step
- Return type:
dict
- training_step(batch, batch_idx)
Training step
- Parameters:
batch (dict) – batch of variables given by the Pytorch Dataloader
batch_idx (int) – index of the batch
- Returns:
results of the step
- Return type:
dict
- validation_step(batch, batch_idx)
Validation step
- Parameters:
batch (dict) – batch of variables given by the Pytorch Dataloader
batch_idx (int) – index of the batch
- Returns:
results of the step
- Return type:
dict