MCRISEScoring

class xaitk_saliency.impls.gen_classifier_conf_sal.mc_rise_scoring.MCRISEScoring(k: int, p1: float = 0.0)

Saliency map generation based on the MC-RISE implementation. This version utilizes only the input perturbed image confidence predictions and does not utilize reference image confidences. This implementation also takes influence from debiased RISE and may take an optional debias probability, p1 (0 by default). In the original paper this is paired with the same probability used in RISE perturbation mask generation (see the p1 parameter in xaitk_saliency.impls.perturb_image.mc_rise.MCRISEGrid).

Based on Hatakeyama et. al: https://openaccess.thecvf.com/content/ACCV2020/papers/Hatakeyama_Visualizing_Color-wise_Saliency_of_Black-Box_Image_Classification_Models_ACCV_2020_paper.pdf

Methods

from_config

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

generate

Warning: this implementation returns a different shape than typically expected by this interface.

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__(k: int, p1: float = 0.0) None
Parameters:
  • k – int Number of colors to used during perturbation.

  • p1 – float Debias probability, typically paired with the same probability used in mask generation.

Raises:

ValueError If p1 not in in [0, 1].

Raises:

ValueError If k < 1.

generate(reference: ndarray, perturbed: ndarray, perturbed_masks: ndarray) ndarray

Warning: this implementation returns a different shape than typically expected by this interface. Instead of [nClasses x H x W], saliency maps of shape [kColors x nClasses x H x W] are generated, one per color per class.

Parameters:
  • reference – np.ndarray Reference image predicted class-confidence vector, as a numpy.ndarray, for all classes that require saliency map generation. This should have a shape [nClasses], be float-typed and with values in the [0,1] range.

  • perturbed – np.ndarray Perturbed image predicted class confidence matrix. Classes represented in this matrix should be congruent to classes represented in the reference vector. This should have a shape [nMasks x nClasses], be float-typed and with values in the [0,1] range.

  • perturbed_masks – np.ndarray Perturbation masks numpy.ndarray over the reference image. This should be parallel in association to the classification results input into the perturbed parameter. This should have a shape [kColors x nMasks x H x W], and values in range [0, 1], where a value closer to 1 indicate areas of the image that are unperturbed.

Returns:

np.ndarray Generated visual saliency heatmap for each input class as a float-type numpy.ndarray of shape [kColors x nClasses x H x W].

Raises:

ValueError If number of perturbations masks and respective confidence lengths do not match.

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