OcclusionExplainer<T>
Models & Types · AiDotNet.Interpretability.Explainers
Occlusion explainer for image and sequential data interpretation.
Implements: IGPUAcceleratedExplainer<T>, ILocalExplainer<T, OcclusionExplanation<T>>
For Beginners
Occlusion is a simple but powerful explanation technique. The idea is: systematically hide different parts of the input and see how the prediction changes.
How it works:
- Take your input (e.g., an image)
- Place a “patch” over one part of the input (occlude it)
- See how the model’s prediction changes
- Move the patch and repeat
- The result is a map showing which regions matter most
Intuition: If covering a region causes the prediction to drop significantly, that region was important for the prediction.
Use cases:
- Understanding which parts of an image a classifier looks at
- Finding what regions of a medical scan led to a diagnosis
- Debugging models that use spurious correlations (e.g., looking at background)
Advantages:
- Very simple and intuitive
- Model-agnostic (works with any model)
- Easy to visualize
Disadvantages:
- Can be slow (many forward passes required)
- May not capture feature interactions well
- Results depend on occlusion patch size
Constructors
| Constructor | Summary |
|---|---|
OcclusionExplainer(Func<Tensor<T>, Tensor<T>> predictFunction, int[] windowShape, int[] strides, T baselineValue, OcclusionShape shape) |
Initializes a new Occlusion explainer. |
Properties
| Property | Summary |
|---|---|
bool IsGPUAccelerated { get; } |
|
bool SupportsGlobalExplanations { get; } |
Gets whether this explainer supports global explanations. |
bool SupportsLocalExplanations { get; } |
Gets whether this explainer supports local explanations. |
string MethodName { get; } |
Gets the method name. |
Methods
| Method | Summary |
|---|---|
List<OcclusionExplanation<T>> ExplainBatch(List<Tensor<T>> inputs, int? targetClass) |
Explains a batch of inputs. |
OcclusionExplainer<T> ForImages(Func<Tensor<T>, Tensor<T>> predictFunction, int patchHeight, int patchWidth, int? strideHeight, int? strideWidth, T baselineValue, OcclusionShape shape) |
Initializes an Occlusion explainer for 2D images. |
OcclusionExplanation<T> Explain(Tensor<T> input, int? targetClass) |
Explains a single input by computing occlusion sensitivity. |
OcclusionExplanation<T> Explain(Vector<T> instance) |
Explains a single vector input. |
OcclusionExplanation<T>[] ExplainBatch(Matrix<T> instances) |
Explains a batch of inputs. |
void SetGPUHelper(GPUExplainerHelper<T> helper) |