MCRISEStack

class xaitk_saliency.impls.gen_image_classifier_blackbox_sal.mc_rise.MCRISEStack(n: int, s: int, p1: float, fill_colors: Sequence[Sequence[int]], seed: int | None, threads: int = 0)

Encapsulation of the perturbation-occlusion method using specifically the MC-RISE implementations of the component algorithms.

This more specifically encapsulates the MC-RISE method as presented in their paper and code. See references in the MCRISEGrid and MCRISEScoring documentation.

This implementation shares the p1 probability and ‘k’ number colors with the internal MCRISEScoring instance use, to make use of the debiasing described in the MC-RISE paper. Debiasing is always on.

Methods

from_config

Instantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.

generate

Generates per-class visual saliency heatmaps for some classifier black box over some image of interest.

get_config

Return a JSON-compliant dictionary that could be passed to this class's from_config method to produce an instance with identical configuration.

get_default_config

Generate and return a default configuration dictionary for this class.

get_impls

Discover and return a set of classes that implement the calling class.

is_usable

Check whether this class is available for use.

__init__(n: int, s: int, p1: float, fill_colors: Sequence[Sequence[int]], seed: int | None, threads: int = 0) None
Parameters:
  • n – int Number of random masks used in the algorithm. E.g. 1000.

  • s – int Spatial resolution of the small masking grid. E.g. 8. Assumes square grid.

  • p1 – float Probability of the grid cell being set to 1 (otherwise 0). This should be a float value in the [0, 1] range. E.g. 0.5.

  • fill_colors – Sequence[Sequence[int]] The fill colors to be used when generating masks.

  • seed – Optional[int] A seed to pass into the constructed random number generator to allow for reproducibility

  • threads – int The number of threads to utilize when generating masks. If this is <=0 or None, no threading is used and processing is performed in-line serially.

Raises:

ValueError If no fill colors are provided.

Raises:

ValueError If provided fill colors have differing numbers of channels.

get_config() dict[str, Any]

Return a JSON-compliant dictionary that could be passed to this class’s from_config method to produce an instance with identical configuration.

In the most cases, this involves naming the keys of the dictionary based on the initialization argument names as if it were to be passed to the constructor via dictionary expansion. In some cases, where it doesn’t make sense to store some object constructor parameters are expected to be supplied at as configuration values (i.e. must be supplied at runtime), this method’s returned dictionary may leave those parameters out. In such cases, the object’s from_config class-method would also take additional positional arguments to fill in for the parameters that this returned configuration lacks.

Returns:

JSON type compliant configuration dictionary.

Return type:

dict