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: Takes a dictionary `activations_dict' of activation values of different layers for an input batch and Returns
  a tensor where all activation values are normalised layer-wise and flattened to a vector for
  each input of the batch.
  
  :param activations_dict: dict containing the activations at different layers.
  :param list_layer_names: Layers' names for fetching the activations
  :return: The activations after normalisation and flattening, where the first dimension is the batch size.
docstr_tok: ["Takes","a","dictionary","`","activations_dict","'","of","activation","values","of","different","layers","for","an","input","batch","and","Returns","a","tensor","where","all","activation","values","are","normalised","layer-wise","and","flattened","to","a","vector","for","each","input","of","the","batch",".",":","param","activations_dict",":","dict","containing","the","activations","at","different","layers",".",":","param","list_layer_names",":","Layers","'","names","for","fetching","the","activations",":","return",":","The","activations","after","normalisation","and","flattening",",","where","the","first","dimension","is","the","batch","size","."]
code: def normalize_concatenate_activations(
      activations_dict: Dict[str, "torch.Tensor"],
      list_layer_names: List[str],
  ) -> "torch.Tensor":
      """
      Takes a dictionary `activations_dict' of activation values of different layers for an input batch and Returns
      a tensor where all activation values are normalised layer-wise and flattened to a vector for
      each input of the batch.
  
      :param activations_dict: dict containing the activations at different layers.
      :param list_layer_names: Layers' names for fetching the activations
      :return: The activations after normalisation and flattening, where the first dimension is the batch size.
      """
  
      import torch
  
      activation_vectors = []
      for name in list_layer_names:
          temp_activation = activations_dict[name]
          size_temp_activation = list(temp_activation.size())
          norm_factor_layer = (
              size_temp_activation[2] * size_temp_activation[3]
          )
          norm_temp_activation = (
              torch.sqrt(
                  torch.sum(temp_activation**2, dim=1, keepdim=True)
              )
              + EPS
          )
          temp_activation_n_channel = (
              temp_activation / norm_temp_activation
          )
          temp_activation_n_layer_channel = (
              temp_activation_n_channel / np.sqrt(norm_factor_layer)
          )
          temp_activation_n_layer_channel_flat = (
              temp_activation_n_layer_channel.view(
                  size_temp_activation[0], -1
              )
          )
          activation_vectors.append(
              temp_activation_n_layer_channel_flat
          )
  
      activation_vectors_flattened = torch.cat(
          activation_vectors, dim=1
      )
      return activation_vectors_flattened
  
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 9 for calling the AdversarialTrainerOAATPyTorch obj's underlying member method code with example usage: obj.normalize_concatenate_activations(activations_dict, list_layer_names) and returns: activation_vectors_flattened