Skip to content

RISE

View colab tutorial | View source | 📰 Paper

The RISE method consist of probing the model with randomly masked versions of the input image and obtaining the corresponding outputs to deduce critical areas.

Quote

[...] we estimate the importance of pixels by dimming them in random combinations, reducing their intensities down to zero. We model this by multiplying an image with a [0,1] valued mask.

-- RISE: Randomized Input Sampling for Explanation of Black-box Models (2018)1

with \(f(x)\) the prediction of a classifier, for an input \(x\) and \(m \sim \mathcal{M}\) a mask with value in \([0,1]\) created from a low dimension (\(m\) is in \({0, 1}^{w \times h}\) with \(w \ll W\) and \(h \ll H\) then upsampled, see the paper for more details).

The RISE importance estimator is defined as:

\[ \phi_i = \mathbb{E}( f(x \odot m) | m_i = 1) \approx \frac{1}{\mathbb{E}(\mathcal{M}) N} \sum_{i=1}^N f(x \odot m_i) m_i \]

The most important parameters here are (1) the grid_size that control \(w\) and \(h\) and (2) nb_samples that control \(N\). The pourcentage of visible pixels \(\mathbb{E}(\mathcal{M})\) is controlled using the preservation_probability parameter.

Example

from xplique.attributions import Rise

# load images, labels and model
# ...

method = Rise(model, nb_samples=4000, grid_size=7, preservation_probability=0.5)
explanations = method.explain(images, labels)

Notebooks

Rise

Used to compute the RISE method, by probing the model with randomly masked versions of the input image and obtaining the corresponding outputs to deduce critical areas.

__init__(self,
         model: Callable,
         batch_size: Optional[int] = 32,
         operator: Union[xplique.commons.operators.Tasks, str,
         Callable[[keras.src.engine.training.Model, tf.Tensor, tf.Tensor], float], None] = None,
         nb_samples: int = 4000,
         grid_size: Union[int, Tuple[int]] = 7,
         preservation_probability: float = 0.5)

Parameters

  • model : Callable

    • The model from which we want to obtain explanations

  • batch_size : Optional[int] = 32

    • Number of pertubed samples to explain at once.

      Default to 32.

  • operator : Union[xplique.commons.operators.Tasks, str, Callable[[keras.src.engine.training.Model, tf.Tensor, tf.Tensor], float], None] = None

    • Function g to explain, g take 3 parameters (f, x, y) and should return a scalar, with f the model, x the inputs and y the targets. If None, use the standard operator g(f, x, y) = f(x)[y].

  • nb_samples : int = 4000

    • Number of masks generated for Monte Carlo sampling.

  • grid_size : Union[int, Tuple[int]] = 7

    • Size of the grid used to generate the scaled-down masks. Masks are then rescale to and cropped to input_size. Can be a tuple for different cutting depending on the dimension.

  • preservation_probability : float = 0.5

    • Probability of preservation for each pixel (or the percentage of non-masked pixels in each masks), also the expectation value of the mask.

explain(self,
        inputs: Union[tf.Dataset, tf.Tensor, numpy.ndarray],
        targets: Union[tf.Tensor, numpy.ndarray, None] = None) -> tf.Tensor

Compute RISE for a batch of samples.

Parameters

  • inputs : Union[tf.Dataset, tf.Tensor, numpy.ndarray]

    • Dataset, Tensor or Array. Input samples to be explained.

      If Dataset, targets should not be provided (included in Dataset).

      Expected shape among (N, W), (N, T, W), (N, H, W, C).

      More information in the documentation.

  • targets : Union[tf.Tensor, numpy.ndarray, None] = None

    • Tensor or Array. One-hot encoding of the model's output from which an explanation is desired. One encoding per input and only one output at a time. Therefore, the expected shape is (N, output_size).

      More information in the documentation.

Return

  • explanations : tf.Tensor

    • RISE maps, same shape as the inputs, except for the channels.