class_docstr: Class for importing MXNet Gluon 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:  # pragma: no cover
      """
      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`.
      """
      import mxnet as mx
  
      if isinstance(layer, six.string_types):
          if layer not in self._layer_names:
              raise ValueError(
                  f"Layer name {layer} is not part of the model."
              )
          layer_ind = self._layer_names.index(layer)
      elif isinstance(layer, int):
          if layer < 0 or layer >= len(self._layer_names):
              raise ValueError(
                  f"Layer index {layer} is outside of range (0 to {len(self._layer_names) - 1} included)."
              )
          layer_ind = layer
      else:
          raise TypeError("Layer must be of type `str` or `int`.")
  
      # Apply preprocessing and defences
      if x.shape == self.input_shape:
          x_expanded = np.expand_dims(x, 0)
      else:
          x_expanded = x
  
      x_preprocessed, _ = self._apply_preprocessing(
          x=x_expanded, y=None, fit=False
      )
  
      if framework:
          return self._model[layer_ind]
  
      # Compute activations with batching
      activations = []
      nb_batches = int(np.ceil(len(x_preprocessed) / float(batch_size)))
      for batch_index in range(nb_batches):
          # Batch indexes
          begin, end = (
              batch_index * batch_size,
              min(
                  (batch_index + 1) * batch_size,
                  x_preprocessed.shape[0],
              ),
          )
  
          # Predict
          x_batch = mx.nd.array(
              x_preprocessed[begin:end].astype(config.ART_NUMPY_DTYPE),
              ctx=self.ctx,
          )
          x_batch.attach_grad()
          with mx.autograd.record(train_mode=False):
              preds = self._model[layer_ind](x_batch)
  
          activations.append(preds.asnumpy())
  
      activations_array = np.vstack(activations)
      return activations_array
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import os
  from typing import List, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  import six
  from art import config
  from art.estimators.mxnet import MXEstimator
  from art.estimators.classification.classifier import ClassGradientsMixin, ClassifierMixin
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 13 for calling the MXClassifier obj's underlying member method code with example usage: obj.get_activations(x, layer, batch_size, framework) and returns: activations_array, self