code: def get_activations(
      model,
      layer,
      examples,
      batch_size=64,
      dtype=None,
      ind_shape=None,
      center_only=False,
  ):
      """Collect center activtions of a layer over an n-dimensional array of images.
  
      Note: this is mostly intended for large synthetic families of images, where
        you can cheaply generate them in Python. For collecting activations over,
        say, ImageNet, there will be better workflows based on various dataset APIs
        in TensorFlow.
  
      Args:
        model: model for activations to be collected from.
        layer: layer (in model) for activtions to be collected from.
        examples: A (potentially n-dimensional) array of images. Can be any nested
          iterable object, including a generator, as long as the inner most objects
          are a numpy array with at least 3 dimensions (image X, Y, channels=3).
        batch_size: How many images should be processed at once?
        dtype: determines dtype of returned data (defaults to model activation
          dtype). Can be used to make function memory efficient.
        ind_shape: Shape that the index (non-image) dimensions of examples. Makes
          code much more memory efficient if examples is not a numpy array.
  
      Memory efficeincy:
        Have examples be a generator rather than an array of images; this allows
        them to be lazily generated and not all stored in memory at once. Also
        use ind_shape so that activations can be stored in an efficient data
        structure. If you still have memory problems, dtype="float16" can probably
        get you another 2x.
  
      Returns:
        A numpy array of shape [ind1, ind2, ..., layer_channels]
      """
  
      if ind_shape is None and isinstance(examples, np.ndarray):
          ind_shape = examples.shape[:-3]
  
      # Create a generator which recursive enumerates examples, stoppping at
      # the third last dimesnion (ie. an individual iamge) if numpy arrays.
      examples_enumerated = recursive_enumerate_nd(
          examples,
          stop_iter=lambda x: isinstance(x, np.ndarray)
          and len(x.shape) <= 3,
      )
  
      # Get responses
      return get_activations_iter(
          model,
          layer,
          examples_enumerated,
          batch_size=batch_size,
          dtype=dtype,
          ind_shape=ind_shape,
          center_only=center_only,
      )
  
imports: import itertools
  from collections import defaultdict
  import numpy
  import tensorflow
  from lucid.misc.iter_nd_utils import recursive_enumerate_nd, dict_to_ndarray, batch_iter
label_desc: Use image node_id 2 for calling a global function with example usage: get_activations(model, layer, examples, batch_size, dtype, ind_shape, center_only) and returns: get_activations_iter