Skip to main content

Code style: black CI PyPI version

Framework for the Evaluation of XAI Algorithms (XAIEV)

This code is heavily based on the master thesis of Julian Ulrich @Lunnaris01.

Installation (work in progress)

  • clone the repo
  • pip install -e .
  • download the "atsds_large" dataset from here

Usage

Bootstrap

  • Open terminal in the directory you want to use for future xaiev-usage.
  • Run xaiev --bootstrap.
    • This creates .env file in current working directory.
  • Edit this file (see next section).

General Notes on Paths

Many scripts and notebooks in this repo depend on paths. To ensure that the code runs on different machines (local development machines, HPC, etc) we use a .env file. This file is machine-specific and is expected to define the necessary paths in environment variables.

Example (see also .env-example):

# Note: This directory might contain several GB of (auto-generated) data
XAIEV_BASE_DIR="/home/username/xaiev/data/atsds_large"

This file is evaluated by utils.read_paths_from_dotenv().

The expected path structure is as follows (as shown in the dataset "atsds_large"):

<XAIEV_BASE_DIR>                      xaiev directory for one dataset (e.g.
│                               atsds_large) specified in .env file
├── imgs_main/                  main images (not masks, not background)
│   ├── test/
│   │   ├── 0001/               class directory
│   │   │   ├── 000000.png      individual image of this class
│   │   │   └── ...             more images
│   │   └── ...                 more classes
│   └── train/
│       └── <class dirs with image files>
│
├── imgs_background/...         background images; same structure
│                               as in imgs_main (test/..., train/...)
│
├── imgs_mask/...               corresponding mask images with same structure
│
├── model_checkpoints/          saved checkpoints for models trained on this
│   │                           dataset
│   ├── convnext_tiny_1_1.tar
│   ├── resnet50_1_1.tar
│   ├── simple_cnn_1_1.tar
│   └── vgg16_1_1.tar
│                               as in imgs_main (test/..., train/...)
├── inference/
│   ├── images_to_classify      directory for images which should be classified
│   └── classification_results
│       ├── simple_cnn_1_1      classification results for a specific model
│       └── ...
│
├── XAI_results
│   ├── simple_cnn/             directory specifying cnn model
│   │   ├── gradcam/            xai method
│   │   │   ├── test/           split fraction (train/test)
│   │   │   │   ├── mask/
│   │   │   │   │   ├── 000000.png.npy
│   │   │   │   │   └── ...
│   │   │   │   ├── mask_on_image/
│   │   │   │   │   ├── 000000.png
│   │   │   │   │   └── ...
│   │   …   …   …
│   ├── vgg16/...
│   ├── resnet50/...
│   └── convnext_tiny/...
│
├── XAI_evaluation
│   ├── simple_cnn/gradcam/test/    same structure as `XAI_results`
│   │           ├── revelation
│   │           │   └── results.pcl
│   │           └── occlusion
│   │               └── results.pcl
│   └── ...                     other XAI methods and models
└── ...

General Usage

The four steps of the pipeline (with example calls):

  • (1) model training,
    • xaiev train --model simple_cnn_1_1
  • (2) applying XAI algorithms to generate weighted saliency maps,
    • xaiev create-saliency-maps --xai-method gradcam --model simple_cnn_1_1
    • xaiev create-saliency-maps --xai-method int_g --model simple_cnn_1_1
  • (3) generating new test images with varying percentages of "important" pixels removed or retained, and
    • xaiev create-eval-images --xai-method gradcam --model simple_cnn_1_1
  • (4) statistically evaluating accuracy changes on these test images and comparison to the ground truth.
    • xaiev eval --xai-method gradcam --model simple_cnn_1_1

Arguments for xaiev create-saliency-maps

  • (1) --xai-method (required): Selects the explainable AI (XAI) method to be used in the analysis. Example: --xai-method gradcam

  • (2) --model (required): Specifies the full model name. Example: --model simple_cnn_1_1

  • (3) --dataset_split (optional): Indicates which dataset part to use (e.g., train or test; see expected directory layout above). Default: test Example: --dataset_split test

  • (4) --random_seed (optional): An integer used to set the random seed for reproducibility. Default: 1414 Example: --random_seed 1414

Additional calls:

  • Use a trained model to perform classification
    • xaiev inference --model simple_cnn_1_1

Contributing and Development Notes

This software is provided in the hope that it will be useful. If you spot opportunities for improvement feel free to open an issue or even better a pull-request.

Unittests and Continuous Integration (CI)

Code Style

Metadata

Release files for xaiev 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xaiev 0.1.0
File Size Uploaded
xaiev-0.1.0.tar.gz 31.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xaiev 0.1.0
File Interpreter ABI Platform
xaiev-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 67.8 kB

Release files / xaiev-0.1.0.tar.gz

Download URL xaiev-0.1.0.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
05a218edf3c811de1a2a9d2dd7e2af8e80ec582f37dabab39950a163cdf0204b
BLAKE2b-256 checksum
How to use checksums
fd4b89114a97b280399c9751f42363851c1e5ebbb18ec4b5b300da5543df4351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / xaiev-0.1.0-py3-none-any.whl

Download URL xaiev-0.1.0-py3-none-any.whl
Size 36.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f45d3a57a2a72ce7466e3b70ef976f8a7718c4e19712f28ae54ea6e3aeff2306
BLAKE2b-256 checksum
How to use checksums
e15c432d50db0e7323a4b094f0531acef498653d69ceb72d08c378a2bddb28d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page