class_docstr: This class implements a classifier with the TensorFlow v2 framework.
class_docstr_tok: ["This","class","implements","a","classifier","with","the","TensorFlow","v2","framework","."]
docstr: Return the output of the specified layer for input `x`. `layer` is specified by layer index (between 0 and
  `nb_layers - 1`) or by name. The number of layers can be determined by counting the results returned by
  calling `layer_names`.
  
  :param x: Input for computing the activations.
  :param layer: Layer for computing the activations.
  :param batch_size: Batch size.
  :param framework: Return activation as tensor.
  :return: The output of `layer`, where the first dimension is the batch size corresponding to `x`.
docstr_tok: ["Return","the","output","of","the","specified","layer","for","input","`","x","`",".","`","layer","`","is","specified","by","layer","index","(","between","0","and","`","nb_layers","-","1","`",")","or","by","name",".","The","number","of","layers","can","be","determined","by","counting","the","results","returned","by","calling","`","layer_names","`",".",":","param","x",":","Input","for","computing","the","activations",".",":","param","layer",":","Layer","for","computing","the","activations",".",":","param","batch_size",":","Batch","size",".",":","param","framework",":","Return","activation","as","tensor",".",":","return",":","The","output","of","`","layer","`",",","where","the","first","dimension","is","the","batch","size","corresponding","to","`","x","`","."]
code: def get_activations(  # type: ignore
      self,
      x: np.ndarray,
      layer: Union[int, str],
      batch_size: int = 128,
      framework: bool = False,
  ) -> Optional[np.ndarray]:
      """
      Return the output of the specified layer for input `x`. `layer` is specified by layer index (between 0 and
      `nb_layers - 1`) or by name. The number of layers can be determined by counting the results returned by
      calling `layer_names`.
  
      :param x: Input for computing the activations.
      :param layer: Layer for computing the activations.
      :param batch_size: Batch size.
      :param framework: Return activation as tensor.
      :return: The output of `layer`, where the first dimension is the batch size corresponding to `x`.
      """
      import tensorflow as tf
      from art.config import ART_NUMPY_DTYPE
  
      if not isinstance(
          self._model, tf.keras.models.Sequential
      ):  # pragma: no cover
          raise ValueError(
              "Method get_activations is not supported for non-Sequential models."
          )
  
      i_layer = None
      if self.layer_names is None:  # pragma: no cover
          raise ValueError("No layer names identified.")
  
      if isinstance(layer, six.string_types):
          if layer not in self.layer_names:  # pragma: no cover
              raise ValueError(
                  f"Layer name {layer} is not part of the graph."
              )
          for i_name, name in enumerate(self.layer_names):
              if name == layer:
                  i_layer = i_name
                  break
      elif isinstance(layer, int):
          if layer < -len(self.layer_names) or layer >= len(
              self.layer_names
          ):  # pragma: no cover
              raise ValueError(
                  f"Layer index {layer} is outside of range (-{len(self.layer_names)} "
                  f"to {len(self.layer_names) - 1})."
              )
          i_layer = layer
      else:  # pragma: no cover
          raise TypeError("Layer must be of type `str` or `int`.")
  
      activation_model = tf.keras.Model(
          self._model.layers[0].input,
          self._model.layers[i_layer].output,
      )
  
      # Apply preprocessing
      x_preprocessed, _ = self._apply_preprocessing(
          x=x, y=None, fit=False
      )
  
      if framework:
          if isinstance(x_preprocessed, tf.Tensor):
              return activation_model(x_preprocessed, training=False)
          return activation_model(
              tf.convert_to_tensor(x_preprocessed), training=False
          )
  
      # Determine shape of expected output and prepare array
      output_shape = self._model.layers[i_layer].output_shape
      activations = np.zeros(
          (x_preprocessed.shape[0],) + output_shape[1:],
          dtype=ART_NUMPY_DTYPE,
      )
  
      # Get activations with batching
      for batch_index in range(
          int(np.ceil(x_preprocessed.shape[0] / float(batch_size)))
      ):
          begin, end = (
              batch_index * batch_size,
              min(
                  (batch_index + 1) * batch_size,
                  x_preprocessed.shape[0],
              ),
          )
          activations[begin:end] = activation_model(
              [x_preprocessed[begin:end]], training=False
          ).numpy()
  
      return activations
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import os
  import random
  import shutil
  import time
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union, TYPE_CHECKING
  from tqdm.auto import tqdm
  import numpy
  import six
  from art import config
  from art.estimators.classification.classifier import ClassGradientsMixin, ClassifierMixin
  from art.estimators.tensorflow import TensorFlowEstimator, TensorFlowV2Estimator
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 18 for calling the TensorFlowV2Classifier obj's underlying member method code with example usage: obj.get_activations(x, layer, batch_size, framework) and returns: activations, activation_model, activation_model