Skip to main content
Obz AI is designed to monitor and explain your vision models behaviour. In particular, it logs post-hoc XAI maps and features useful for outlier detection. Import necessary Python libraries.
Let’s define a Vision Transformer based on DINO ViT Backbone! To quickly look at XAI functionalities, we download and utilize a fine-tuned DINO ViT model on Imagenette dataset. In practice, you would have already trained or fine-tuned a deep learning model suitable for your data.

Configure the ViT classifer based on DINO backbone

We are adding a binary classification head (see how torch.nn.Linear) onto a DINO backbone.
We load the pre-trained weights onto this model.
Next, let’s prepare the datasets. In this tutorial, we focus on XAI such that the model is applied on samples to classify and explanations are computed using attention maps. In general, you likely want to consider two separate sets of images at the minimum — Reference and Inference data. For this tutorial, we will use a subset of the ImageNet dataset called Imagenette as our example data source. We download them if needed:
Visualize the first 5 samples from ref_loader.
png

XAI Module Setup

XAI Module have components to both provide you with easy-to-use explainability tools and evaluation tools. Module consist of two major ingredients:
  • XAITool - Particular implementations of explainability methods.
  • XAIEval - Evaluation methods for achieved explainability maps.
Let’s do some imports!
Let’s instantiate few objects:

XAITool

  • cdam_tool - It is an excellent explainability method, highly discriminative with regards to the target class.
  • smooth_grad_tool - Classical and simple XAI method.
  • attention_tool - Classical way to inspect ViT like models.

XAIEval

  • fidelity_tool - It is an explainability maps evaluation tool. It assess xai map quality by measuring behaviour of output logits in case of input perturbation.
  • compactness_tool - It is just another xai maps evaluation tool.
That is all! Your explainability and evaluation tools are ready to use! Let’s try it.
There are several Explainable AI (XAI) methods available, each with their own advantages and limitations. Obz AI offers a set of evaluation tools to help assess the quality of XAI methods. fidelity_tool measures how accurately a given XAI method reflects the model’s true decision process. It does this by systematically perturbing input features based on their importance scores and observing the resulting change in the model performance. compactness_tool evaluates how sparse and concentrated the importance scores are. A more compact set of importance scores is often easier for humans to interpret, as it highlights the most relevant features in a concise manner. By using these tools, you can better understand and compare the effectiveness and interpretability of different XAI approaches.
We can now visualize resulting XAI Maps. We run the normalization function for each of XAI maps before calling the plotting functions.
png