Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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`.
Returns:
XRAIOutput: an object that contains the output of the XRAI algorithm.
TODO(tolgab) Add output_selector functionality from XRAI API doc
"""
if extra_parameters is None:
extra_parameters = XRAIParameters()
# Check the shape of base_attribution.
if base_attribution is not None:
if not isinstance(base_attribution, np.ndarray):
base_attribution = np.array(base_attribution)
if base_attribution.shape != x_value.shape:
raise ValueError(
'The base attribution shape should be the same as the shape of '
'`x_value`. Expected {}, got {}'.format(
x_value.shape, base_attribution.shape))
# Calculate IG attribution if not provided by the caller.
if base_attribution is None:
_logger.info("Computing IG...")
x_baselines = self._make_baselines(x_value, baselines)