code: def get_gradients_of_activations(
      model,
      x,
      y,
      layer_names=None,
      output_format="simple",
      nested=False,
  ):
      """
      Get gradients of the outputs of the activation functions, regarding the loss.
      Intuitively, it shows how your activation maps change over a tiny modification of the loss.
      :param model: keras compiled model or one of ['vgg16', 'vgg19', 'inception_v3', 'inception_resnet_v2',
      'mobilenet_v2', 'mobilenetv2'].
      :param x: Model input (Numpy array). In the case of multi-inputs, x should be of type List.
      :param y: Model target (Numpy array). In the case of multi-inputs, y should be of type List.
      :param layer_names: (optional) Single name of a layer or list of layer names for which activations should be
      returned. It is useful in very big networks when it is computationally expensive to evaluate all the layers/nodes.
      :param output_format: Change the output dictionary key of the function.
      - 'simple': output key will match the names of the Keras layers. For example Dense(1, name='d1') will
      return {'d1': ...}.
      - 'full': output key will match the full name of the output layer name. In the example above, it will
      return {'d1/BiasAdd:0': ...}.
      - 'numbered': output key will be an index range, based on the order of definition of each layer within the model.
      :param nested: (optional) If set, will move recursively through the model definition to retrieve nested layers.
                  Recursion ends at leaf layers of the model tree or at layers with their name specified in layer_names.
  
                  E.g., a model with the following structure
  
                  -layer1
                      -conv1
                      ...
                      -fc1
                  -layer2
                      -fc2
  
                  ... yields a dictionary with keys 'layer1/conv1', ..., 'layer1/fc1', 'layer2/fc2'.
                  If layer_names = ['layer2/fc2'] is specified, the dictionary will only hold one key 'layer2/fc2'.
  
                  The layer names are generated by joining all layers from top level to leaf level with the separator '/'.
      :return: Dict {layer_names (specified by output_format) -> activation of the layer output/node (Numpy array)}.
      """
      nodes = OrderedDict()
      _get_nodes(
          model,
          nodes,
          output_format,
          nested=nested,
          layer_names=layer_names,
      )
      return _get_gradients(model, x, y, nodes)
  
imports: import json
  import os
  from collections import OrderedDict
  import numpy
  import tensorflow
  import tensorflow.keras.backend
  from tensorflow.keras import Sequential
  from tensorflow.keras.models import Model
label_desc: Use image node_id 6 for calling a global function with example usage: get_gradients_of_activations(model, x, y, layer_names, output_format, nested) and returns: _get_gradients