class_docstr: A CoreSaliency class that computes saliency masks using the XRAI method.
class_docstr_tok: ["A","CoreSaliency","class","that","computes","saliency","masks","using","the","XRAI","method","."]
docstr: Applies XRAI method on an input image and returns the result saliency heatmap.
  
  
  Args:
      x_value: Input ndarray.
      call_model_function: A function that interfaces with a model to return
        specific data in a dictionary when given an input and other arguments.
        Expected function signature:
        - call_model_function(x_value_batch,
                              call_model_args=None,
                              expected_keys=None):
          x_value_batch - Input for the model, given as a batch (i.e.
            dimension 0 is the batch dimension, dimensions 1 through n
            represent a single input).
          call_model_args - Other arguments used to call and run the model.
          expected_keys - List of keys that are expected in the output. For
            this method (XRAI), the expected keys are
            INPUT_OUTPUT_GRADIENTS - Gradients of the output being
              explained (the logit/softmax value) with respect to the input.
              Shape should be the same shape as x_value_batch.
      call_model_args: The arguments that will be passed to the call model
         function, for every call of the model.
      baselines: a list of baselines to use for calculating
        Integrated Gradients attribution. Every baseline in
        the list should have the same dimensions as the
        input. If the value is not set then the algorithm
        will make the best effort to select default
        baselines. Defaults to None.
      segments: the list of precalculated image segments that should
        be passed to XRAI. Each element of the list is an
        [N,M] boolean array, where NxM are the image
        dimensions. Each elemeent on the list contains exactly the
        mask that corresponds to one segment. If the value is None,
        Felzenszwalb's segmentation algorithm will be applied.
        Defaults to None.
      base_attribution: an optional pre-calculated base attribution that XRAI
        should use. The shape of the parameter should match
        the shape of `x_value`. If the value is None, the
        method calculates Integrated Gradients attribution and
        uses it.
      batch_size: Maximum number of x inputs (steps along the integration
        path) that are passed to call_model_function as a batch.
      extra_parameters: an XRAIParameters object that specifies
        additional parameters for the XRAI saliency
        method. If it is None, an XRAIParameters object
        will be created with default parameters. See
        XRAIParameters for more details.
  
  Raises:
      ValueError: If algorithm type is unknown (not full or fast).
                  If the shape of `base_attribution` dosn't match the shape of
                    `x_value`.
                  If the shape of INPUT_OUTPUT_GRADIENTS doesn't match the
                    shape of x_value_batch.
  
  Returns:
      np.ndarray: A numpy array that contains the saliency heatmap.
  
  
  TODO(tolgab) Add output_selector functionality from XRAI API doc
docstr_tok: ["Applies","XRAI","method","on","an","input","image","and","returns","the","result","saliency","heatmap",".","Args",":","x_value",":","Input","ndarray",".","call_model_function",":","A","function","that","interfaces","with","a","model","to","return","specific","data","in","a","dictionary","when","given","an","input","and","other","arguments",".","Expected","function","signature",":","-","call_model_function","(","x_value_batch",",","call_model_args=None",",","expected_keys=None",")",":","x_value_batch","-","Input","for","the","model",",","given","as","a","batch","(","i.e",".","dimension","0","is","the","batch","dimension",",","dimensions","1","through","n","represent","a","single","input",")",".","call_model_args","-","Other","arguments","used","to","call","and","run","the","model",".","expected_keys","-","List","of","keys","that","are","expected","in","the","output",".","For","this","method","(","XRAI",")",",","the","expected","keys","are","INPUT_OUTPUT_GRADIENTS","-","Gradients","of","the","output","being","explained","(","the","logit\/softmax","value",")","with","respect","to","the","input",".","Shape","should","be","the","same","shape","as","x_value_batch",".","call_model_args",":","The","arguments","that","will","be","passed","to","the","call","model","function",",","for","every","call","of","the","model",".","baselines",":","a","list","of","baselines","to","use","for","calculating","Integrated","Gradients","attribution",".","Every","baseline","in","the","list","should","have","the","same","dimensions","as","the","input",".","If","the","value","is","not","set","then","the","algorithm","will","make","the","best","effort","to","select","default","baselines",".","Defaults","to","None",".","segments",":","the","list","of","precalculated","image","segments","that","should","be","passed","to","XRAI",".","Each","element","of","the","list","is","an","[","N",",","M","]","boolean","array",",","where","NxM","are","the","image","dimensions",".","Each","elemeent","on","the","list","contains","exactly","the","mask","that","corresponds","to","one","segment",".","If","the","value","is","None",",","Felzenszwalb","'s","segmentation","algorithm","will","be","applied",".","Defaults","to","None",".","base_attribution",":","an","optional","pre-calculated","base","attribution","that","XRAI","should","use",".","The","shape","of","the","parameter","should","match","the","shape","of","`","x_value","`",".","If","the","value","is","None",",","the","method","calculates","Integrated","Gradients","attribution","and","uses","it",".","batch_size",":","Maximum","number","of","x","inputs","(","steps","along","the","integration","path",")","that","are","passed","to","call_model_function","as","a","batch",".","extra_parameters",":","an","XRAIParameters","object","that","specifies","additional","parameters","for","the","XRAI","saliency","method",".","If","it","is","None",",","an","XRAIParameters","object","will","be","created","with","default","parameters",".","See","XRAIParameters","for","more","details",".","Raises",":","ValueError",":","If","algorithm","type","is","unknown","(","not","full","or","fast",")",".","If","the","shape","of","`","base_attribution","`","dos","n't","match","the","shape","of","`","x_value","`",".","If","the","shape","of","INPUT_OUTPUT_GRADIENTS","does","n't","match","the","shape","of","x_value_batch",".","Returns",":","np.ndarray",":","A","numpy","array","that","contains","the","saliency","heatmap",".","TODO","(","tolgab",")","Add","output_selector","functionality","from","XRAI","API","doc"]
code: def GetMask(
      self,
      x_value,
      call_model_function,
      call_model_args=None,
      baselines=None,
      segments=None,
      base_attribution=None,
      batch_size=1,
      extra_parameters=None,
  ):
      """Applies XRAI method on an input image and returns the result saliency heatmap.
  
  
      Args:
          x_value: Input ndarray.
          call_model_function: A function that interfaces with a model to return
            specific data in a dictionary when given an input and other arguments.
            Expected function signature:
            - call_model_function(x_value_batch,
                                  call_model_args=None,
                                  expected_keys=None):
              x_value_batch - Input for the model, given as a batch (i.e.
                dimension 0 is the batch dimension, dimensions 1 through n
                represent a single input).
              call_model_args - Other arguments used to call and run the model.
              expected_keys - List of keys that are expected in the output. For
                this method (XRAI), the expected keys are
                INPUT_OUTPUT_GRADIENTS - Gradients of the output being
                  explained (the logit/softmax value) with respect to the input.
                  Shape should be the same shape as x_value_batch.
          call_model_args: The arguments that will be passed to the call model
             function, for every call of the model.
          baselines: a list of baselines to use for calculating
            Integrated Gradients attribution. Every baseline in
            the list should have the same dimensions as the
            input. If the value is not set then the algorithm
            will make the best effort to select default
            baselines. Defaults to None.
          segments: the list of precalculated image segments that should
            be passed to XRAI. Each element of the list is an
            [N,M] boolean array, where NxM are the image
            dimensions. Each elemeent on the list contains exactly the
            mask that corresponds to one segment. If the value is None,
            Felzenszwalb's segmentation algorithm will be applied.
            Defaults to None.
          base_attribution: an optional pre-calculated base attribution that XRAI
            should use. The shape of the parameter should match
            the shape of `x_value`. If the value is None, the
            method calculates Integrated Gradients attribution and
            uses it.
          batch_size: Maximum number of x inputs (steps along the integration
            path) that are passed to call_model_function as a batch.
          extra_parameters: an XRAIParameters object that specifies
            additional parameters for the XRAI saliency
            method. If it is None, an XRAIParameters object
            will be created with default parameters. See
            XRAIParameters for more details.
  
      Raises:
          ValueError: If algorithm type is unknown (not full or fast).
                      If the shape of `base_attribution` dosn't match the shape of
                        `x_value`.
                      If the shape of INPUT_OUTPUT_GRADIENTS doesn't match the
                        shape of x_value_batch.
  
      Returns:
          np.ndarray: A numpy array that contains the saliency heatmap.
  
  
      TODO(tolgab) Add output_selector functionality from XRAI API doc
      """
      results = self.GetMaskWithDetails(
          x_value,
          call_model_function,
          call_model_args=call_model_args,
          baselines=baselines,
          segments=segments,
          base_attribution=base_attribution,
          batch_size=batch_size,
          extra_parameters=extra_parameters,
      )
      return results.attribution_mask
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import logging
  from .base import CoreSaliency
  from .integrated_gradients import IntegratedGradients
  import numpy
  from skimage import segmentation
  from skimage.morphology import dilation
  from skimage.morphology import disk
  from skimage.transform import resize
label_desc: Use image node_id 5 for calling the XRAI obj's underlying member method code with example usage: obj.GetMask(x_value, call_model_function, call_model_args, baselines, segments, base_attribution, batch_size, extra_parameters) and returns: results