Skip to main content

Compute IAUC, DAUC, IROF scores to measure quality of image attributions

Project description

Compute IAUC, DAUC, IROF scores to measure the quality of image attributions (PyTorch)

This package allows to evaluate the quality of attributions wrt. to your original iamge. For that purpose, you can compute IAUC (Insert Area Under Curve, Insertion score), DAUC (Delete Area Under Curve, Deletion score) and IROF (Iterative Removal Of Features).

Install via PyPi: pip install explainable-ai-image-measures

The shared idea behind all of them is to remove the most relevant pixels from the original image and replace it by a baseline color (DAUC, IROF) or to take blank a blank image and add the most relevant pixels again starting with the most relevant (IAUC). In contrast to IAUC and DAUC, IROF does this superpixel-wise.

  1. Create new images by removing / adding pixels / entire areas
  2. Send the newly created images through the network and save the probabilities.
  3. Compute the Area Under the Curve (AUC) for the recorded probabilities.
  4. Interpretation: For DAUC lower scores are better, for IROF and IAUC higher scores.

See github for a gif visualization of the mechanics

In contrast to other publicly available code,

  • all of the heavy computation is running on the GPU (no numpy or CPU in between)
  • you can compute the scores for a single image also batch-wise
  • there is parametrization possible to suit your needs
  • IAUC, DAUC and IROF is possible using a single package
  • multiple attributions for multiple images are possible (see example.ipynb)

Here a minimal code for a single image:

import torch
from captum.attr import Saliency
import torchvision.models as models

from explainable_ai_image_measures import Measures

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = models.resnet18(pretrained=True).to(device)

image = torch.rand((1, 3, 224, 224)).to(device)
attribution = Saliency(model).attribute(image, target=17)

# Average the attribution over the color channels
attribution = torch.mean(attribution, dim=1)

measure = Measures(model, batch_size=250, irof_segments=70)
score, y = measure.compute_IROF(image[0], attribution[0], 17)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

explainable_ai_image_measures-1.0.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file explainable_ai_image_measures-1.0.1.tar.gz.

File metadata

  • Download URL: explainable_ai_image_measures-1.0.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for explainable_ai_image_measures-1.0.1.tar.gz
Algorithm Hash digest
SHA256 dee008ec831964dae87e38579dcab956efc1f0cbbc8783aab3387de0579f3edc
MD5 df7799daa146fca192388291b28d57f1
BLAKE2b-256 b31d6e068ae6960197cad1967630fd1bb50779c6aaf4ff973d0af58b49d5d22d

See more details on using hashes here.

File details

Details for the file explainable_ai_image_measures-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: explainable_ai_image_measures-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for explainable_ai_image_measures-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89e16094f4b5c009d362ef0d4a11f06b92e2a210285e22b30809b110624f5678
MD5 f1b627e5d58e6ce347fb8830ae5e6ca2
BLAKE2b-256 0b5403391200aadec33f3c3e91d7d4f328d98ba9ea05608014c4bf22ba0a4cae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page