FORGrad¶
View colab tutorial | View source | 📰 Paper
ForGrad is an enhancement for any attribution method by effectively filtering out high-frequency noise in gradient-based attribution maps, resulting in improved explainability scores and promoting the adoption of more computationally efficient techniques for model interpretability.
Quote
The application of an optimal low-pass filter to attribution maps improves gradient-based attribution methods significantly, resulting in higher explainability scores across multiple models and elevating gradient-based methods to a top ranking among state-of-the-art techniques, sparking renewed interest in simpler and more computationally efficient explainability approaches.
-- Gradient strikes back: How filtering out high frequencies improves explanations (2023)1
In a more precise manner, to obtain an attribution map \(\varphi_\sigma(x)\), we apply a filter \(w_\sigma\) with a cutoff value \(\sigma\) to remove high frequencies, as shown in the equation:
The parameter \(\sigma\) controls the amount of frequencies retained and ranges between \((0, W]\), where \(W\) represents the dimension of the squared image. A value of \(0\) eliminates all frequencies, while \(W\) retains all frequencies. The paper presents a method to estimate the optimal cutoff, and for ImageNet images, the recommended default value for the optimal sigma is typically around 15.
Example¶
from xplique.attributions import Saliency
from xplique.common import forgrad
# load images, labels and model
# ...
method = Saliency(model)
explanations = method.explain(images, labels)
explanations_filtered = forgrad(explanations, sigma=15)
Notebooks¶
forgrad(explanations: tensorflow.python.framework.tensor.Tensor,
sigma: int = 15) -> tensorflow.python.framework.tensor.Tensor
¶
sigma: int = 15) -> tensorflow.python.framework.tensor.Tensor
ForGRAD is a method that enhances any attributions explanations (particularly useful on
gradients based attribution method) by eliminating high frequencies in the explanations.
Parameters
-
explanations : tensorflow.python.framework.tensor.Tensor
List of explanations to filter. Explanation should be at least 3D (batch, height, width) and should have the same height and width.
-
sigma : int = 15
Bandwith of the low pass filter. The higher the sigma, the more frequencies are kept.
Sigma should be positive and less than image size.
Default to paper recommendation, 15 for image size 224.
Return
-
filtered_explanations : tensorflow.python.framework.tensor.Tensor
Explanations low-pass filtered.