How to use the saliency.IntegratedGradients function in saliency

To help you get started, we’ve selected a few saliency examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google-research / google-research / interpretability_benchmark / saliency_data_gen / saliency_helper.py View on Github external
Args:
    graph: tensor flow graph.
    sess: the current session.
    y: the pre-softmax activation we want to assess attribution with respect to.
    image: float32 image tensor with size [1, None, None].
    saliency_method: string indicating saliency map type to generate.

  Returns:
    a saliency map and a smoothed saliency map.

  Raises:
    ValueError: if the saliency_method string does not match any included method
  """
  if saliency_method == 'integrated_gradients':
    integrated_placeholder = saliency.IntegratedGradients(graph, sess, y, image)
    return integrated_placeholder
  elif saliency_method == 'gradient':
    gradient_placeholder = saliency.GradientSaliency(graph, sess, y, image)
    return gradient_placeholder
  elif saliency_method == 'guided_backprop':
    gb_placeholder = saliency.GuidedBackprop(graph, sess, y, image)
    return gb_placeholder
  else:
    raise ValueError('No saliency method method matched. Verification of'
                     'input needed')