class_docstr: Class performing adversarial training following Oracle Aligned Adversarial Training (OAAT) protocol.
  
  | Paper link: https://link.springer.com/chapter/10.1007/978-3-031-20065-6_18
class_docstr_tok: ["Class","performing","adversarial","training","following","Oracle","Aligned","Adversarial","Training","(","OAAT",")","protocol",".","|","Paper","link",":","https",":","\/\/link.springer.com\/chapter\/10.1007\/978-3-031-20065-6_18"]
docstr: Calculate wight perturbation for a batch of data.
  See class documentation for more information on the exact procedure.
  
  :param x_batch: batch of x.
  :param x_batch_pert: batch of x with perturbations.
  :param y_batch: batch of y.
  :return: dict containing names of classifier model's layers as keys and parameters as values
docstr_tok: ["Calculate","wight","perturbation","for","a","batch","of","data",".","See","class","documentation","for","more","information","on","the","exact","procedure",".",":","param","x_batch",":","batch","of","x.",":","param","x_batch_pert",":","batch","of","x","with","perturbations",".",":","param","y_batch",":","batch","of","y.",":","return",":","dict","containing","names","of","classifier","model","'s","layers","as","keys","and","parameters","as","values"]
code: def _weight_perturbation(
      self,
      x_batch: "torch.Tensor",
      x_batch_pert: "torch.Tensor",
      y_batch: "torch.Tensor",
  ) -> Dict[str, "torch.Tensor"]:
      """
      Calculate wight perturbation for a batch of data.
      See class documentation for more information on the exact procedure.
  
      :param x_batch: batch of x.
      :param x_batch_pert: batch of x with perturbations.
      :param y_batch: batch of y.
      :return: dict containing names of classifier model's layers as keys and parameters as values
      """
      import torch
      from torch import nn
      import torch.nn.functional as F
  
      w_perturb = OrderedDict()
      params_dict, _ = self._calculate_model_params(self._classifier)
      list_keys = list(params_dict.keys())
      self._proxy_classifier.model.load_state_dict(
          self._classifier.model.state_dict()
      )
      self._proxy_classifier.model.train(mode=True)
  
      n = x_batch.shape[0]
      # Perform prediction
      model_outputs = self._proxy_classifier.model(x_batch)
      model_outputs_pert = self._proxy_classifier.model(x_batch_pert)
      loss_clean = self._proxy_classifier.loss(model_outputs, y_batch)
      loss_kl = (1.0 / n) * nn.KLDivLoss(reduction="sum")(
          F.log_softmax(model_outputs_pert, dim=1),
          torch.clamp(F.softmax(model_outputs, dim=1), min=EPS),
      )
      loss = -1.0 * (loss_clean + self._train_params["beta"] * loss_kl)
  
      self._proxy_classifier.optimizer.zero_grad()
      loss.backward()
      self._proxy_classifier.optimizer.step()
  
      params_dict_proxy, _ = self._calculate_model_params(
          self._proxy_classifier
      )
  
      for name in list_keys:
          perturbation = (
              params_dict_proxy[name]["param"]
              - params_dict[name]["param"]
          )
          perturbation = torch.reshape(
              perturbation, list(params_dict[name]["size"])
          )
          scale = params_dict[name]["norm"] / (
              perturbation.norm() + EPS
          )
          w_perturb[name] = scale * perturbation
  
      return w_perturb
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  from collections import OrderedDict
  import logging
  import os
  import time
  from typing import Optional, Tuple, TYPE_CHECKING, List, Dict, Union
  import six
  import numpy
  from tqdm.auto import trange
  from art import config
  from art.defences.trainer.adversarial_trainer_oaat import AdversarialTrainerOAAT
  from art.estimators.classification.pytorch import PyTorchClassifier
  from art.data_generators import DataGenerator
  from art.attacks.attack import EvasionAttack
  from art.utils import check_and_transform_label_format, random_sphere
  from art.config import ART_NUMPY_DTYPE
label_desc: Use image node_id 5 for calling the AdversarialTrainerOAATPyTorch obj's underlying member method code with example usage: obj._weight_perturbation(x_batch, x_batch_pert, y_batch) and returns: w_perturb