PerturbationOcclusion

class xaitk_saliency.impls.gen_image_similarity_blackbox_sal.occlusion_based.PerturbationOcclusion(*, perturber: PerturbImage, generator: GenerateDescriptorSimilaritySaliency, fill: int | Sequence[int] | ndarray[Any, Any] | None = None, threads: int | None = None)

Image similarity saliency generator composed of modular perturbation and occlusion-based algorithms.

This implementation exposes its fill attribute as public. This allows it 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 FakeImageDescriptorGenerator
>>> from xaitk_saliency.impls.gen_descriptor_sim_sal.similarity_scoring import SimilarityScoring
>>> from xaitk_saliency.impls.perturb_image.sliding_window import SlidingWindow
>>> n_query, height, width = 2, 18, 24
>>> ref_image = np.zeros((height, width, 3), dtype=np.uint8)
>>> query_images = [
...     np.zeros((height, width, 3), dtype=np.uint8),
...     np.zeros((height, width, 3), dtype=np.uint8),
... ]
>>> gen = PerturbationOcclusion(
...     perturber=SlidingWindow(window_size=(8, 8), stride=(8, 8)),
...     generator=SimilarityScoring(),
... )
>>> sal = gen.generate(ref_image=ref_image, query_images=query_images, blackbox=FakeImageDescriptorGenerator())
>>> sal.shape == (n_query, height, width)
True

Methods

from_config

Create a PerturbationOcclusion instance from a configuration dictionary.

generate

Generates visual saliency maps based on the similarity of the reference image to each query image.

get_config

Get the configuration dictionary of the PerturbationOcclusion instance.

get_default_config

Returns the default configuration for the PerturbationOcclusion.

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__(*, perturber: PerturbImage, generator: GenerateDescriptorSimilaritySaliency, fill: int | Sequence[int] | ndarray[Any, Any] | None = None, threads: int | None = None) → None

Image similarity saliency generator composed of modular perturbation and occlusion-based algorithms.

Parameters:
  • perturber – PerturbImage implementation instance for generating occlusion masks.

  • generator – GenerateDescriptorSimilaritySaliency implementation instance for generating saliency masks given occlusion masks and image feature vector generator outputs.

  • fill – Optional fill for alpha-blending the occluded regions based on the masks generated by the given perturber. Can be a scalar value, a per-channel sequence or a shape-matched image.

  • 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.