Code Monkey home page Code Monkey logo

evalprotopnet's Introduction

EvalProtoPNet

Introduction

This is the official implementation of paper "Evaluation and Improvement of Interpretability for Self-Explainable Part-Prototype Networks".

Required Packages

Our required python packages are listed as below:

pytorch==1.12.1+cu113
Augmentor==0.2.9
torchvision==0.13.1+cu113
pillow==8.4.0 (9.3.0 for train)
timm==0.5.4
opencv-python==4.6.0.66
tensorboard==2.9.1
scipy==1.8.1
pandas==1.4.3
matplotlib==3.5.2
scikit-learn==1.1.1
numpy==1.22.0
tqdm==4.66.1

Dataset Preparation

  • Download the dataset (CUB_200_2011.tgz) from here.
  • Unpack CUB_200_2011.tgz to the datasets/ directory in this project (the path of CUB-200-2011 dataset will be datasets/CUB_200_2011/).
  • Run python util/crop_cub_data.py to split the cropped images into training and test sets. The cropped training images will be in the directory datasets/cub200_cropped/train_cropped/, and the cropped test images will be in the directory datasets/cub200_cropped/test_cropped/.
  • Run python util/img_aug.py --data_path /path/to/source_codes/datasets/cub200_cropped to augment the training set. Note that /path/to/source_codes/datasets/cub200_cropped should be an absolute path. This will create an augmented training set in the following directory: datasets/cub200_cropped/train_cropped_augmented/.

Model Weights

Most model weights will be downloaded automatically, except the ResNet50 backbone on iNaturalist2017. It (BBN.iNaturalist2017.res50.90epoch.best_model.pth) can be downloaded from here and put into the folder pretrained_models.

Training Instructions

Use scripts/train.sh for training:

sh scripts/train.sh $model $num_gpus

Here, $model is the name of backbone chosen from resnet34, resnet152, vgg19, densenet121, densenet161, $num_gpus is the number of GPUs for training (2 GPUs is recommended).

For example, the instruction for training a ResNet34 model with 2 GPUs is as below:

sh scripts/train.sh resnet34 2

Note that when running two scripts at the same time, the variable use_port in scripts/train.sh should be different for them.

Evaluate Consistency Score

The instruction for evaluating the consistency score of a ResNet34 model with checkpoint path $ckpt_path:

python eval_consistency.py \
--base_architecture resnet34 \
--resume $ckpt_path

Evaluate Stability Score

The instruction for evaluating the stability score of a ResNet34 model with checkpoint path $ckpt_path:

python eval_stability.py \
--base_architecture resnet34 \
--resume $ckpt_path

Visualization

The instruction for visualizing a ResNet34 model with checkpoint path $ckpt_path for the images in category $class:

python local_analysis_vis.py \
--base_architecture resnet34 \
--resume $ckpt_path \
--imgclass $class

For example, the instruction for evaluating a ResNet34 model with checkpoint path output_cosine/CUB2011/resnet34/1028-1e-4-adam-12-train/checkpoints/save_model.pth for the images in category 15:

python local_analysis_vis.py \
--base_architecture resnet34 \
--resume output_cosine/CUB2011/resnet34/1028-1e-4-adam-12-train/checkpoints/save_model.pth \
--imgclass 15

The results will be saved in output_view directory.

evalprotopnet's People

Contributors

hqhqaq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

evalprotopnet's Issues

Code for vision transformers

Hello, thank you for your great work and for opening your codes.

In your supplementary materials, I found the results for ViTs.
But I could not find the details for the experiments on ViTs,
such as which layers are used for the SDFA module.

Will you tell me how can I reproduce the results for ViTs?

Best regards.

Half size question

What is half-size in the code? Is it just half of the bounding box size? How is this value determined?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.