class_docstr: Wrapper class for importing Keras regression models.
class_docstr_tok: ["Wrapper","class","for","importing","Keras","regression","models","."]
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: Size of batches.
  :param framework: If true, return the intermediate tensor representation of the activation.
  :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",":","Size","of","batches",".",":","param","framework",":","If","true",",","return","the","intermediate","tensor","representation","of","the","activation",".",":","return",":","The","output","of","`","layer","`",",","where","the","first","dimension","is","the","batch","size","corresponding","to","`","x","`","."]
code: def get_activations(
      self,
      x: np.ndarray,
      layer: Union[int, str],
      batch_size: int = 128,
      framework: bool = False,
  ) -> 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: Size of batches.
      :param framework: If true, return the intermediate tensor representation of the activation.
      :return: The output of `layer`, where the first dimension is the batch size corresponding to `x`.
      """
      # pylint: disable=E0401
      if self.is_tensorflow:
          import tensorflow.keras.backend as k  # pylint: disable=E0611
      else:
          import keras.backend as k
      from art.config import ART_NUMPY_DTYPE
  
      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."
              )
          layer_name = layer
      elif isinstance(layer, int):
          if layer < 0 or layer >= len(
              self._layer_names
          ):  # pragma: no cover
              raise ValueError(
                  f"Layer index {layer} is outside of range (0 to {len(self._layer_names) - 1} included)."
              )
          layer_name = self._layer_names[layer]
      else:  # pragma: no cover
          raise TypeError("Layer must be of type `str` or `int`.")
  
      if x.shape == self.input_shape:
          x_expanded = np.expand_dims(x, 0)
      else:
          x_expanded = x
  
      # Apply preprocessing
      x_preprocessed, _ = self._apply_preprocessing(
          x=x_expanded, y=None, fit=False
      )
  
      if not hasattr(self, "_activations_func"):
          self._activations_func: Dict[str, Callable] = {}
  
      keras_layer = self._model.get_layer(layer_name)
      if layer_name not in self._activations_func:
          num_inbound_nodes = len(
              getattr(keras_layer, "_inbound_nodes", [])
          )
          if num_inbound_nodes > 1:
              layer_output = keras_layer.get_output_at(0)
          else:
              layer_output = keras_layer.output
          self._activations_func[layer_name] = k.function(
              [self._input, k.learning_phase()], [layer_output]
          )
  
      # Determine shape of expected output and prepare array
      output_shape = self._activations_func[layer_name](
          [x_preprocessed[0][None, ...], int(False)]
      )[0].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] = self._activations_func[layer_name](
              [x_preprocessed[begin:end], 0]
          )[0]
  
      if framework:
          placeholder = k.placeholder(shape=x.shape)
          return placeholder, keras_layer(placeholder)  # type: ignore
  
      return activations
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import os
  import time
  from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  import six
  from art import config
  from art.estimators.keras import KerasEstimator
  from art.estimators.regression.regressor import RegressorMixin
label_desc: Use image node_id 12 for calling the KerasRegressor obj's underlying member method code with example usage: obj.get_activations(x, layer, batch_size, framework) and returns: activations, placeholder,  keras_layer