anomalib.models.ganomaly¶
GANomaly Model.
Submodules¶
Package Contents¶
Classes¶
PL Lightning Module for the GANomaly Algorithm. |
|
PL Lightning Module for the GANomaly Algorithm. |
- class anomalib.models.ganomaly.Ganomaly(batch_size: int, input_size: Tuple[int, int], n_features: int, latent_vec_size: int, extra_layers: int = 0, add_final_conv_layer: bool = True, wadv: int = 1, wcon: int = 50, wenc: int = 1, lr: float = 0.0002, beta1: float = 0.5, beta2: float = 0.999)[source]¶
Bases:
anomalib.models.components.AnomalyModulePL Lightning Module for the GANomaly Algorithm.
- Parameters
batch_size (int) – Batch size.
input_size (Tuple[int,int]) – Input dimension.
n_features (int) – Number of features layers in the CNNs.
latent_vec_size (int) – Size of autoencoder latent vector.
extra_layers (int, optional) – Number of extra layers for encoder/decoder. Defaults to 0.
add_final_conv_layer (bool, optional) – Add convolution layer at the end. Defaults to True.
wadv (int, optional) – Weight for adversarial loss. Defaults to 1.
wcon (int, optional) – Image regeneration weight. Defaults to 50.
wenc (int, optional) – Latent vector encoder weight. Defaults to 1.
- _reset_min_max(self)¶
Resets min_max scores.
- configure_optimizers(self) List[torch.optim.Optimizer]¶
Configures optimizers for each decoder.
Note
This method is used for the existing CLI. When PL CLI is introduced, configure optimizers method will be
deprecated, and optimizers will be configured from either config.yaml file or from CLI.
- Returns
Adam optimizer for each decoder
- Return type
Optimizer
- training_step(self, batch, _, optimizer_idx)¶
Training step.
- Parameters
batch (Dict) – Input batch containing images.
optimizer_idx (int) – Optimizer which is being called for current training step.
- Returns
Loss
- Return type
Dict[str, Tensor]
- on_validation_start(self) None¶
Reset min and max values for current validation epoch.
- validation_step(self, batch, _) Dict[str, torch.Tensor]¶
Update min and max scores from the current step.
- Parameters
batch (Dict[str, Tensor]) – Predicted difference between z and z_hat.
- Returns
batch
- Return type
Dict[str, Tensor]
- validation_epoch_end(self, outputs)¶
Normalize outputs based on min/max values.
- on_test_start(self) None¶
Reset min max values before test batch starts.
- test_step(self, batch, _)¶
Update min and max scores from the current step.
- test_epoch_end(self, outputs)¶
Normalize outputs based on min/max values.
- _normalize(self, scores: torch.Tensor) torch.Tensor¶
Normalize the scores based on min/max of entire dataset.
- Parameters
scores (Tensor) – Un-normalized scores.
- Returns
Normalized scores.
- Return type
Tensor
- class anomalib.models.ganomaly.GanomalyLightning(hparams: Union[omegaconf.DictConfig, omegaconf.ListConfig])[source]¶
Bases:
GanomalyPL Lightning Module for the GANomaly Algorithm.
- Parameters
hparams (Union[DictConfig, ListConfig]) – Model params
- configure_callbacks(self)¶
Configure model-specific callbacks.
Note
This method is used for the existing CLI. When PL CLI is introduced, configure callback method will be
deprecated, and callbacks will be configured from either config.yaml file or from CLI.