PerturbationOcclusion
- class xaitk_saliency.impls.gen_image_classifier_blackbox_sal.occlusion_based.PerturbationOcclusion(*, perturber: PerturbImage, generator: GenerateClassifierConfidenceSaliency, threads: int = 0)
Generator composed of modular perturbation and occlusion-based algorithms.
This implementation exposes a public attribute fill. This may be set to a scalar or sequence value to indicate a color that should be used for filling occluded areas as determined by the given PerturbImage implementation. This is a parameter to be set during runtime as this is most often driven by the black-box algorithm used, if at all.
- Example:
>>> from xaitk_saliency._fakes import FakeClassifyImage >>> from xaitk_saliency.impls.gen_classifier_conf_sal.occlusion_scoring import OcclusionScoring >>> from xaitk_saliency.impls.perturb_image.sliding_window import SlidingWindow >>> n_classes, height, width = 1, 18, 24 >>> ref_image = np.zeros((height, width, 3), dtype=np.uint8) >>> gen = PerturbationOcclusion( ... perturber=SlidingWindow(window_size=(8, 8), stride=(8, 8)), ... generator=OcclusionScoring(), ... ) >>> sal = gen.generate(ref_image=ref_image, blackbox=FakeClassifyImage({0: 1.0})) >>> sal.shape == (n_classes, height, width) True
Methods
Create a PerturbationOcclusion instance from a configuration dictionary.
generateGenerates per-class visual saliency heatmaps for some classifier black box over some image of interest.
Get the configuration dictionary of the PerturbationOcclusion instance.
Returns the default configuration for the PerturbationOcclusion.
get_implsDiscover and return a set of classes that implement the calling class.
is_usableCheck whether this class is available for use.
- __init__(*, perturber: PerturbImage, generator: GenerateClassifierConfidenceSaliency, threads: int = 0) None
Initialization of a generator for modular perturbation and occlusion-based algorithms.
- Parameters:
perturber – PerturbImage implementation instance for generating masks that will dictate occlusion.
generator – Implementation instance for generating saliency masks given occlusion masks and classifier outputs.
threads – Optional number threads to use to enable parallelism in applying perturbation masks to an input image. If 0, a negative value, or None, work will be performed on the main-thread in-line.
- classmethod from_config(config_dict: dict[str, Any], merge_default: bool = True) Self
Create a PerturbationOcclusion instance from a configuration dictionary.
- Args:
config_dict (dict): Configuration dictionary with perturber details. merge_default (bool): Whether to merge with the default configuration.
- Returns:
PerturbationOcclusion: An instance of PerturbationOcclusion.
- get_config() dict[str, Any]
Get the configuration dictionary of the PerturbationOcclusion instance.
- Returns:
dict[str, Any]: Configuration dictionary.
- classmethod get_default_config() dict[str, Any]
Returns the default configuration for the PerturbationOcclusion.
This method provides a default configuration dictionary, specifying default values for key parameters in the factory. It can be used to create an instance of the factory with preset configurations.
- Returns:
dict[str, Any]: A dictionary containing default configuration parameters.