Skip to content

Commit

Permalink
Simplify LR test, train and eval pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
marios1861 committed Sep 1, 2022
1 parent c06ab32 commit c05eb99
Show file tree
Hide file tree
Showing 43 changed files with 313 additions and 1,513 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ dataset
├── ILSVRC2012_val_00000002.JPEG
└── ...
```
If you have already downloaded the ILSVRC 2012 dataset and don't want to change its location, edit the paths in the file scripts/bash scripts/pc_info.sh to the location of your dataset.
If you have already downloaded the ILSVRC 2012 dataset and don't want to change its location, edit the paths in the file `scripts/bash scripts/pc_info.sh` to the location of your dataset.

## Initial Setup
Check that you have a working Python 3 and pip installation before proceeding.
Check that you have a working cuda, Python 3 and pip installation before proceeding.
- Clone this repository:
~~~
git clone https://github.com/bmezaris/TAME
Expand All @@ -44,21 +44,23 @@ python3 -m venv ./venv
~~~
pip install -r requirements.txt
~~~
Note: you may have to install the libraries torch and torchvision separately. Follow the pip instructions [here](https://pytorch.org/get-started/locally/).
> _**Note**_: you may have to install the libraries torch and torchvision separately. Follow the pip instructions [here](https://pytorch.org/get-started/locally/). Also, make sure you have a working matplotlib gui backend.
## Usage
You can generate explanation maps with the pretrained attention module:
~~~
cd "TAME/scripts/bash scripts"
. get_mask.sh <image_name> <label>
~~~
The image will be searched in the images directory. `image_name` should contain the file extension as well. If no `image_name` and `label` are provided, runs default test with image `162_166.JPEG` and label `162`.
The image will be searched in the `TAME/images` directory. `image_name` should contain the file extension as well. If no `image_name` and `label` are provided, runs default test with image `TAME/images/162_166.JPEG` and label `162`.
> _**Note**_:
If you want to load a model from a different directory, add the path to the checkpoint directory on the flag `--restore-dir`

## Training
- To train TAME on VGG-16 or ResNet-50 from scratch, run:
- To train TAME on VGG-16 or ResNet-50 from scratch, and generate the evaluation metrics AD, IC for the 100%, 50% and 15% masks, run:
~~~
cd "scripts/bash scripts"
. job.sh
. train_eval.sh
~~~

**OR**, for the ResNet-50 backbone with the selected loss function:
Expand Down
File renamed without changes.
14 changes: 0 additions & 14 deletions scripts/bash scripts/ResNet50_AD_IC.sh

This file was deleted.

17 changes: 0 additions & 17 deletions scripts/bash scripts/ResNet50_train.sh

This file was deleted.

18 changes: 0 additions & 18 deletions scripts/bash scripts/VGG16_eval.sh

This file was deleted.

20 changes: 0 additions & 20 deletions scripts/bash scripts/VGG16_train.sh

This file was deleted.

19 changes: 0 additions & 19 deletions scripts/bash scripts/VGG16_train_cylic.sh

This file was deleted.

19 changes: 0 additions & 19 deletions scripts/bash scripts/eval.sh

This file was deleted.

36 changes: 36 additions & 0 deletions scripts/bash scripts/experiment_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh



(
cd ../


CUDA_VISIBLE_DEVICES=0 python train_script.py \
--img-dir=$IMGDIR \
--restore-dir=$RESTORE \
--train-list=${TRAIN:=VGG16_train.txt} \
--num-workers=4 \
--model=${MODEL:=vgg16} \
--version"${VERSION:="TAME"}" \
--layers="${LAYERS:="features.16 features.23 features.30"}" \
--wd=${WD:=5e-4} \
--max-lr=${MLR:=1e-2} \
--epoch=${EPOCHS:=8} \
--batch-size=${BSIZE:=8} \


CUDA_VISIBLE_DEVICES=0 python eval_script.py \
--val-dir=$VALDIR \
--restore-dir=$RESTORE \
--test-list=${TEST:="Evaluation_2000.txt"} \
--num-workers=4 \
--model=${MODEL:="vgg16"} \
--version${VERSION:="TAME"} \
--layers="${LAYERS:="features.16 features.23 features.30"}" \
--start-epoch=1 \
--end-epoch=${EPOCHS:=8}


exit 0
)
1 change: 1 addition & 0 deletions scripts/bash scripts/get_mask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name=$1
label=$2

CUDA_VISIBLE_DEVICES=0 python masked_print.py \
--restore-dir=''\
--name=${name:="162_166.JPEG"} \
--label=${label:="162"}
)
11 changes: 0 additions & 11 deletions scripts/bash scripts/hyper_eval.sh

This file was deleted.

20 changes: 0 additions & 20 deletions scripts/bash scripts/job.sh

This file was deleted.

22 changes: 0 additions & 22 deletions scripts/bash scripts/job2.sh

This file was deleted.

24 changes: 0 additions & 24 deletions scripts/bash scripts/job3.sh

This file was deleted.

23 changes: 0 additions & 23 deletions scripts/bash scripts/job4.sh

This file was deleted.

26 changes: 10 additions & 16 deletions scripts/bash scripts/lr_finder.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
#!/bin/sh

(
. pc_info.sh

ARCH="_f30"
LAYERS="features.16 features.23 features.30"
#BN="true"
#WD="5e-4"
MODE="all"
#B2="0.99"
BSIZE=8

#MODEL="resnet50"
#LAYERS="layer2 layer3 layer4"
VER="V5"

cd ../

. lr_finder.sh
CUDA_VISIBLE_DEVICES=0 python lr_finder.py \
--img-dir=$IMGDIR \
--num-workers=4 \
--train-list=${TRAIN:=VGG16_train.txt} \
--model=${MODEL:=vgg16} \
--layers="${LAYERS:="features.16 features.23 features.30"}" \
--wd=${WD:=5e-4} \
--version="${VERSION:="TAME"}" \
--batch-size=${BSIZE:=8} \

exit 0
)
)
22 changes: 0 additions & 22 deletions scripts/bash scripts/lr_finder2.sh

This file was deleted.

23 changes: 0 additions & 23 deletions scripts/bash scripts/lr_finder3.sh

This file was deleted.

Loading

0 comments on commit c05eb99

Please sign in to comment.