Hila commited on
Commit
1500c35
1 Parent(s): 7754b29

fix readme

Browse files
Files changed (1) hide show
  1. README.md +11 -124
README.md CHANGED
@@ -1,124 +1,11 @@
1
- # RobustViT
2
-
3
- [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/hila-chefer/RobustViT/blob/master/RobustViT.ipynb)
4
-
5
- Official PyTorch implementation of **Optimizing Relevance Maps of Vision Transformers Improves Robustness**. This code allows to
6
- finetune the explainability maps of Vision Transformers to enhance robustness.
7
-
8
- The method employs loss functions directly to the explainability maps to ensure that the model is focused mostly on the foreground of the image:
9
- <p align="center">
10
- <img width="500" height="400" src="teaser.png">
11
- </p>
12
- Using a short finetuning process with only 3 labeled examples from 500 classes, our method imrpoves robustness of ViT models across different model sizes and training techniques, even when data augmentations/ regularization are applied.
13
-
14
- ## Producing Segmenataion Data
15
- ### Using ImageNet-S
16
- To use the ImageNet-S labeled data, [download the `ImageNetS919` dataset](https://github.com/UnsupervisedSemanticSegmentation/ImageNet-S)
17
-
18
- ### Using TokenCut for unsupervised segmentation
19
- 1. Clone the TokenCut project
20
- ```
21
- git clone https://github.com/YangtaoWANG95/TokenCut.git
22
- ```
23
- 2. Install the dependencies
24
- Python 3.7, PyTorch 1.7.1 and CUDA 11.2. Please refer to the official installation. If CUDA 10.2 has been properly installed:
25
- ```
26
- pip install torch==1.7.1 torchvision==0.8.2
27
- ```
28
- Followed by
29
- ```
30
- pip install -r TokenCut/requirements.txt
31
-
32
- 3. Use the following command to extract the segmentation maps:
33
- ```
34
- python tokencut_generate_segmentation.py --img_path <PATH_TO_IMAGE> --out_dir <PATH_TO_OUTPUT_DIRECTORY>
35
- ```
36
-
37
-
38
- ## Finetuning ViT models
39
-
40
- To finetune a pretrained ViT model use the `imagenet_finetune.py` script. Notice to uncomment the import line containing the pretrained model you
41
- wish to finetune.
42
-
43
- Usage example:
44
-
45
- ```bash
46
- python imagenet_finetune.py --seg_data <PATH_TO_SEGMENTATION_DATA> --data <PATH_TO_IMAGENET> --gpu 0 --lr <LR> --lambda_seg <SEG> --lambda_acc <ACC> --lambda_background <BACK> --lambda_foreground <FORE>
47
- ```
48
-
49
- Notes:
50
-
51
- * For all models we use :
52
- * `lambda_seg=0.8`
53
- * `lambda_acc=0.2`
54
- * `lambda_background=2`
55
- * `lambda_foreground=0.3`
56
- * For **DeiT** models, a temprature is required as follows:
57
- * `temprature=0.65` for DeiT-B
58
- * `temprature=0.55` for DeiT-S
59
- * The learning rates per model are:
60
- * ViT-B: 3e-6
61
- * ViT-L: 9e-7
62
- * AR-S: 2e-6
63
- * AR-B: 6e-7
64
- * AR-L: 9e-7
65
- * DeiT-S: 1e-6
66
- * DeiT-B: 8e-7
67
-
68
- ## Baseline methods
69
- Notice to uncomment the import line containing the pretrained model you wish to finetune in the code.
70
-
71
- ### GradMask
72
- Run the following command:
73
- ```bash
74
- python imagenet_finetune_gradmask.py --seg_data <PATH_TO_SEGMENTATION_DATA> --data <PATH_TO_IMAGENET> --gpu 0 --lr <LR> --lambda_seg <SEG> --lambda_acc <ACC>
75
- ```
76
- All hyperparameters for the different models can be found in section D of the supplementary material.
77
-
78
- ### Right for the Right Reasons
79
- Run the following command:
80
- ```bash
81
- python imagenet_finetune_rrr.py --seg_data <PATH_TO_SEGMENTATION_DATA> --data <PATH_TO_IMAGENET> --gpu 0 --lr <LR> --lambda_seg <SEG> --lambda_acc <ACC>
82
- ```
83
- All hyperparameters for the different models can be found in section D of the supplementary material.
84
-
85
- ## Evaluation
86
-
87
- ### Robustness Evaluation
88
-
89
- 1. Download the evaluation datasets:
90
- * [INet-A](https://github.com/hendrycks/natural-adv-examples)
91
- * [INet-R](https://github.com/hendrycks/imagenet-r)
92
- * [INet-v2](https://github.com/modestyachts/ImageNetV2)
93
- * [ObjectNet](https://objectnet.dev/)
94
- * [SI-Score](https://github.com/google-research/si-score)
95
-
96
- 2. Run the following script to evaluate:
97
-
98
- ```bash
99
- python imagenet_eval_robustness.py --data <PATH_TO_ROBUSTNESS_DATASET> --batch-size <BATCH_SIZE> --evaluate --checkpoint <PATH_TO_FINETUNED_CHECKPOINT>
100
- ```
101
- * Notice to uncomment the import line containing the pretrained model you wish to evaluate in the code.
102
- * To evaluate the original model simply omit the `checkpoint` parameter.
103
- * For the INet-v2 dataset add `--isV2`.
104
- * For the ObjectNet dataset add `--isObjectNet`.
105
- * For the SI datasets add `--isSI`.
106
-
107
- ### Segmentation Evaluation
108
- Our segmentation tests are based on the test in the official implementation of [Transformer Interpretability Beyond Attention Visualization](https://github.com/hila-chefer/Transformer-Explainability).
109
- 1. [Download the ImageNet segmentation test set](https://github.com/hila-chefer/Transformer-Explainability#section-a-segmentation-results).
110
- 2. Run the following script to evaluate:
111
-
112
- ```bash
113
- PYTHONPATH=./:$PYTHONPATH python SegmentationTest/imagenet_seg_eval.py --imagenet-seg-path <PATH_TO_gtsegs_ijcv.mat>
114
- ```
115
- * Notice to uncomment the import line containing the pretrained model you wish to evaluate in the code.
116
-
117
- ### Credits
118
- * The TokenCut code is built on top of [LOST](https://github.com/valeoai/LOST), [DINO](https://github.com/facebookresearch/dino), [Segswap](https://github.com/XiSHEN0220/SegSwap), and [Bilateral_Sovlver](https://github.com/poolio/bilateral_solver).
119
- * Our ViT code is based on the [pytorch-image-models](https://github.com/rwightman/pytorch-image-models) repository.
120
- * Our ImageNet finetuning code is based on [code from the official PyTorch repo](https://github.com/pytorch/examples/blob/main/imagenet/main.py).
121
- * The code to convert ObjectNet classes to ImageNet classes was taken from [the torchprune repo](https://github.com/lucaslie/torchprune/blob/b753745b773c3ed259bf819d193ce8573d89efbb/src/torchprune/torchprune/util/datasets/objectnet.py).
122
- * The code to convert SI-Score classes to ImageNet classes was taken from [the official implementation](https://github.com/google-research/si-score).
123
-
124
- We would like to sincerely thank the authors for their great works.
1
+ ---
2
+ title: RobustViT
3
+ emoji:
4
+ colorFrom: red
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 3.0.11
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---