GuidedGradCAMExplainer<T>

Models & Types · AiDotNet.Interpretability.Explainers

Guided GradCAM explainer combining GuidedBackprop with GradCAM for high-resolution explanations.

Implements: IGPUAcceleratedExplainer<T>, ILocalExplainer<T, GuidedGradCAMExplanation<T>>

For Beginners

Guided GradCAM is the best of both worlds - it combines:

  1. GradCAM: Tells you WHERE to look (coarse localization)
  2. GuidedBackprop: Tells you WHAT to look for (fine-grained details)

How it works:

  1. Compute GradCAM map (coarse localization of important regions)
  2. Upsample GradCAM to input resolution
  3. Compute Guided Backpropagation (fine-grained pixel-level importance)
  4. Element-wise multiply: GuidedGradCAM = GuidedBackprop * upsampled_GradCAM

Why this works:

  • GradCAM alone is too coarse (can’t see fine details)
  • GuidedBackprop alone highlights details everywhere (not localized)
  • Multiplying them together keeps only important details in important regions

Result: High-resolution, class-discriminative visualizations that show both WHERE the model is looking AND WHAT features it sees there.

Use cases:

  • Medical imaging (showing exactly what pixels indicate disease)
  • Object detection debugging (why was this object detected?)
  • Fine-grained classification (what distinguishes this bird species?)

Constructors

Constructor Summary
GuidedGradCAMExplainer(GuidedBackpropExplainer<T> guidedBackpropExplainer, LayerGradCAMExplainer<T> gradcamExplainer, int[] inputShape) Initializes a Guided GradCAM explainer from component explainers.
GuidedGradCAMExplainer(INeuralNetwork<T> network, Func<Vector<T>, Vector<T>> predictFunction, Func<Vector<T>, Vector<T>> layerActivationFunction, Func<Vector<T>, int, Vector<T>> layerGradientFunction, int[] inputShape, int layerHeight, int layerWidth, int numChannels) Initializes a Guided GradCAM explainer from a neural network.

Properties

Property Summary
bool IsGPUAccelerated { get; }
bool SupportsGlobalExplanations { get; }
bool SupportsLocalExplanations { get; }
string MethodName { get; }

Methods

Method Summary
GuidedGradCAMExplanation<T> Explain(Vector<T> input, int? targetClass) Generates a Guided GradCAM explanation for an input.
GuidedGradCAMExplanation<T> ExplainTensor(Tensor<T> input, int? targetClass) Explains a tensor input.
GuidedGradCAMExplanation<T>[] ExplainBatch(Matrix<T> instances)
void SetGPUHelper(GPUExplainerHelper<T> helper)