attribench.masking.image.SampleAverageImageMasker
- class attribench.masking.image.SampleAverageImageMasker(feature_level)[source]
Bases:
ImageMaskerImage masker that masks pixels or features by replacing them with the average value in the corresponding image.
- Parameters:
- feature_levelstr
The level at which to mask the image. Must be either
"pixel"or"feature".
Methods
Return the number of features in the samples.
Mask the
kleast important features, according to the attributions.Mask
krandom features.Mask the
kmost important features, according to the attributions.Set the batch of samples and attributions to use for masking.
- get_num_features()
Return the number of features in the samples.
- Returns:
- int
Number of features in the samples.
- mask_bot(k)
Mask the
kleast important features, according to the attributions.- Parameters:
- kint
Number of features to mask.
- Returns:
- torch.Tensor
Samples with the bottom k features masked.
- mask_rand(k, return_indices=False)
Mask
krandom features.- Parameters:
- kint
Number of features to mask.
- return_indicesbool, optional
Whether to return the indices of the masked features, by default False
- Returns:
- torch.Tensor
Samples with k random features masked.
- Return type:
Union[Tensor,Tuple[Tensor,Tensor]]
- mask_top(k)
Mask the
kmost important features, according to the attributions.- Parameters:
- kint
Number of features to mask.
- Returns:
- torch.Tensor
Samples with the top k features masked.
- set_batch(samples, attributions=None, segmented_samples=None)
Set the batch of samples and attributions to use for masking. Optionally also set the segmented samples.
- Parameters:
- samplestorch.Tensor
Samples to use for masking.
- attributionstorch.Tensor, optional
Attributions to use for masking, by default None If None, the
mask_top()andmask_bot()methods will not be available.- segmented_samplestorch.Tensor, optional
Segmented samples to use for masking, by default None