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.2.tar.gz (43.2 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.2-py3-none-any.whl (52.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ptame-1.0.2.tar.gz
  • Upload date:
  • Size: 43.2 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.2.tar.gz
Algorithm Hash digest
SHA256 17ee33218e2cc2f7c656ee93972d1414330b25d9fd7d46dd2c31b624767f77b8
MD5 b20b3168c672d6f998edcff0eb1b7d1b
BLAKE2b-256 e97e75671a774148e893b939b7f2be0f69f3ea77f56443f1930fa48bfae83816

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ptame-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 100ecec9c4ad98f6ae904848212c7a8da4c834d7b74944ce1e76d23c872d6953
MD5 b396cb9ef58fc884cbe485b0ff5b4b87
BLAKE2b-256 7db0743961c87c8473ac0e061781910691304ea584ce17eb0945a07e48702293

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