RandomGridStack
- class xaitk_saliency.impls.gen_object_detector_blackbox_sal.drise.RandomGridStack(*, n: int, s: tuple[int, int], p1: float, seed: int | None = None, fill: int | Sequence[int] | ndarray[Any, Any] | None = None, threads: int = 0)
Encapsulation of the perturbation-occlusion method using RandomGrid perturbation and DRISE scoring algorithms.
This generates visual saliency maps for object detection. See references in the
RandomGridandDRISEScoringdocumentation.- Example:
>>> from xaitk_saliency._fakes import FakeDetectImageObjects >>> n_dets, height, width = 1, 18, 24 >>> ref_image = np.zeros((height, width, 3), dtype=np.uint8) >>> bboxes = np.array([[0, 0, 8, 8]]) >>> scores = np.array([[0.4, 0.6]]) >>> gen = RandomGridStack(n=3, s=(4, 4), p1=0.5, seed=0) >>> sal = gen.generate(ref_image=ref_image, bboxes=bboxes, scores=scores, blackbox=FakeDetectImageObjects()) >>> sal.shape == (n_dets, height, width) True
Methods
from_configInstantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.
generateGenerate per-detection visual saliency heatmaps for some object detector black-box.
get_configReturn a JSON-compliant dictionary that could be passed to this class's
from_configmethod to produce an instance with identical configuration.get_default_configGenerate and return a default configuration dictionary for this class.
get_implsDiscover and return a set of classes that implement the calling class.
is_usableCheck whether this class is available for use.
- __init__(*, n: int, s: tuple[int, int], p1: float, seed: int | None = None, fill: int | Sequence[int] | ndarray[Any, Any] | None = None, threads: int = 0) None
Encapsulation of the perturbation-occlusion method using RandomGrid perturbation and DRISE algorithms.
This generates visual saliency maps for object detection.
- Parameters:
n – Number of random masks.
s – Dimensions of each grid cell in pixels. E.g. (3, 4) would use a grid of 3x4 pixel cells.
p1 – Probability of a grid cell being set to 1 (not occluded). This should be a float value in the [0, 1] range.
seed – A seed to pass to the constructed random number generator to allow for reproducibility.
fill – Optional fill for alpha-blending the occluded regions based on the masks generated by the RandomGrid perturber. Can be a scalar value, a per-channel sequence or a shape-matched image.
threads – 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.