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).

  1. 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. In contrast to IAUC and DAUC, IROF proceeds super-pixel-wise.
  2. Then the Area Under the Curve (AUC) is computed.
  3. For DAUC lower scores are better, for IROF and IAUC higher scores mean a better attribution.

Mechanics behind IROF

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 scoring_metric import ExplainableAIImageMeasure

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 = ExplainableAIImageMeasure(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.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

  • Download URL: explainable_ai_image_measures-1.0.0.tar.gz
  • Upload date:
  • Size: 8.1 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.0.tar.gz
Algorithm Hash digest
SHA256 6a7b254a770602618790739fa1e6ac3c1dafa9a7d9e62df13b875402791ee213
MD5 9ac3f06582ec27570a976eab51decce7
BLAKE2b-256 9022e596a1f909b70ac68d51dc22c469fddeda745bf2191645e683cb200d3c09

See more details on using hashes here.

File details

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

File metadata

  • Download URL: explainable_ai_image_measures-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b4ea98d2a74eedb90ed06549dbc70355fc464b2acdd5897274a9a0c50cdce47
MD5 8729fc9dfcfec24be6a446f4e9c7417d
BLAKE2b-256 890bec6121c99e326df24de3fde0cd21407ce9df7d5e0d98b0984a61b87db4b8

See more details on using hashes here.

Supported by

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