Skip to main content

Explain Any Image Classifier with Trained Perturbations

Project description

P-TAME

Explain Any Image Classifier with Trained Perturbations

arXiv python pytorch lightning hydra Ruff

Don't hesitate to open a new issue if you encounter problems while using this method!

Table of contents

Introduction

The adoption of Deep Neural Networks (DNNs) in critical fields where predictions need justifications is limited by their black-box nature. P-TAME (Perturbation-based Trainable Attention Mechanism for Explanations) is a model-agnostic method for explaining DNN-based image classifiers. It uses an auxiliary image classifier to extract features from the input image, bypassing the need to modify the explanation method to the architecture of the classifier being explained. Unlike traditional perturbation-based methods, P-TAME generates high-resolution explanations efficiently in a single forward pass during inference. We demonstrate its performance by applying it to VGG-16, ResNet-50, and ViT-B-16. The quantitative and qualitative results included in our work can be reproduced using this code, as explained below. Additionally, the procedure to apply this method to any classifier is also described.

Installation

If you already have PyTorch installed on your machine, the latest version of P-TAME can be obtained from PyPI as follows:

pip install ptame

Package requirements

The package requirements are as follows:

python>=3.10.0
torch>=2.0.0

Project structure

The directory structure of new project looks like this:

├── data               <- Project data
│   └── datalists         <- Validation and test subsets
├── logs               <- Logs generated by loggers
├── README.md
├── requirements.txt   <- File for installing python dependencies
├── setup.py           <- File for installing project as a package
└── src                <- Source code
    └── ptame
        ├── configs          <- Hydra configs
        │   ├── callbacks
        │   ├── data
        │   ├── debug
        │   ├── experiment      <- Experiment configs
        │   ├── extras
        │   ├── hparams_search  <- Hyperparameter search configs
        │   ├── hydra
        │   ├── local
        │   ├── logger
        │   ├── model           <- Model configs
        │   ├── paths
        │   ├── trainer
        │   ├── print_map.yaml
        │   ├── ax_sweep.yaml
        │   └── train.yaml
        ├── data             <- Data module
        ├── models           <- Model module
        ├── print_map.py     <- Script for printing explanation maps
        ├── ax_sweep.py      <- Script for hyperparameter optimization
        ├── train.py         <- Script for training
        └── utils            <- Utility module

Tutorials

To learn how to reproduce the results in tables 1 and 2 of the paper, and how to apply the method to classifiers besides the ones included in the experiments, refer to this page in the documentation.

Citation

If you fine this XAI explainability method interesting or useful in your research, use the following Bibtex annotation to cite us:

@misc{ntrougkas2025ptameexplainimageclassifier,
      title={P-TAME: Explain Any Image Classifier with Trained Perturbations},
      author={Mariano V. Ntrougkas and Vasileios Mezaris and Ioannis Patras},
      year={2025},
      eprint={2501.17813},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2501.17813},
}

Acknowledgement

The P-TAME repository was built using the lightning-hydra-template. The results of the comparison study are obtained using the following implementations:

  • The pytorch-gradcam library's implementations of the Grad-CAM, Grad-CAM++, Score-CAM, and Ablation-CAM methods.
  • The original implementation of the RISE method.
  • The original implementation of the Opti-CAM method.
  • The original implementation of the T-TAME method.

The weights for the pretrained ResNet-50, VGG-16, ViT-B-16, ResNet-18, MobileNet-V3, and MnasNet were taken from torchvision.models.

This work was supported by the EU Horizon 2020 programme under grant agreement 101070190 AI4TRUST.

License

This code is provided for academic, non-commercial use only. Please also check for any restrictions applied in the code parts and datasets used here from other sources. For the materials not covered by any such restrictions, redistribution and use in source and binary forms, with or without modification, are permitted for academic non-commercial use provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation provided with the distribution.

This software is provided by the authors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the authors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.

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

ptame-1.0.0.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ptame-1.0.0-py3-none-any.whl (52.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ptame-1.0.0.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for ptame-1.0.0.tar.gz
Algorithm Hash digest
SHA256 083d301d10827c63d38b0863a053c86ec1da9ab2d868bb54610dbf4d18de464e
MD5 e17962cd06d7ddfd2b04c152741c3e97
BLAKE2b-256 88206b4bbe257a0da6d1d79b941f764338a11cbda08241d030e6bac6353a88e1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ptame-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 52.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for ptame-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b4fa629f07dab5598fdad8ba71546b02532e0c17f02308f0661a5574bd4fd29
MD5 666a844cd9d8b0369f296430d1b92374
BLAKE2b-256 c0f6e6ffd2305cce653ba2a1e7f77d0745d1200585e664d543f8180d0c96bdb3

See more details on using hashes here.

Supported by

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