Home

Awesome

PIP-Net: Patch-Based Intuitive Prototypes for Interpretable Image Classification

This repository presents the PyTorch code for PIP-Net (Patch-based Intuitive Prototypes Network).

Main Paper at CVPR: "PIP-Net: Patch-Based Intuitive Prototypes for Interpretable Image Classification" introduces PIP-Net for natural images.
Medical applications, data quality inspection and manual corrections: Interpreting and Correcting Medical Image Classification with PIP-Net, applies PIP-Net to X-rays and skin lesion images where biases can be fixed by (manually) disabling prototypes.
Evaluation of part-prototype models like PIP-Net: The Co-12 Recipe for Evaluating Interpretable Part-Prototype Image Classifiers, presented at the XAI World Conference in July 2023.

PIP-Net is an interpretable and intuitive deep learning method for image classification. PIP-Net learns prototypical parts: interpretable concepts visualized as image patches. PIP-Net classifies an image with a sparse scoring sheet where the presence of a prototypical part in an image adds evidence for a class. PIP-Net is globally interpretable since the set of learned prototypes shows the entire reasoning of the model. A smaller local explanation locates the relevant prototypes in a test image. The model can also abstain from a decision for out-of-distribution data by saying “I haven’t seen this before”. The model only uses image-level labels and does not rely on any part annotations.

Overview of PIP-Net

Required Python Packages:

Training PIP-Net

PIP-Net can be trained by running main.py with arguments. Run main.py --help to see all the argument options. Recommended parameters per dataset are present in the used_arguments.txt file (usually corresponds to the default options).

Training PIP-Net on your own data

Want to train PIP-Net on another dataset? Add your dataset in util/data.py by creating a function get_yourdata with the desired data augmentation (that captures human perception of similarity), add it to the existing get_data function in util/data.py and give your dataset a name. Use --dataset your_dataset_name as argument to run PIP-Net on your dataset.

Other relevant arguments are for example --weighted_loss which is useful when your data is imbalanced. In case of a 2-class task with presence/absence reasoning, you could consider using --bias to include a traininable bias term in the linear classification layer (which could decrease the OoD abilities) such that PIP-Net does not necessarily need to find evidence for the absence-class.

Check your --log_dir to keep track of the training progress. This directory contains log_epoch_overview.csv which prints statistics per epoch. File tqdm.txt prints updates per iteration and potential errors. File out.txt includes all print statements such as additional info. See the Interpreting the Results section for further details.

Visualizations of prototypes are included in your --log_dir / --dir_for_saving_images.

Trained checkpoints

Various trained versions of PIP-Net are made available:

Data

The code can be applied to any imaging classification data set, structured according to the Imagefolder format:

root/class1/xxx.png <br /> root/class1/xxy.png <br /> root/class2/xyy.png <br /> root/class2/yyy.png

Add or update the paths to your dataset in util/data.py.

For preparing CUB-200-2011 with 200 bird species, use util/preprocess_cub.py. For Stanford Cars with 196 car types, use the Instructions of ProtoTree.

Interpreting the Results

During training, various files will be created in your --log_dir:

Hyperparameter FAQ

Reference and Citation

Please refer to our work when using or discussing PIP-Net:

Meike Nauta, Jörg Schlötterer, Maurice van Keulen, Christin Seifert (2023). “PIP-Net: Patch-Based Intuitive Prototypes for Interpretable Image Classification.” IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR).

BibTex citation:

@article{nauta2023pipnet,
  title={PIP-Net: Patch-Based Intuitive Prototypes for Interpretable Image Classification},
  author={Nauta, Meike and Schlötterer, Jörg and van Keulen, Maurice and Seifert, Christin},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year={2023},
}