class_docstr: PL Lightning Module for the GANomaly Algorithm.
  
  Args:
      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.
class_docstr_tok: ["PL","Lightning","Module","for","the","GANomaly","Algorithm",".","Args",":","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","."]
docstr: Training step.
  
  Args:
      batch (dict[str, str | Tensor]): Input batch containing images.
      batch_idx (int): Batch index.
      optimizer_idx (int): Optimizer which is being called for current training step.
  
  Returns:
      STEP_OUTPUT: Loss
docstr_tok: ["Training","step",".","Args",":","batch","(","dict","[","str",",","str","|","Tensor","]",")",":","Input","batch","containing","images",".","batch_idx","(","int",")",":","Batch","index",".","optimizer_idx","(","int",")",":","Optimizer","which","is","being","called","for","current","training","step",".","Returns",":","STEP_OUTPUT",":","Loss"]
code: def training_step(
      self,
      batch: dict[str, str | Tensor],
      batch_idx: int,
      optimizer_idx: int,
  ) -> STEP_OUTPUT:  # pylint: disable=arguments-differ
      """Training step.
  
      Args:
          batch (dict[str, str | Tensor]): Input batch containing images.
          batch_idx (int): Batch index.
          optimizer_idx (int): Optimizer which is being called for current training step.
  
      Returns:
          STEP_OUTPUT: Loss
      """
      del batch_idx  # `batch_idx` variables is not used.
  
      # forward pass
      padded, fake, latent_i, latent_o = self.model(batch["image"])
      pred_real, _ = self.model.discriminator(padded)
  
      if optimizer_idx == 0:  # Discriminator
          pred_fake, _ = self.model.discriminator(fake.detach())
          loss = self.discriminator_loss(pred_real, pred_fake)
      else:  # Generator
          pred_fake, _ = self.model.discriminator(fake)
          loss = self.generator_loss(
              latent_i, latent_o, padded, fake, pred_real, pred_fake
          )
  
      self.log(
          "train_loss",
          loss.item(),
          on_epoch=True,
          prog_bar=True,
          logger=True,
      )
      return {"loss": loss}
  
imports: from __future__ import annotations
  import logging
  import torch
  from omegaconf import DictConfig, ListConfig
  from pytorch_lightning.callbacks import Callback, EarlyStopping
  from pytorch_lightning.utilities.types import EPOCH_OUTPUT, STEP_OUTPUT
  from torch import Tensor, optim
  from anomalib.models.components import AnomalyModule
  from anomalib.models.ganomaly.loss import DiscriminatorLoss, GeneratorLoss
  from .torch_model import GanomalyModel
label_desc: Use image node_id 4 for calling the Ganomaly obj's underlying member method code with example usage: obj.training_step(batch, batch_idx, optimizer_idx) and returns: dict